欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Struts2 多条件组合查询和准备默认数据

程序员文章站 2023-01-22 20:45:25
在使用ssh的时候,会在daoimpl中生成 findbyexample 和findbyall 一般情况在 我们都会在execute方法中使用findbyall 去给页面准备数据  ...

在使用ssh的时候,会在daoimpl中生成 findbyexample 和findbyall


一般情况在 我们都会在execute方法中使用findbyall 去给页面准备数据

 


加入你页面中 包含了这个action 那么就会出现数据 覆盖的问题


[html]\
<s:action name="category" executeresult="false"></s:action> 

<s:action name="category" executeresult="false"></s:action>
那么现在 在execute方法中 直接使用 findbyexample

查询方法 也在execute中 不必在去写

代码:


[java]
public string execute(){ 
     
    list<category> clist=(list<category>)categoryservice.findbyexample(getcategory()); 
    map map=(map)servletactioncontext.getcontext().get("request"); 
    map.put("categorylist",clist); 
    system.out.println("查询对象,数据大小:"+clist.size()); 
     
    return "success"; 

 public string execute(){
  
  list<category> clist=(list<category>)categoryservice.findbyexample(getcategory());
  map map=(map)servletactioncontext.getcontext().get("request");
  map.put("categorylist",clist);
  system.out.println("查询对象,数据大小:"+clist.size());
  
  return "success";
 }
这样 在最开始的时候,没有任何条件,就是准备所有的数据,

让传入条件,他会根据条件不为null 然后来产品sql语句

类似于:select * from table where name=222.....sex=2222....