1.通用mapper一些优异的功能

2019-10-16  本文已影响0人  anyly

以下为通用mapper目前有的一些不错功能

1. Example简化,mbg生成的一般都是**Example,而通用mapper只有一个Example
Example example = new Example(Country.class);
example.setForUpdate(true);
example.createCriteria().andGreaterThan("id", 100).andLessThan("id",151);
example.or().andLessThan("id", 41);
List<Country> countries = mapper.selectByExample(example);
2. 设置查询列,一个表的字段有很多,但是有些情况你却只要一个字段比如(id)
Example example = new Example(Country.class);
example.selectProperties("id", "countryname");
List<Country> countries = mapper.selectByExample(example);
3. 可以自定义主键生成策略,只要自己定义生成策略就可以了
public class UUIdGenId implements GenId<String> {
   @Override
   public String genId(String table, String column) {
       return UUID.randomUUID().toString();
   }
}
public class User {
   @Id
   @KeySql(genId = UUIdGenId.class)
   private String id;
   private String name;
   private String code;

   public User() {
   }

   public User(String name, String code) {
       this.name = name;
       this.code = code;
   }
   //省略 setter 和 getter
}
4. 自带乐观锁实现
上一篇 下一篇

猜你喜欢

热点阅读