mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
v1.0.0 prepare
This commit is contained in:
parent
e5f87b8212
commit
d9e7b7d43f
@ -162,6 +162,10 @@ public class FlexConfiguration extends Configuration {
|
|||||||
*/
|
*/
|
||||||
private MappedStatement replaceRowKeyGenerator(MappedStatement ms) {
|
private MappedStatement replaceRowKeyGenerator(MappedStatement ms) {
|
||||||
|
|
||||||
|
//执行原生 SQL,不需要为其设置主键生成器
|
||||||
|
if (ms.getId().endsWith("BySql")) {
|
||||||
|
return ms;
|
||||||
|
}
|
||||||
|
|
||||||
KeyGenerator keyGenerator = new RowKeyGenerator(ms);
|
KeyGenerator keyGenerator = new RowKeyGenerator(ms);
|
||||||
if (ms.getId().endsWith("insertBatchWithFirstRowColumns")) {
|
if (ms.getId().endsWith("insertBatchWithFirstRowColumns")) {
|
||||||
|
|||||||
@ -49,7 +49,6 @@ public class MybatisFlexStarter {
|
|||||||
System.out.println(row);
|
System.out.println(row);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//新增一条数据,自增
|
//新增一条数据,自增
|
||||||
Row newRow = Row.ofKey(RowKey.ID_AUTO) // id 自增
|
Row newRow = Row.ofKey(RowKey.ID_AUTO) // id 自增
|
||||||
.set("user_name", "lisi")
|
.set("user_name", "lisi")
|
||||||
@ -63,11 +62,17 @@ public class MybatisFlexStarter {
|
|||||||
System.out.println(">>>>>>newRow.id: " + newRow.get("id"));
|
System.out.println(">>>>>>newRow.id: " + newRow.get("id"));
|
||||||
|
|
||||||
|
|
||||||
|
bootstrap.execute(RowMapper.class, rowMapper ->
|
||||||
|
rowMapper.insertBySql("insert into tb_account(user_name,age,birthday) values (?,?,?)"
|
||||||
|
, "张三"
|
||||||
|
, 18
|
||||||
|
, new Date()));
|
||||||
|
|
||||||
|
|
||||||
List<Row> newRowList = new ArrayList<>();
|
List<Row> newRowList = new ArrayList<>();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
Row insertRow = Row.ofKey(RowKey.ID_AUTO) // id 自增
|
Row insertRow = Row.ofKey(RowKey.ID_AUTO) //id 自增
|
||||||
.set("user_name", "new_user_"+i)
|
.set("user_name", "new_user_" + i)
|
||||||
.set("age", 22)
|
.set("age", 22)
|
||||||
.set("birthday", new Date());
|
.set("birthday", new Date());
|
||||||
newRowList.add(insertRow);
|
newRowList.add(insertRow);
|
||||||
@ -75,20 +80,20 @@ public class MybatisFlexStarter {
|
|||||||
|
|
||||||
//批量插入数据
|
//批量插入数据
|
||||||
bootstrap.execute(RowMapper.class, rowMapper ->
|
bootstrap.execute(RowMapper.class, rowMapper ->
|
||||||
rowMapper.insertBatchWithFirstRowColumns("tb_account",newRowList));
|
rowMapper.insertBatchWithFirstRowColumns("tb_account", newRowList));
|
||||||
|
|
||||||
|
|
||||||
//查询全部数据
|
//查询全部数据
|
||||||
List<Row> rows = bootstrap.execute(RowMapper.class, rowMapper ->
|
List<Row> rows = bootstrap.execute(RowMapper.class, rowMapper ->
|
||||||
rowMapper.selectAll("tb_account"));
|
rowMapper.selectAll("tb_account"));
|
||||||
|
|
||||||
System.out.println("rows count: " + rows.size()); //8
|
System.out.println("rows count: " + rows.size()); //9
|
||||||
System.out.println(rows);
|
System.out.println(rows);
|
||||||
|
|
||||||
|
|
||||||
//分页查询,第 2 页,每页 3 条数据
|
//分页查询,第 2 页,每页 4 条数据
|
||||||
Page<Row> rowPage = bootstrap.execute(RowMapper.class, rowMapper ->
|
Page<Row> rowPage = bootstrap.execute(RowMapper.class, rowMapper ->
|
||||||
rowMapper.paginate("tb_account", 2, 3, QueryWrapper.create()));
|
rowMapper.paginate("tb_account", 2, 4, QueryWrapper.create()));
|
||||||
System.out.println(rowPage);
|
System.out.println(rowPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user