生活随笔
收集整理的這篇文章主要介紹了
Spring+SpringMVC项目搭建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
前言:本文基于上一篇內容-Spring項目搭建
<dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>4.2.4.RELEASE</version>
</dependency>
<!--?SpringMVC攔截器配置,配置文件名稱默認為/WEB-INF/'<serlet-name>值'-servlet.xml?--><servlet><servlet-name>applicationContext</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class></servlet><!--?SpringMVC攔截內容?--><servlet-mapping><servlet-name>applicationContext</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
<?xml?version="1.0"?encoding="UTF-8"?>
<beans?xmlns="http://www.springframework.org/schema/beans"??xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xmlns:p="http://www.springframework.org/schema/p"??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-4.0.xsd???http://www.springframework.org/schema/context???http://www.springframework.org/schema/context/spring-context-4.0.xsd??http://www.springframework.org/schema/mvc???http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--?注解自動掃描包設置?--><context:component-scan?base-package="com.MyTest.controller"?/><!--?注解驅動配置?--><mvc:annotation-driven?/><!--?視圖控制器,主頁配置?--><mvc:view-controller?path="/"?view-name="index"/><!--?資源目錄配置?--><mvc:resources mapping="/css/*.css" location="/css/"/><mvc:resources mapping="/js/*.js" location="/js/"/><mvc:resources mapping="/images/**" location="/images/"/><!--?視圖解析器配置?--><bean?class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property?name="prefix"?value="/WEB-INF/views/"></property><property?name="suffix"?value=".jsp"></property></bean></beans>
package?com.MyTest.controller;import?org.springframework.stereotype.Controller;
import?org.springframework.web.bind.annotation.RequestMapping;@Controller
public?class?MyTestController?{@RequestMapping("/myTest")public?String?myTest(){return?"MyTest";}
}
<%@?page?language="java"?contentType="text/html;?charset=UTF-8"?pageEncoding="UTF-8"%>
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=UTF-8">
<title>Insert?title?here</title>
</head>
<body>
This?is?MyTest?page!
</body>
</html>
轉載于:https://my.oschina.net/lixuelong/blog/617934
總結
以上是生活随笔為你收集整理的Spring+SpringMVC项目搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。