关于页面传值页面的跳转,以及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">

 

posted on 2016-04-05 22:58  有酒有故事  阅读(1148)  评论(0编辑  收藏  举报

导航