在字符串模板中拼装SQL,字符串支持变量表达式(可以是变量,可以进行运算,可以调用函数),dea 自动补全SQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| String selectSql = sql" select * from ${table} where name = ${name} ";
Data<User> data = jdbc.selectSql(sql, User.class);
boolean isEmpty = data.isEmpty(); User user = data.getOne(); List<User> list = data.getList() Map<Long, User> map = data.getMap(user -> user.getId); String json = data.toJson();
Data data = data.filter(user -> user.age > 10);
String insertOneSql = sql" insert into ${table}(id, name, age) values(${user.id}, ${user.name}, ${user.age}) ";
String insertListSql = sql" insert into ${table}(id, name, age) values ${ for(User user in list) { sql(join=",")" (${user.id}, ${user.name}, ${user.age}) " } } ";
Data data = jdbc.update(insertOneSql);
|