问题描述
我想,以避免额外的XML mybatis3定义映射。注释正适合你
I am trying to avoid having an additional xml to define the mapper in mybatis3. Annotation fits right in.
我有点被@ SelectProvider / @ InsertProvider /等的使用混淆。不要以为有很多资源在网上引导我通过这个。
I am a bit confused by the usage of @SelectProvider/@InsertProvider/etc. Don't think there are many resources online guiding me through this.
基本上,我会想寻找其他的注解版本在mybatis3。
Basically, I will like to find the annotation version of alternative for in mybatis3.
例如,我有一个XML映射器,我想将其转换为使用注释
For example, I have a xml mapper and I wanna convert it to use annotation
<select ...>
<where>
<if cause.....>
</if>
<if cause......>
</if>
</where>
</select>
谁能提供一个具体的答案/解决方案,包括code?
Could anyone provide a concrete answer/solution including the code?
在此先感谢!
推荐答案
你的替代解决方案。
您可以添加&LT;脚本&GT;
在你@annotation年初
you can add <script>
at the beginning of your @annotation
@Update("""<script>
update Author
<set>
<if test="username != null">username=#{username},</if>
<if test="password != null">password=#{password},</if>
<if test="email != null">email=#{email},</if>
<if test="bio != null">bio=#{bio}</if>
</set>
where id=#{id}
</script>""")
在额外的,我们编译.groovy作为在我们的项目中的.class,因此,我们可以写SQL在@annotation像上面
In additional, we compile .groovy to .class in our projects, thus, we can write SQL in @annotation like above
这篇关于如何MyBatis中使用动态SQL查询与注释(如何使用selectProvider)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!