问题描述
我试图避免在 mybatis3 中使用额外的 xml 来定义映射器.注释正好适合.
I am trying to avoid having an additional xml to define the mapper in mybatis3. Annotation fits right in.
我对@SelectProvider/@InsertProvider/etc 的用法有点困惑.不要以为网上有很多资源可以指导我.
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中找到alternative for的注解版本.
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>
谁能提供包括代码在内的具体答案/解决方案?
Could anyone provide a concrete answer/solution including the code?
提前致谢!
推荐答案
您的替代解决方案可能是:
An alternative solution for you could be:
在@annotation 的开头添加 <script>
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,因此,我们可以像上面一样在@annotation 中编写 SQL
In additional, we compile .groovy to .class in our projects, thus, we can write SQL in @annotation like above
这篇关于如何在 MyBatis 中使用带注解的动态 SQL 查询(如何使用 selectProvider)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!