idea-mybatis-generator插件

可以不通过maven配置,利用idea插件idea-mybatis-generator完成pojoMapperDao的自动生成

注意:xml文件代码生成路径通常设置为XXX/src/main/resources,包路径设置为mapper,application.yml中设置

mapper-locations: classpath:mapper/**/*.xml

1
2
3
4
5
6
7
8
9
10
// 查询测试
@Test
void contextLoads() {

BasicActor build = BasicActor.QueryBuild().actorName("超级管理员").build();

List<BasicActor> actors = mapper.queryBasicActor(build);

System.out.println(actors);
}

有需要自定义的sql接口,可以写在BaseMapper中(默认为空),对应的xml写在base.xml中(默认为空)

利用插件生成的内部builder类去实例化一个对象

1
2
3
4
5
6
7
8
9
@Test
void update(){
BasicActor basicActor = new BasicActor();
basicActor.setActorName("财务1");
BasicActor.ConditionBuilder build = BasicActor.ConditionBuild().fuzzyActorName("财").build();
BasicActor.UpdateBuilder updateBuilder = BasicActor.UpdateBuild().set(basicActor).where(build).build();
// UPDATE `basic_actor` SET `actorName` = `财务1` where ( `ActorName` like concat('%',`财`,'%') )
mapper.update(updateBuilder);
}
1
2
3
4
5
6
7
8
9
10
11
@Test
void queryBasicActor(){
BasicActor actor = BasicActor.QueryBuild().actorIdBetWeen(3, 10).build();
// select `actorId`, `actorName` from `basic_actor` where `actorId` >= 3 and `actorId` <= 10
List<BasicActor> actors = mapper.queryBasicActor(actor);
// select `actorId`, `actorName` from `basic_actor` where `actorId` >= 3 and `actorId` <= 10 limit 1
BasicActor basicActor = mapper.queryBasicActorLimit1(actor);
BasicActor build = BasicActor.Build().actorName("财务").build();
// select `actorId`, `actorName` from `basic_actor` where `actorName` = `财务`
List<BasicActor> basicActors = mapper.queryBasicActor(build);
}
赏个🍗吧
0%