首页 > 代码库 > SpringMVC Annotation
SpringMVC Annotation
1 jar
commons-logging-1.2.jar spring-aop-4.3.3.RELEASE.jar spring-beans-4.3.3.RELEASE.jar spring-context-4.3.3.RELEASE.jar spring-context-support-4.3.3.RELEASE.jar spring-core-4.3.3.RELEASE.jar spring-expression-4.3.3.RELEASE.jar spring-web-4.3.3.RELEASE.jar spring-webmvc-4.3.3.RELEASE.jar
2 web.xml
<?xml version="1.0" encoding="UTF-8"?> <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_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>SpringMVC_Annotation</display-name> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
3 controller
package com.sgcc.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class HelloController { @RequestMapping("/hello") public ModelAndView hello(HttpServletRequest req,HttpServletResponse rep){ ModelAndView mv = new ModelAndView(); mv.addObject("msg", "hello Springmvc Annotation"); mv.setViewName("hello"); return mv; } }
4 springmvc 配置
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:p="http://www.springframework.org/schema/p" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xsi:schemaLocation=" 7 http://www.springframework.org/schema/beans 8 http://www.springframework.org/schema/beans/spring-beans.xsd 9 http://www.springframework.org/schema/context 10 http://www.springframework.org/schema/context/spring-context.xsd"> 11 <!-- configure the InternalResourceViewResolver --> 12 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 13 id="internalResourceViewResolver"> 14 <!-- 前缀 --> 15 <property name="prefix" value="http://www.mamicode.com/WEB-INF/jsp/" /> 16 <!-- 后缀 --> 17 <property name="suffix" value="http://www.mamicode.com/.jsp" /> 18 </bean> 19 <context:component-scan base-package="com.sgcc.controller"></context:component-scan> 20 </beans>
SpringMVC Annotation
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。