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);
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
}