注解SpringMVC

时间:2025-04-12 11:37:37
<!--注解映射器 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<!--注解适配器 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/> <!-- 对于注解的Handler可以单个配置
实际开发中建议使用组件扫描
-->
<!-- <bean class="cn.itcast.ssm.controller.ItemsController3" /> -->
<!-- 可以扫描controller、service、...
这里让扫描controller,指定controller的包
-->
<context:component-scan base-package="com.test.handler.items"></context:component-scan>

对于handler不需要实现任何接口

@Controller
public class ItemsHandler3 { @RequestMapping("/queryitems")
public ModelAndView queryitems(){
//*****************
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject(itemsList);
modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
return modelAndView;
}

访问路径为/queryitems.action