数据回显

来源:互联网 发布:中科院软件所怎么样 编辑:程序博客网 时间:2024/05/18 13:26

springmvc默认对pojo数据进行回显

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

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


2.@ModelAttribute("")



//商品分类

---controller
@ModelAttribute("itemTypes")
public Map<String,String> getItemTypes(){
Map<String,String> itemTypes = new HashMap<String,String>();
itemTypes.put("101", "数码");
itemTypes.put("102", "母婴");
return itemTypes;
}

----页面

商品类型:<select>
<c:forEach items="${itemTypes}" var="itemType">
<option value="${itemType.key }">${itemType.value}</option>
</c:forEach>
  </select>


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

model.addAttribute("","");


原创粉丝点击