美文网首页
1.通用mapper一些优异的功能

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

作者: anyly | 来源:发表于2019-10-16 16:28 被阅读0次

以下为通用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. 自带乐观锁实现

相关文章

网友评论

      本文标题:1.通用mapper一些优异的功能

      本文链接:https://www.haomeiwen.com/subject/thkumctx.html