批量:获取编辑列表及提交

来源:互联网 发布:重庆爱知日语招聘 编辑:程序博客网 时间:2024/06/02 02:56

1

// 批量编辑列表@RequestMapping("/editItemsQuery")public ModelAndView editItemsQuery(HttpServletRequest request,ItemsQueryVo itemsQueryVo) throws Exception {List<ItemsCustom> itemsList = itemsService.findItemsList(itemsQueryVo);ModelAndView modelAndView = new ModelAndView();modelAndView.addObject("itemsList", itemsList);modelAndView.setViewName("items/editItemsQuery");return modelAndView;}// 批量编辑提交@RequestMapping("/editItemsAllSubmit")public String editItemsAllSubmit(ItemsQueryVo itemsQueryVo)throws Exception {return "success";}


2.springmvc注解开发-validation校验-商品修改校验

// 编辑提交@RequestMapping("/editItemsSubmit")public String editItemsSubmit(HttpServletRequest request,Integer id,@Validated ItemsCustom itemsCustom,BindingResult bindingResult) throws Exception {// 获取校验错误信息if (bindingResult.hasErrors()) {// 输出错误信息List<ObjectError> allErrors = bindingResult.getAllErrors();for (ObjectError objectError : allErrors) {System.out.println("\n校验器下面:");// 输出错误信息System.out.println(objectError.getDefaultMessage());}}// 调用service更新商品信息,页面需要将商品信息传到此方法itemsService.updateItems(id, itemsCustom);return "success";}

CustomValidationMessages.properties

#添加校验错误提交信息items.name.length.error=请输入1到30个字符的商品名称items.createtime.isNUll=请输入商品的生产日期

 这自来是POJO类名的

    @Size(min=1,max=30,message="{items.name.length.error}")    private String name;    @NotNull(message="{items.createtime.isNUll}")    private Date createtime;


<!-- 显示错误信息 --><c:if test="${allErrors!=null }"><c:forEach items="${allErrors }" var="error">${ error.defaultMessage } <br/></c:forEach></c:if>


3.springmvc注解开发-validation校验-分组校验

public interface ValidGroup1 {//接口中不需要定义任何方法,仅是对不同的校验规则进行分组//此分组只校验商品名称长度}

public interface ValidGroup2 {//接口中不需要定义任何方法,仅是对不同的校验规则进行分组}


POJO类
    //校验名称在1到30字符中间    //message是提示校验出错显示的信息    //groups:此校验属于哪个分组,groups可以定义多个分组    @Size(min=1,max=30,message="{items.name.length.error}",groups={ValidGroup1.class})    private String name;

// 编辑提交// value={ValidGroup1.class}指定使用ValidGroup1分组的 校验@RequestMapping("/editItemsSubmit")public String editItemsSubmit(Model model,HttpServletRequest request,Integer id,@Validated(value={ValidGroup1.class}) ItemsCustom itemsCustom,BindingResult bindingResult) throws Exception {


4.springmvc注解开发-数据回显

// @ModelAttribute可以指定pojo回显到页面在request中的key@RequestMapping("/editItemsSubmit")public String editItemsSubmit(Model model,HttpServletRequest request,Integer id,@ModelAttribute("items") @Validated(value={ValidGroup1.class}) ItemsCustom itemsCustom,BindingResult bindingResult) throws Exception {

// 商品类型//子路径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;}
<td>商品名称:<input name="itemsCustom.name" />商品类型:<select name="itemtype"><c:forEach items="${itemtypes }" var="itemtype"><option value="${itemtype.key }">${itemtype.value }</option></c:forEach></select></td>


// 获取校验错误信息if (bindingResult.hasErrors()) {// 输出错误信息List<ObjectError> allErrors = bindingResult.getAllErrors();for (ObjectError objectError : allErrors) {System.out.println("\n校验器下面:");// 输出错误信息System.out.println(objectError.getDefaultMessage());}model.addAttribute("allErrors", allErrors);model.addAttribute("items", itemsCustom);return "items/editItems";}


5.

6.

0 0