榪欐鏃墮棿寮濮嬪皝瑁呭叕鍙稿唴閮ㄤ嬌鐢ㄧ殑寮鍙戞鏋訛紝鍩轟簬鎬ц兘鐨勮冭檻錛屼嬌鐢╯rpingmvc+hibernate鎶鏈紝涓嬮潰鏄竴浜涙惌寤鴻繃紼嬶紙涓嶅寘鍚玠ao灞傚皝瑁咃級錛屽啓涓嬫潵澶囧繕銆?br />1.璁﹕pringmvc璺戣搗鏉?br />榪欎釜榪囩▼寰堢畝鍗曘傚鍏pring鐨刯ar鍖呭氨濂戒簡錛岃繖閲岀畝鍗曠殑浠嬬粛涓媕ar鍖呭惂銆備富瑕佸垎srping鐨勫疄鐜板寘錛屽拰渚濊禆鍖?br />涓誨寘錛歴pring-framework-3.1.1.RELEASE-with-docs.zip
渚濊禆錛歴pring-framework-3.0.1.RELEASE-A-dependencies.zip
涓誨寘涓笉闇瑕佸叏閮ㄥ姞榪涘幓錛岄変竴浜涢渶瑕佺殑灝卞ソ浜嗗涓?

鐒跺悗鍐嶅姞鍏ヤ緷璧栵細(xì)

鍔犲叆浜唈ar鍖呭悗灝卞紑濮嬮厤緗畐eb.xml鏂囦歡錛屽湪web.xml涓姞鍏ュ涓嬩唬鐮併?br />
<!--鍒濆鍖杝rpingMVC-->
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 榪欐牱鍙互閰嶇疆xml-servlet錛屼笉榛樿鎵総est-servlet.xml -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/configSource/test-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<!--榪欓噷鎴戞槸鎷︽埅浠?test緇撳熬鐨勮姹?/span>-->
<url-pattern>*.test</url-pattern>
</servlet-mapping>

鍥犱負(fù)srpingmvc鏄熀浜巗ervlet瀹炵幇鐨勩傛墍鏈夎姹傞兘闇瑕侀氳繃DispatcherServlet鏉ヨ漿鍙戣姹?br />瑙i噴涓媔nit-param榪欐錛岄粯璁ゅ彲浠ヤ笉闇瑕侀厤緗殑錛屽彧瑕佸湪WEB-INF涓嬮潰瀹氫箟test-servlet.xml灝卞彲浠ヨ嚜宸辨壘鍒扮殑錛岋紙test-servlet.xml錛岃繖涓悕瀛楃殑鐢辨潵鏄洜涓烘垜鐨剆ervlet鐨刵ame鏄痶est錛屾墍鏈夋湁test-servlet.xml鏂囦歡灝變細(xì)鑷姩鎵懼埌榪欎釜鏂囦歡錛岀孩鑹插瓧浣撴爣娉級錛岃繖鏍風(fēng)殑璇濅笅闈㈢殑init-param榪欎竴涓妭鐐瑰氨鍙互涓嶉渶瑕侀厤緗簡銆?br />浣嗘槸涓轟簡綆$悊鏂逛究錛屾垜鏀懼湪浜?span style="color: #339966">configSource榪欎釜鍖呴噷闈紝鎵浠ユ垜鍦╬aram-value涓殑<param-value>classpath:/configSource/*-servlet.xml</param-value>鏄繖鏍烽厤緗殑銆傚熀鏈繖鏍峰氨閰嶇疆瀹屼簡錛屽彲浠ョ畝鍗曟祴璇曪紝灝辨潵涓猦elloworld渚嬪瓙鍚с?br />鍦╰est-servlet.xml涓厤緗涓嬩唬鐮侊細(xì)
1
<beans xmlns="http://www.springframework.org/schema/beans"
2
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
3
xmlns:context="http://www.springframework.org/schema/context"
4
xmlns:mvc="http://www.springframework.org/schema/mvc"
5
xsi:schemaLocation="http://www.springframework.org/schema/beans
6
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7
http://www.springframework.org/schema/mvc
8
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
9
http://www.springframework.org/schema/context
10
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
11
<!-- 鑷姩鎵弿com.baobaotao.web 鍖呬笅鐨凘Controller鏍囨敞鐨勭被鎺у埗鍣ㄧ被 -->
12
<context:component-scan base-package="com.Integrat.*.controller" />
13
<!-- 鍚姩Spring MVC鐨勬敞瑙e姛鑳斤紝瀹屾垚璇鋒眰鍜屾敞瑙OJO鐨勬槧灝?nbsp;-->
14
<mvc:annotation-driven/>
15
</beans>
16
閲嶇偣鍙湁涓ゅ彞錛屽氨鏄紑鍚敞瑙o紝鍜岃嚜鍔ㄦ壂鎻忔帶鍒跺櫒
base-package="com.Integrat.*.controller" 榪欎釜搴旇鎳備簨榪欎箞鎰忔濅簡鍚э紝涓嶈В閲娿?br />閰嶇疆濂借繖浜涗簡灝卞紑濮嬪啓controller鍚?br />浠g爜濡備笅錛?br />
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;

@org.springframework.stereotype.Controller //榪欓噷鏄敞瑙o紝琛ㄧず榪欐槸涓涓帶鍒跺櫒
@RequestMapping("/helloworld") //榪欓噷鏄闂礬寰勶紝涓漢鎰熻鍜宻truts鐨刵amespace涓鐐圭被浼鹼紝涓嶈繃鍔熻兘涓嶆濡傛錛岀暐榪?/span>

public class HelloWorldController
{
@RequestMapping("/hello") //娉ㄦ剰榪欓噷涔熷啓涓?/span>

public String query()
{
System.out.println("hello world錛侊紒錛?/span>");
return null;
}
}


榪欐牱鍩烘湰灝卞彲浠ヤ簡銆傚彂甯冮」鐩紝璁塊棶鍦板潃--> http://localhost:8080/欏圭洰鍚?helloworld/hello.test
灝卞彲浠ョ湅鍒版帶鍒跺彴杈撳嚭helloworld浜嗐?br />鏈畬寰呯畫....

]]>