目录
jsp页面,controller,requestmapping
前端页面
controller
@RequestMapping("/queryitems")
限制请求的方法method={RequestMethod.POST,RequestMethod.GET}
包装类型的pojo参数类型绑定
数组类型的参数绑定
jsp页面,controller,requestmapping
springmvc将jsp写在WebRoot/WEB-INF下,不能直接访问。需要通过控制器来决定那个页面可以被访问,所以能看到那个页面是由contrller来决定。
产生一个请求到contrller,contrller跟据请求的参数决定返回视图。(controller中注解requestmapping表示接收这个请求,通过return表示转到那个jsp页面上。)
前端页面将一组数据传到controller可以通过定义一个,这样,页面中的属性将会被controller接收到。springmvc将url和controller方法映射
前端页面
在springmvc中,前端页面中属性的name要与pojo中的属性值同名,这样在controller进行参数绑定时才可以自动成功绑定到。
查询商品列表
查询条件:
商品列表:
商品名称
商品价格
生产日期
商品描述
操作
${item.name }
${item.price }
${item.detail }
action="${pageContext.request.contextPath }/items/queryitems.action,
controller
controller的queryitems的写法:
@Autowired
ItemsService itemsService;
@RequestMapping("/queryitems")
public ModelAndView queryItems() throws Exception {
Listitemslist = itemsService.findItemList(null);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("itemslist", itemslist);
modelAndView.setViewName("items/itemslist");
return modelAndView;
}
@RequestMapping("/queryitems")
注解表示接收queryitems这个请求并处理
controller除了可以返回ModelAndView还可以返回String,如果返回的是String,则返回的是url。
如果不使用ModelAndView返回,那么将通过形参绑定的方式返回数据
<