mybatis-generator 1.3.5支持流式 fluent 方法

在以往的无数此写model的过程中,大家都会烦恼model的set方法写一堆。比如

Person p = new Person();
p.setName("name");
p.setAge(5);
p.setLocation("location");
.....


代码冗余且不优美,在最新的1.3.5版本中。由stefanlack 提交的MR加入此了功能,只需要在generatorConfig.xml的context节点下加入配置

<plugin type="org.mybatis.generator.plugins.FluentBuilderMethodsPlugin" /> 

就可以生成带有fluent风格的model代码。

public Person withId(Long id) {
this.setId(id);
return this;
}

public Person withUserId(Integer userId) {
this.setUserId(userId);
return this;
}

 

使用起来就方便多了

Person p = new Person();
p.withId(1).withName("name").withAge(5);

 

posted @ 2017-01-06 14:35  CandyLeer  阅读(1307)  评论(0)    收藏  举报