1 工程创建

1.1 单根Dispatcherservlet配置

<web-app>

<display-name>Archetype Created Web Application</display-name>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:WEB-INF/root-context.xml</param-value>

</context-param>

<servlet>

<servlet-name>mvc</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:WEB-INF/mvc-servlet.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>mvc</servlet-name>

<url-pattern>/*</url-pattern>

</servlet-mapping>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

2 启动和测试项目

2.1 启动成功信息

<strong>信息: Initializing Spring FrameworkServlet 'mvc'

六月 19, 2017 7:13:49 下午 org.springframework.web.servlet.DispatcherServlet initServletBean

信息: FrameworkServlet 'mvc': initialization started

六月 19, 2017 7:13:49 下午 org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh

信息: Refreshing WebApplicationContext for namespace 'mvc-servlet': startup date [Mon Jun 19 19:13:49 CST 2017]; parent: Root WebApplicationContext

六月 19, 2017 7:13:49 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

信息: Loading XML bean definitions from class path resource [WEB-INF/mvc-servlet.xml]

六月 19, 2017 7:13:50 下午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register

信息: Mapped "{[/user/{id}],methods=[GET]}" onto public mvc.bean.User mvc.controller.UserController.getUser(java.lang.Long)

六月 19, 2017 7:13:50 下午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register

信息: Mapped "{[/user/add],methods=[POST]}" onto public java.lang.String mvc.controller.UserController.addUser(mvc.bean.User)

六月 19, 2017 7:13:50 下午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache

信息: Looking for @ControllerAdvice: WebApplicationContext for namespace 'mvc-servlet': startup date [Mon Jun 19 19:13:49 CST 2017]; parent: Root WebApplicationContext

六月 19, 2017 7:13:50 下午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache

信息: Looking for @ControllerAdvice: WebApplicationContext for namespace 'mvc-servlet': startup date [Mon Jun 19 19:13:49 CST 2017]; parent: Root WebApplicationContext

六月 19, 2017 7:13:50 下午 org.springframework.web.servlet.DispatcherServlet initServletBean

信息: FrameworkServlet 'mvc': initialization completed in 707 ms

六月 19, 2017 7:13:50 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["http-nio-8080"]

六月 19, 2017 7:13:50 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["ajp-nio-8032"]

六月 19, 2017 7:13:50 下午 org.apache.catalina.startup.Catalina start

信息: Server startup in 2239 ms</strong>

可以看到一个post和一个get接口已经注册成功了。

2.2 注册一个用户

2.3 获取注册的用户

请求id不是123时返回的数据

webapi分层(一个简单Resful结构Web)(1)

是123时返回的数据

webapi分层(一个简单Resful结构Web)(2)

,