這篇文章給大家介紹怎么在java中搭建一個Spring框架,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于做網(wǎng)站、網(wǎng)站制作、紅安網(wǎng)絡(luò)推廣、小程序設(shè)計、紅安網(wǎng)絡(luò)營銷、紅安企業(yè)策劃、紅安品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學生創(chuàng)業(yè)者提供紅安建站搭建服務,24小時服務熱線:18982081108,官方網(wǎng)址:www.muchs.cn
Java是一門面向?qū)ο缶幊陶Z言,可以編寫桌面應用程序、Web應用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應用程序。
1.配置web.xml文件
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <!--設(shè)置轉(zhuǎn)發(fā)--> <servlet> <servlet-name>DispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <!--加載配置文件--> <param-value> classpath:applicationContext.xml</param-value> </init-param> <!--標記容器是否在啟動的時候就加載這個servlet。 當值為0或者大于0時,表示容器在應用啟動時就加載這個servlet; 當是一個負數(shù)時或者沒有指定時,則指示容器在該servlet被選擇時才加載。 正數(shù)的值越小,啟動該servlet的優(yōu)先級越高。--> <load-on-startup> 1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>DispatcherServlet</servlet-name> <!--接受所有請求--> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
2.配置applicationContext.xml文件
<beans xmlns= "http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <!--這里可以去掉,因為下面自動掃描包的代碼,就包含了該行的功能--> <context:annotation-config/> <!-- 自動掃描web包 ,將帶有注解的類 納入spring容器管理 --> <context:component-scan base-package="com.zds"></context:component-scan> </beans>
3.新建Controller文件
package com.zds; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/test") public class TestController { @RequestMapping(value = "hello", method = RequestMethod.GET) @ResponseBody public String helloWorld(@RequestParam("user") String userName) { String string = ""; string.split(","); return "Hello " + userName + " !"; } }
關(guān)于怎么在java中搭建一個Spring框架就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
文章標題:怎么在java中搭建一個Spring框架
文章出自:http://www.muchs.cn/article32/ghgesc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、搜索引擎優(yōu)化、營銷型網(wǎng)站建設(shè)、面包屑導航、動態(tài)網(wǎng)站、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)