版本4.0查询改为模糊查询

一、字典类型查询:

 

DictionaryKindDAOEx:

public class DictionaryKindDAOEx extends DictionaryKindDAO { /** * @author:denghuimin * @createTime:Jul 14, 2009 10:33:30 AM * @function: * @param sql * @return */ public List<Dictionary> findByLike(String sql) { List<Dictionary> list = this.getHibernateTemplate().find(sql); return list; } }

 

DictionaryKindModel:

 

public DictionaryKind dictionaryKind; public DictionaryKind cloneDicKind; public DictionaryKindDAOEx dictionaryKindDAOEx; // 控件可操作标志 // 控件可操作标志 private boolean bolSave = true; private boolean bolInput = true; private boolean bolModify = false; private boolean bolCancel = true; // 是否可保存标志 private boolean bolCanSave = true; // 查询条件变量 private String kindCondition = null; private String detailCondition = null; // 错误信息 private String errorStr; // 字典类型变量 private String dictionaryKindKind; private String dictionaryKindDetail; private String dictionaryKindSource; // 常量 private static final String SCBZ0 = "0"; private static final String SCBZ1 = "1"; private static final String ModifyDictionaryKindPane = "ModifyDictionaryKindPane"; private static final String DictionaryKindListPane = "DictionaryKindListPane"; private static final String AddDictionaryKindPane = "AddDictionaryKindPane"; // 分页变量 protected int rowCount = 0; // 记录数 protected int pageCount = 0; // 总页数 protected int pageSize = GlobalConstants.DEFAULT_PAGE_SIZE;// 每页显示的条数 protected int currentPageNumber = GlobalConstants.DEFAULT_PAGE_NUMBER;// 当前页码 protected int gotoPageNumber = GlobalConstants.DEFAULT_PAGE_NUMBER; public List<DictionaryKind> dklist; /** * * @author:denghuimin,yanghanming * @createTime:Jul 7, 2009 11:41:24 AM * @function:重写父类的findByQueryCondition方法 * @param otherCondition * 查询条件 * @return: */ public String findByQueryCondition(String otherCondition) { String errMessage = ""; List list = new ArrayList<QueryConVo>(); String hql = null; dklist = new ArrayList<DictionaryKind>(); GenarateConnection gc = (GenarateConnection) getCtx().getBean( BizGlobalConstants.X_GCONNECTION); // 当查询条件不为空时候执行这个hql if (StringUtils.isNotBlank(this.getKindCondition()) || StringUtils.isNotBlank(this.getDetailCondition())) { hql = "from DictionaryKind where scbz='0' and kind like '%" + this.getKindCondition().trim() + "%'" + " and detail like '%" + this.getDetailCondition().trim() + "%'"; } else { //当查询条件不为空时候执行这个语句 hql = "from DictionaryKind as ti where 1=1 and ti.scbz ='0'"; } try { this.dklist = gc.findListForPage(hql, list, this .getCurrentPageNumber(), this.getPageSize()); this.rowCount = gc.findCountForPage(hql, list, this .getCurrentPageNumber(), this.getPageSize()); } catch (Exception e) { e.printStackTrace(); } return errMessage; } public String doBriefQuery() { String errMessage = ""; errMessage = findByQueryCondition(dictionaryKind.getKind()); this.fromOutcome = DictionaryKindListPane; return errMessage; } /** * @author:denghuimin,yanghanming * @createTime:Jul 14, 2009 3:35:52 PM * @function:模糊查询 * @return */ public String findByLike() { String sql = "from DictionaryKind where scbz='0' and kind like '%" + this.getKindCondition().trim() + "%'" + " and detail like '%" + this.getDetailCondition().trim() + "%'"; dklist = (List) dictionaryKindDAOEx.findByLike(sql); this.setRowCount(dklist.size()); return null; }

 

 

DictionaryKindListPane.xhtml:

 

<ui:define name="QueryConditionPanel"> <h:form style="margin:0px;" mce_style="margin:0px;" id="theBriefQueryForm"> <table align="center" width="80%"> <tr width="60%"> <td align="right" style="font-size: 10pt;" mce_style="font-size: 10pt;" width="40%"> 字典类型代码: <jsfext:inputText value="#{dictionaryKindModel.kindCondition}" id="kind" tabindex="1" maxlength="64"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <td align="right" style="font-size: 10pt;" mce_style="font-size: 10pt;" width="40%"> 字典类型代码中文: <jsfext:inputText value="#{dictionaryKindModel.detailCondition}" id="zdzwhy" tabindex="2" maxlength="65"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <td align="center" style="font-size: 10pt;" mce_style="font-size: 10pt;" width="20%"> <h:commandButton value=" 查 询 " action="#{dictionaryKindModel.findByLike}" tabindex="3"></h:commandButton> </td> </tr> </table> </h:form> </ui:define>

 

 

二、字典条目查询:

 

DictionaryModel:

private Dictionary dictionary; private Dictionary cloneDic; private DictionaryKind dictionaryKind; private DictionaryDAOEx dictionaryDAOEx; private String kindTemp; private String detailTemp; // 控件可操作标志 private boolean bolSave = true; private boolean bolInput = true; private boolean bolModify = false; private boolean bolCancel = true; // 是否可保存标志 private boolean bolCanSave = true; private boolean bolUpdate = true; // 分页控制标志 private boolean bolByQuery = true; private List<Dictionary> diclist; // 查询条件变量 private String codeCondition; // 区分更新还是保存变量 private String save = null; // 字典条目变量 private String dictionaryKinds; private String dictionaryCode; private String dictionaryDetail; private String dictionarySpell; private String dictionaryWb; private String dictionaryHomophony; private String dictionarySource; private String dictionaryNote; private String dictionaryAimKind; private String dictionaryAimCode; private String dictionaryAimDetail; // 目标字典动态过滤使用的sql private String aimSql = "select code ,detail from T_SYS_DICTIONARY where kind='' "; private String allKindSql = "select detail as code , kind as detail ,'' as spell from T_SYS_DICTIONARYKIND where scbz='0'"; // 常量 private static final String SCBZ0 = "0"; private static final String SCBZ1 = "1"; private static final String ModifyDictionaryPane = "ModifyDictionaryPane"; private static final String DictionaryListPane = "DictionaryListPane"; private static final String AddDictionaryPane = "AddDictionaryPane"; // 分页变量 protected int rowCount = 0; // 记录数 protected int pageCount = 0; // 总页数 protected int pageSize = GlobalConstants.DEFAULT_PAGE_SIZE;// 每页显示的条数 protected int currentPageNumber = GlobalConstants.DEFAULT_PAGE_NUMBER;// 当前页码 protected int gotoPageNumber = GlobalConstants.DEFAULT_PAGE_NUMBER; /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:36:26 AM * @function: * @param otherCondition * @return: */ public String findByQueryCondition(String otherCondition) { String errMessage = ""; String hql = null; List list = new ArrayList<QueryConVo>(); // 点击“字典维护”链接时候,执行此函数,判断bolByQuery标志,第一次获取页面传来的字典类型kind if (bolByQuery) { bolByQuery = false; Map requestParams = FacesContext.getCurrentInstance() .getExternalContext().getRequestParameterMap(); // kindTemp,获取页面传来的字典类型的kind,并以此为条件查找对应的字典条目 kindTemp = (String) requestParams.get("kind"); // detailTemp,获取页面传来的字典类型的中文含义,用来设置字典条目列表的标题 // 页面传过来时出现非中文字符,需要转换为中文字符 detailTemp = CommonFunction .escapeSequenceToString((String) requestParams .get("detail")); this.getDictionaryKind().setDetail(detailTemp); this.getDictionaryKind().setKind(kindTemp); } diclist = new ArrayList<Dictionary>(); GenarateConnection gc = (GenarateConnection) getCtx().getBean( BizGlobalConstants.X_GCONNECTION); // 当查询条件不为空时候执行这个hql if (StringUtils.isNotBlank(this.getCodeCondition())) { hql = "from Dictionary where scbz='0' and kind='" + kindTemp + "' and code like '%" + this.getCodeCondition().trim() + "%'"; } else { //当查询条件不为空时候执行这个语句 hql = "from Dictionary as ti where 1=1 and ti.scbz ='0'"; QueryConVo conVo = new QueryConVo(dictionaryDAOEx.KIND, kindTemp); list.add(conVo); } try { this.diclist = gc.findListForPage(hql, list, this .getCurrentPageNumber(), this.getPageSize()); this.rowCount = gc.findCountForPage(hql, list, this .getCurrentPageNumber(), this.getPageSize()); this.setRowCount(rowCount); } catch (Exception e) { e.printStackTrace(); } return errMessage.trim(); } /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:46:56 AM * @function:查询时在diclist表里面查,不用再次查找数据库 * @return: */ public String findByLike() { List tempList = new ArrayList(); String sql = "from Dictionary where scbz='0' and kind='" + kindTemp + "' and code like '%" + this.getCodeCondition().trim() + "%'"; tempList = dictionaryDAOEx.findByLike(sql); diclist = tempList; this.setRowCount(diclist.size()); return null; } public String doBriefQuery() { String errMessage = ""; errMessage = findByQueryCondition(dictionary.getKind()); this.fromOutcome = DictionaryListPane; return errMessage; }

 

DictionaryDAOEx

 

/** * @author:denghuimin * @createTime:Jul 14, 2009 10:16:29 AM * @function: * @param sql * @return */ public List<Dictionary> findByLike(String sql) { List<Dictionary> list = this.getHibernateTemplate().find(sql); return list; }

 

DictionaryListPane:

<table> <tr> <td> 字典代码: <jsfext:inputText value="#{dictionaryModel.codeCondition}" id="code" tabindex="1" maxlength="50"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <td> <t:commandButton id="briefQueryButton" value=" 查 询 " action="#{dictionaryModel.findByLike}" tabindex="2" forceId="true" /> </td> </tr> </table>

你可能感兴趣的:(sql,exception,function,String,list,Dictionary)