mybatis通用查詢條件與傳回值
1. mybatis查詢常用标簽
sql标簽:
if标簽:
trim标簽:
prefix=”where”//給第一符合條件的語句 加上字首where
prefixOverrides=”and” //将最後一條語句的 字首and 覆寫
suffix=”and” //給第一符合條件的語句 加上字尾 and
suffixOverrides=”and”//将最後一條語句的字尾 and 覆寫
test标簽:
include标簽:
refid标簽:
where标簽
2.樣例
<!-- 查詢條件 -->
<sql id="where_cnd">
where del_flag = 0
<trim suffixOverrides="," >
<if test="id != null and id != ''" >
and ID = #{id}
</if>
<if test="name!= null and name != ''" >
and NAME = #{NAME}
</if>
</trim>
</sql>
<!-- 傳回值-->
<sql id="Base_Column_List">
ID, NAME
</sql>
<!--查詢語句-->
<select id="getAll" resultMap="BaseResultMap" parameterType="java.lang.String">
SELECT <include refid="Base_Column_List"/> FROM
(SELECT * FROM STUDENT
<include refid="where_cnd"/>
)
order by CREATE_TIME desc
</select>