Package com.xiaoleilu.hutool.db.handler

Examples of com.xiaoleilu.hutool.db.handler.EntityHandler


      // 执行非查询语句,返回自增的键,如果有多个自增键,只返回第一个
      Long generatedKey = SqlExecutor.executeForGeneratedKey(conn, "UPDATE " + TABLE_NAME + " set field1 = ? where id = ?", 0, 0);
      log.info("主键:{}", generatedKey);

      /* 执行查询语句,返回实体列表,一个Entity对象表示一行的数据,Entity对象是一个继承自HashMap的对象,存储的key为字段名,value为字段值 */
      List<Entity> entityList = SqlExecutor.query(conn, "select * from " + TABLE_NAME + " where param1 = ?", new EntityHandler(), "值");
      log.info("{}", entityList);
    } catch (SQLException e) {
      Log.error(log, e, "SQL error!");
    } finally {
      DbUtil.close(conn);
View Full Code Here


      // 改,生成SQL为 UPDATE `table_name` SET `字段1` = ?, `字段2` = ? WHERE `条件1` = ?
      runner.update(entity, where);

      // 查,生成SQL为 SELECT * FROM `table_name` WHERE WHERE `条件1` = ? 第一个参数为返回的字段列表,如果null则返回所有字段
      List<Entity> entityList = runner.find(null, where, new EntityHandler());
      log.info("{}", entityList);

      // 分页,注意,ANSI SQL中不支持分页!
      List<Entity> pagedEntityList = runner.page(null, where, 0, 20, new EntityHandler());
      log.info("{}", pagedEntityList);

      // 满足条件的结果数,生成SQL为 SELECT count(1) FROM `table_name` WHERE WHERE `条件1` = ?
      int count = runner.count(where);
      log.info("count: {}", count);
View Full Code Here

      // 改,生成SQL为 UPDATE `table_name` SET `字段1` = ?, `字段2` = ? WHERE `条件1` = ?
      session.update(entity, where);

      // 查,生成SQL为 SELECT * FROM `table_name` WHERE WHERE `条件1` = ? 第一个参数为返回的字段列表,如果null则返回所有字段
      List<Entity> entityList = session.find(null, where, new EntityHandler());
      log.info("{}", entityList);

      // 分页,注意,ANSI SQL中不支持分页!
      List<Entity> pagedEntityList = session.page(null, where, 0, 20, new EntityHandler());
      log.info("{}", pagedEntityList);

      session.commit();
    } catch (Exception e) {
      session.quietRollback();
View Full Code Here

TOP

Related Classes of com.xiaoleilu.hutool.db.handler.EntityHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.