1 、用:<mvc:annotation-driven/>
代替下面两行:
<!-- 读取注解 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
2、统一的RequestMapping
3、Model和View分开
@Controller
@RequestMapping("/annotation")
public class TestAnnotationController2 {
@RequestMapping("/test1")
public ModelAndView test1() {
System.out.println("--------------->test1");
ModelAndView modelAndView = new ModelAndView("testAnnotation2");
return modelAndView;
}
/**
* 对ModelAndView进行简化
* @return
*/
@RequestMapping("/test2")
public String test2(Model model) {
System.out.println("--------------->test2");
model.addAttribute("userName", "tom");
return "testAnnotation2";
}
}