1. spring + spring mvc
web项目中:
spring: applicationContext.xml (IOC配置 AOP配置 数据源配置 事务管理器配置 等等)=>src目录
web项目怎么加载 applicationContext.xml:
web.xml:
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
-------------------------
spring mvc:
springmvc.xml: (springmvc-servlet.xml)
配置了视图解析器,控制器的扫描包,静态资源过滤处理,文件上传下载配置
web项目怎么加载 springmvc.xml:
web.xml
<!-- The front controller of this Spring Web application, responsible for
handling all application requests -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
-------------------------------------------------------
Rest风格(restful):
查询: get api/user/{userid} /api/user
增加:post /api/user
修改:put /api/user/{userid}
删除:delete /api/user/{userid} / /api/user
------------------------------------------------------
测试:
dao/service/: junit测试 spring+junit
controller: 可以用postman(建议升级到最新版,否则可能有bug),后续还有介绍
------------------------------------------------------
@GetMapping @RequestMapping
@GetMapping == @RequestMapping(method = RequestMethod.GET)
@RestController ==@Controller + @ResponseBody