mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
remove deprecated methods
This commit is contained in:
@@ -2,6 +2,7 @@ package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.db.handler.EntityListHandler;
|
||||
import cn.hutool.db.pojo.User;
|
||||
import cn.hutool.db.sql.Condition;
|
||||
@@ -189,4 +190,11 @@ public class CRUDTest {
|
||||
int[] result = db.insert(CollUtil.newArrayList(data1));
|
||||
Console.log(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectInTest() throws SQLException {
|
||||
final List<Entity> results = db.query("select * from user where id in (:ids)",
|
||||
MapUtil.of("ids", new int[]{1, 2, 3}));
|
||||
Assert.assertEquals(2, results.size());
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,18 +28,18 @@ public class NamedSqlTest {
|
||||
Assert.assertEquals("张三", namedSql.getParams()[0]);
|
||||
Assert.assertEquals("小豆豆", namedSql.getParams()[1]);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void parseTest2() {
|
||||
String sql = "select * from table where id=@id and name = @name1 and nickName = :subName";
|
||||
|
||||
|
||||
Map<String, Object> paramMap = MapUtil
|
||||
.builder("name1", (Object)"张三")
|
||||
.put("age", 12)
|
||||
.put("subName", "小豆豆")
|
||||
.put("id", null)
|
||||
.build();
|
||||
|
||||
|
||||
NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||
Assert.assertEquals("select * from table where id=? and name = ? and nickName = ?", namedSql.getSql());
|
||||
//指定了null参数的依旧替换,参数值为null
|
||||
@@ -73,6 +74,18 @@ public class NamedSqlTest {
|
||||
Assert.assertEquals(sql, namedSql.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInTest(){
|
||||
String sql = "select * from user where id in (:ids)";
|
||||
final HashMap<String, Object> paramMap = MapUtil.of("ids", new int[]{1, 2, 3});
|
||||
|
||||
NamedSql namedSql = new NamedSql(sql, paramMap);
|
||||
Assert.assertEquals("select * from user where id in (?,?,?)", namedSql.getSql());
|
||||
Assert.assertEquals(1, namedSql.getParams()[0]);
|
||||
Assert.assertEquals(2, namedSql.getParams()[1]);
|
||||
Assert.assertEquals(3, namedSql.getParams()[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryTest() throws SQLException {
|
||||
Map<String, Object> paramMap = MapUtil
|
||||
|
Reference in New Issue
Block a user