码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC Annotation

时间:2016-11-15 00:37:54      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:index   rtu   return   view   release   div   can   lease   .com   

技术分享

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="/WEB-INF/jsp/" />
16         <!-- 后缀 -->
17         <property name="suffix" value=".jsp" />
18     </bean>
19     <context:component-scan base-package="com.sgcc.controller"></context:component-scan>
20 </beans>

 

SpringMVC Annotation

标签:index   rtu   return   view   release   div   can   lease   .com   

原文地址:http://www.cnblogs.com/alloevil/p/6063877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!