频道栏目
首页 > 资讯 > Jsp > 正文

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

13-05-10        来源:[db:作者]  
收藏   我要投稿

在使用SSH的时候,会在DaoImpl中生成 findByExample 和findByAll


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

 


加入你jsp页面中 包含了这个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....


 

相关TAG标签
上一篇:JQuery WEB前段开发
下一篇:hdu-4519-二分-郑厂长系列故事——体检
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站