springmvc学习笔记之一

来源:互联网 发布:淘宝如何参加公益宝贝 编辑:程序博客网 时间:2024/06/05 15:25

  1.springmvc默认对pojo数据进行回显。

  pojo数据传入controller方法后,springmvc自动将pojo数据放到request域,key等于pojo类型(首字母小写)

  使用@ModelAttribute指定pojo回显到页面在request中的key

  2.@ModelAttribute还可以将方法的返回值传到页面

  在商品查询列表页面,通过商品类型查询商品信息。在controller中定义商品类型查询方法,最终将商品类型传到页面。

  // 商品分类

  //itemtypes表示最终将方法返回值放在request中的key

  @ModelAttribute("itemtypes")

  public Map getItemTypes() {

  Map itemTypes = new HashMap();

  itemTypes.put("101", "数码");

  itemTypes.put("102", "母婴");

  return itemTypes;

  }1234567891011

  页面上可以得到itemTypes数据。

  

  商品名称:

  商品类型:

  

  123456789

  3.使用最简单方法使用model,可以不用@ModelAttribute

  //可以直接使用model将提交pojo回显到页面

  //model.addAttribute("items", itemsCustom);

0 0