SpringMvc使用注解的方式
修改配置文件开启注解方式

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="cn.spring.controller"></context:component-scan>
</beans>
controller中通过注解实现
@Controller
public class UserController {
@RequestMapping("/fun1")
public ModelAndView fun1(){
System.out.println("-----fun1-----");
ModelAndView mav = new ModelAndView();
mav.addObject("msg","mag1");
mav.setViewName("/index.jsp");
return mav;
}
@RequestMapping("/fun3")
@ResponseBody
public void fun3(){
System.out.println("-----fun3-----");
}