Mybatis小技巧

Mybatis 大家想必用得很多,这里给大家介绍两个实战小经验

1 if 标签嵌套

<select>
	select xxx, ccc from A
	left join B on A.a = B.a
	<if test="param='value'">
		left join C on C.c = A.c
	if>
	where A.active = 1
	<if test="param1 = 'value2'">
		and (B.b = '111' 
			<if test="param2 = 'value3'">
			 or C.x = #{aaa}
			if>
		)
	if>
select>
  1. list 可以使用 contains 判断是否包含某个值

注意, 假如list里面是字符串话要对引号进行转义

<select>
	select * from A where A.a = ''
	<if test="list.contains("3")">
		and A.b = ''
	if>
select>

你可能感兴趣的:(JAVA,java)