예제 #1
0
 @Test
 public void testfindTopList() {
   String sql = "select * from t_user tu order by cname";
   Map<String, Object> params = new HashMap<String, Object>();
   List<User> users = smartJdbcTemplate.findTopList(sql, params, 20, User.class);
   Assert.assertEquals(20, users.size());
 }
예제 #2
0
 @Test
 public void testUpdate() {
   String sql = "update t_user set cname=:cname where cname=:cname";
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("cname", "张扬");
   int w = smartJdbcTemplate.update(sql, params);
   Assert.assertEquals(1, w);
 }
예제 #3
0
 @Test
 public void testGetLong() {
   String sql = "select count(*) from t_user tu where tu.cname=:cname";
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("cname", "张扬");
   long count = smartJdbcTemplate.getLong(sql, params);
   Assert.assertEquals(1, count);
 }
예제 #4
0
 @Test
 public void testGet() {
   String sql = "select * from t_user tu where tu.cname=:cname";
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("cname", "张扬");
   User user = smartJdbcTemplate.get(sql, params, User.class);
   Assert.assertEquals("zhangyang", user.getCcode());
 }
예제 #5
0
 @Test
 public void testFindList() {
   String sql = "select * from t_user tu";
   Map<String, Object> params = new HashMap<String, Object>();
   List<User> users = smartJdbcTemplate.findList(sql, params, User.class);
   for (User u : users) {
     System.out.format("用户名称:%s,用户代码:%s\n", u.getCname(), u.getCcode());
   }
   Assert.assertEquals(true, users.size() > 0);
 }
예제 #6
0
 @Test
 public void testGetPage() {
   IPage<User> page = new Page<User>(20, 3);
   String sql = "select * from t_user tu order by cname";
   Map<String, Object> params = new HashMap<String, Object>();
   page = smartJdbcTemplate.getPage(sql, params, page, User.class);
   Assert.assertEquals(20, page.getPageSize());
   Assert.assertEquals(40, page.getStartRow());
   Assert.assertEquals(3, page.getCurrentPage());
   Assert.assertEquals(301, page.getTotalCount());
   Assert.assertEquals(20, page.getResults().size());
 }
예제 #7
0
  @Test
  public void testBatchUpdate() {
    String sql = "update t_user set cname=:cname where cname=:cname";
    @SuppressWarnings("unchecked")
    Map<String, Object>[] maps = new HashMap[3];
    for (int i = 0; i < 3; i++) {
      maps[i] = new HashMap<String, Object>();
      maps[i].put("cname", "张扬");
    }

    int[] w = smartJdbcTemplate.batchUpdate(sql, maps);
    Assert.assertEquals(3, w.length);
  }
예제 #8
0
 @Test
 public void testExcute() {
   String sql = "select count(*) from t_user tu where tu.cname='张扬'";
   smartJdbcTemplate.execute(sql);
 }