Mybatis 关于 xml 语法相关

Mybatis中xml关于大于、小于符号的处理方式

第一种写法: create_time %lt; #{createTime}
<&lt;小于
<=&lt;小于等于
>&gt;大于
>=&gt;=大于等于
&&amp;
'&apos;单引号
"&quot;双引号
第二种写法:<![CDATA[ create_time >= #{createTime} ]]>
>=<![CDATA[ param >= #{param}大于等于
以此类推...

Mybatis中xml关于if语法、for循环语法、类中常量赋值语法,如下示例

<!-- if 语法示例 -->
<if test="paramId != null and paramId != ''">
    AND a.`param_id` = #{paramId}
</if>

<!-- foreach 语法示例 -->
<if test="paramList != null">
    AND a.`param_id` in 
	<foreach collection="paramList" item="id" index="index" open="(" close=")" separator=",">
        #{id}
	</foreach>
</if>

<!-- in 直接赋值语法,注意,这里是美元符号不是井号 -->
<if test="paramListStr != null and paramListStr != ''">
    AND a.`param_id` in (${paramListStr})
</if>

<!-- 类中常量语法示例 -->
<if test="flag == null or flag == ''">
    AND a.`flag` != '${@cn.xx.xx.constant.CommonConstant@FLAG_DELETE}'
</if>

Mybatis中xml 关于自增id,新增记录返回新增记录id的值,配置如下
注意:表 主键 设置为自增方能生效,keyProperty="id",id为主键字段,此值根据主键字段名称自行更改

<!-- 主要是这两句 useGeneratedKeys="true" keyProperty="id" -->
<insert id="insert" parameterType="cn.xx.xx.entity.xx" useGeneratedKeys="true" keyProperty="id">
insert into xx(id)
values (#{id})
</insert>


版权声明:本文为liqing99_原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。