zoukankan      html  css  js  c++  java
  • HIbernate 查询拼接参数

    public List<TrailTestModel> findByEid(List<String> trailids, String eid) {
    // TODO Auto-generated method stub
    String hql = " from TrailTestModel where 1=1 ";
    ArrayList<String> count = new ArrayList<String>();
    if (trailids != null && trailids.size() > 0) {
    hql += " and trail.uid in (:trailids) ";
    }
    if (StringUtils.isNotBlank(eid)) {
    hql += " and employee.uid = :eid ";
    count.add(eid);
    }
    Query query = hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(hql);
    Object[] arr = new Object[trailids.size()];
    for (int i = 0; i < trailids.size(); i++) {
    arr[i] = trailids.get(i);
    }
    if (trailids != null && trailids.size() > 0) {
    query.setParameterList("trailids", arr);
    }
    if (StringUtils.isNotBlank(eid)) {
    query.setParameter("eid", eid);
    }
    List<TrailTestModel> list = query.list();
    return list;
    }

    ---------------------------------------------------------------------------------------------------------------------------

    @Override
    public Map<String, List<ZhuanTiModel>> list(Integer currentNo, Integer pageSize, String qc, String yunying_name, Integer toufang_state,
    Integer page_type, Integer zhuanti_state, Integer qcstate, String dept_id) {
    // TODO Auto-generated method stub
    HashMap<String, List<ZhuanTiModel>> map = new HashMap<String, List<ZhuanTiModel>>();
    List<Object> count = new ArrayList<Object>();
    String sql = "select * from t_zhuanti where 1=1 ";
    if (StringUtils.isNotBlank(yunying_name)) {
    sql += " and yunying_name like ? ";
    count.add("%"+yunying_name+"%");
    }
    if (StringUtils.isNotBlank(qc)) {
    sql += " and qc_name = ? ";
    count.add(qc);
    }
    if (toufang_state != null) {
    sql += " and toufang_state= ? ";
    count.add(toufang_state);
    }
    if (zhuanti_state != null) {
    sql += " and zhuanti_url_state=? ";
    count.add(zhuanti_state);
    }
    if (page_type != null) {
    sql += " and page_type=? ";
    count.add(page_type);
    }
    if (qcstate != null) {
    sql += " and qc_state=? ";
    count.add(qcstate);
    }
    if (StringUtils.isNotBlank(dept_id)) {
    sql += " and dept_id=? ";
    count.add(dept_id);
    }
    sql += " order by create_time desc";
    Query query = hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql).addEntity(ZhuanTiModel.class);
    for (int i = 0; i < count.size(); i++) {
    query.setParameter(i, count.get(i));
    }
    List<ZhuanTiModel> total = query.list();
    query.setFirstResult((currentNo - 1) * pageSize);
    query.setMaxResults(pageSize);
    List<ZhuanTiModel> list = query.list();
    map.put("total", total);
    map.put("list", list);
    return map;
    }

  • 相关阅读:
    bootstrap收费模版,里面也有后台模版
    漂亮的后台设计
    table ie td宽度 bug
    何让WordPress博客首页不显示某分类的所有文章?
    WordPress不同分类使用不同列表样式
    wordpress学习笔记(一)
    Chariot主题是一款专业自适应Wordpress作品主题
    洛谷P1450 [HAOI2008]硬币购物 动态规划 + 容斥原理
    洛谷P2671 求和 数学 前缀和
    洛谷1288 取数游戏II 博弈论
  • 原文地址:https://www.cnblogs.com/coderdxj/p/6650477.html
Copyright © 2011-2022 走看看