数据回显

来源:互联网 发布:淘宝怎么贷款最高额度 编辑:程序博客网 时间:2024/05/23 01:15

数据回显

 1.什么是数据回显

提交表单后,如果出现错误,将刚才提交的数据回显到刚才提交的页面

2.pojo数据回显方法

2.1springmvc默认对pojo的数据进行回显

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

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

@ModelAttribute还可以将方法的返回值传到页面,如在商品查询列表页面,通过商品类型查询商品信息,在controller中定义商品类型查询方法,最终将商品类型传到页面:

//商品分类//itemtypes表示最终将方法返回值放在request中的key@ModelAttribute("itemtypes")public Map<String,String> getItemTypes(){Map<String,String> itemTypes=new HashMap<String,String>();itemTypes.put("101","数码");itemTypes.put("102","母婴");return itemTypes;}
页面上可以得到itemTypes数据

商品类型<select name="itemtype"><c:forEach items="${itemtypes}" var="itemtype">
<option value="itemtype.key">${itemtype.value}</option></c:forEach></select>
2.3最简单方法使用model,可以不用@ModelAttribute
model.addAttribute(" ", );

3.简单类型数据回显

使用最简单方法model


0 0
原创粉丝点击