springMVC注解开发及提供restful接口

配置

1.1 pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
aaaaaa
springMVC
war
0.0.1-SNAPSHOT
springMVC Maven Webapp
http://maven.apache.org


org.slf4j
slf4j-api
1.7.5



org.slf4j
slf4j-log4j12
1.7.5



org.codehaus.jackson
jackson-core-asl
1.9.13


org.codehaus.jackson
jackson-mapper-asl
1.9.13



junit
junit
3.8.1
test



javax.servlet
servlet-api
3.0-alpha-1
test


 
            javax  
            javaee-api  
            7.0  
       
 



org.springframework
spring-webmvc
4.0.5.RELEASE




org.springframework
spring-jdbc
4.0.5.RELEASE




org.springframework
spring-test
4.0.5.RELEASE





springMVC


1.2 web.xml配置

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


action
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:action-servlet.xml



action
/


index.jsp


1.3 action-servlet.xml


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.2.xsd">











 


1.4 controller 

package cn.itcast.controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

@Controller
@RequestMapping("/home")
public class HomeController{
@ResponseBody
@RequestMapping("/home")
public Map goHome(HttpServletRequest request,String name){
Map map=new HashMap();
System.out.println(name);
map.put("aaa", "aaa");
return map;
}
}




你可能感兴趣的:(spring)