首页 > 其他 > 详细

mybatis-generator 1.3.5支持流式 fluent 方法

时间:2017-01-06 15:28:06      阅读:377      评论:0      收藏:0      [点我收藏+]

在以往的无数此写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);

 

mybatis-generator 1.3.5支持流式 fluent 方法

原文:http://www.cnblogs.com/candylee/p/6256218.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!