什么是数据回显:

提交后,如果出现错误(或者别的情况),将刚才提交的数据回显到刚才的提交页面。

pojo数据回显方法:

一、springmvc默认对pojo数据进行回显。

比如现在的jsp页面提示出现错误,页面自动显示之前的数据:

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

这里默认将数据放到itemsCustom中

 1 //商品信息修改提交
 2     @RequestMapping("/editItemsSubmit")
 3     public String editItemsSubmit(Model model,
 4                                   HttpServletRequest request,
 5                                   Integer id, 
 6                                   @Validated(value={ValidGroup1.class}) ItemsCustom itemsCustom,BindingResult bindingResult)
 7                                  throws Exception {
 8         
 9         if(bindingResult.hasErrors()){
10              List<ObjectError> allErrors = bindingResult.getAllErrors();
11              for(ObjectError objectError : allErrors){
12                  System.out.println(objectError.getDefaultMessage());
13              }
14              
15             // 将错误信息传到页面
16             model.addAttribute("allErrors", allErrors);
17             
18             return "items/editItems";
19         }
20         
21         itemsService.updateItems(id, itemsCustom);
22         return "success";
23     }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2021-09-18
  • 2021-09-30
  • 2021-06-07
猜你喜欢
  • 2021-08-03
  • 2021-08-25
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2022-02-25
相关资源
相似解决方案