zoukankan      html  css  js  c++  java
  • 关于页面传值页面的跳转,以及spring mvc 框架的流程问题

    list页面

    1.点击页面后,进入后台的list方法中,通过findPage()查询数据的,findPage中含有findList();

    2.如果页面没有输入查询条件,那么则显示所有数据集合,如果页面传人了查询条件的值,则后台list中的controller参数中bean是有值的,如输入姓名作为查询条件,则此时bean的name值是有的,但bean的其他值为null;

    form页面

    1.在弄懂form页面如何工作的,首先要了解下面的代码

         @ModelAttribute//此注解表示每次都最先执行的,也就是进入controller层里这是最先执行的
         public AddressBook get(@RequestParam(required=false) String id) {
           AddressBook entity = null;
           if (StringUtils.isNotBlank(id)){
               entity = addressBookService.get(id);
           }
           if (entity == null){
               entity = new AddressBook();
           }
           return entity;
          }

    2.添加操作:<li><a href="${ctx}/addressBook/form">添加联系人</a></li>,可以看出添加操作时,直接进入form页面

    @RequiresPermissions("addressBook:view")
    @RequestMapping(value = "form")
    public String form(AddressBook bean, Model model) {
         model.addAttribute("bean", bean);
         return "modules/hzzl/addressBookForm";
    }

       但由于1中@ModelAttribute注解先进行1中的get(id),由于没有传id的值,即id为null,过,到form中

      3.修改操作: <a  href="${ctx}/addressBook/form?id=${bean.id}" >修改</a>

         修改操作进入get(id)得到实体bean,此时的bean是有值的,然后将bean中的值form,再带到前台输入框中。

     4.添加和修改在提交时都进入action中的save方法中,

    <li class="active"><a href="form?id=${bean.id}">${not empty bean.id?'修改':'添加'}联系人</a></li>

      5. form表单中的 modelAttribute的值与cotroller中form的model.addAttribute("bean", bean);对应,如此做path就不需要bean.属性值了,直接path=”name”形式即可

    <form:form id="inputForm" modelAttribute="bean" action="${ctx}/addressBook/save" method="post" class="form-horizontal" enctype="multipart/form-data">
  • 相关阅读:
    第4月第1天 makefile automake
    第3月30天 UIImage imageWithContentsOfFile卡顿 Can't add self as subview MPMoviePlayerControlle rcrash
    第3月第27天 uitableviewcell复用
    learning uboot fstype command
    learning uboot part command
    linux command dialog
    linux command curl and sha256sum implement download verification package
    learning shell script prompt to run with superuser privileges (4)
    learning shell get script absolute path (3)
    learning shell args handing key=value example (2)
  • 原文地址:https://www.cnblogs.com/banxian-yi/p/5357284.html
Copyright © 2011-2022 走看看