MyBatis中 <sql>标签和<include>标签

<sql>这个元素可以被用来定义可重用的 SQL 代码段,可以包含在其他语句中。它可以被静态地(在加载参数) 参数化. 不同的属性值通过包含的实例变化.

<sql id="table">
from users
<where>
<if test="id != null"> id= #{id} </if>
</where>
</sql>

<select id="getName" parameterType="map" resultMap="map">
select name
<include refid="table"/>
</select>

<sql id="property">
  account,password
</sql>

<select id="getUser" parameterType="map" resultMap="map">
    select 
    <include refid="property"/>
    <include refid="table"/>
</select>
  • 感谢您的阅读。如果感觉文章对您有用,麻烦您动动手指点个赞,以资鼓励。谢谢!

猜你喜欢

转载自blog.csdn.net/lihua5419/article/details/81098962
今日推荐