mybatis中的sql标签和include标签

来源:互联网 发布:tomcat centos 编辑:程序博客网 时间:2024/06/16 18:03

<sql>标签作用类似于封装,将sql语句封装起来

<include>就是用来调用<sql>封装的sql语句

如下:

<sql id="test">  id, name,password,sex,age</sql>

<select id="select" parameterType="java.lang.String" resultType="User">  select   <include refid="test" />
  from user
where id = #{id,jdbcType=VARCHAR}</select>

上面等价于  select  id , name , password , sex , age from user ......


也可以用sql不仅仅可以封装字段,也可以封装整个sql语句或者判断条件

原创粉丝点击