zoukankan      html  css  js  c++  java
  • nutz的自定义sql

         Pager page = new Pager(pager.getCurrent(), pager.getPageSize());//分页
            NutDao dao = ioc.get(NutDao.class, "dao");
    
            //数据库查询数据
            StringBuffer sb = new StringBuffer();
            sb.append("SELECT o1.id,o1.user_id,o1.name,o1.create_time,a3.name AS customer_name,a3.mobile,o4.user_contact FROM。。。")
    if(StringUtils.isNotBlank(keyWords)){
                sb.append(" where o1.name like '%"+keyWords+"%' or a3.name like '%"+keyWords+"%' or a3.mobile like '%"+keyWords+"%' or o4.user_contact like '%"+keyWords+"%'");
            }
    
            Sql sql = Sqls.create(sb.toString());
            if(pager != null){
                sql.setPager(page);
            }
            sql.setCallback(new SqlCallback() {
                @Override
                public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
                    List list = new LinkedList();
                    while (null != rs && rs.next()) {
                        HashMap c = new HashMap();
                        c.put("id", rs.getInt("id"));
                        c.put("userId", rs.getString("user_id"));
                        c.put("name", rs.getString("name"));
                        c.put("createTime", rs.getLong("create_time"));
                        c.put("customerName", rs.getString("customer_name"));
                        c.put("mobile", rs.getString("mobile"));
                        c.put("userContact", rs.getString("user_contact"));
                        list.add(c);
                    }
                    return list;
                }
            });
            dao.execute(sql);
            List<HashMap> list = sql.getList(HashMap.class);

    以上是自定义sql(因为有联查)的实现,其中要想获取数据是需要callback

    当然还有普通的自定义sql查询:

    List<SecurityServiceInstance> instanceList = operationSecurityServiceInstanceDAO.
                        query(SecurityServiceInstance.class, Cnd.where("customer_id", "=", userId)
                                .and("manage_status", "=", ManageStatusEnum.MANAGE.getCode())
                                .and("special_line_id", "=", id));

    其中,operationSecurityServiceInstanceDAO继承了NutDao

    持续更新中、、、

  • 相关阅读:
    Meteor + node-imap(nodejs) + mailparser(nodejs) 实现完整收发邮件
    详解log4j2(上)
    循序渐进之Spring AOP(6)
    循序渐进之Spring AOP(5)
    循序渐进之Spring AOP(3)
    循序渐进之Spring AOP(4)
    循序渐进之Spring AOP(2)
    循序渐进之Spring AOP(1)
    通俗的解释JAVA wait/notify机制
    开发高性能JAVA应用程序基础(内存篇)
  • 原文地址:https://www.cnblogs.com/notchangeworld/p/11692311.html
Copyright © 2011-2022 走看看