关于mybatis 的SQL语句查询

动态查找返回记录数

<select id="findObjectsCountByFuzzyProperty" parameterType="map" resultType="int">

SELECT count(fid) FROM t_msg_schedule${tenantId}
<trim prefix="WHERE" prefixOverrides="AND"> 
<if test="parameter.projectId != null and parameter.projectId != ''">
AND fproject_id LIKE CONCAT(#{parameter.projectId},'%' )
</if>
<if test="parameter.projectHandleStatus != null and parameter.projectHandleStatus != ''">
AND fproject_handle_status LIKE CONCAT(#{parameter.projectHandleStatus},'%' )
</if>
<if test="parameter.content != null and parameter.content != ''">
AND fcontent LIKE CONCAT(#{parameter.content},'%' )
</if>
<if test="parameter.treatPerson != null and parameter.treatPerson != ''">
AND ftreat_person LIKE CONCAT(#{parameter.treatPerson},'%' )
</if>
<if test="parameter.status != null and parameter.status != ''">
AND fstatus LIKE CONCAT(#{parameter.status},'%' )
</if>
<if test="parameter.createTime != null and parameter.createTime != ''">
AND fcreate_time LIKE CONCAT(#{parameter.createTime},'%' )
</if>
        </trim>

</select>

动态查找返回对象

     结果返回resultMap,入参也用map


  <!-- esultMap -->
<resultMap id="ResultMap" type="com.szewec.pms.sysmsg.model.Schedule">
<id column="fid" property="id" jdbcType="VARCHAR" />
<result column="fproject_id" property="projectId" jdbcType="VARCHAR" />
<result column="fproject_handle_status" property="projectHandleStatus" jdbcType="INTEGER" />
<result column="fcontent" property="content" jdbcType="VARCHAR" />
<result column="ftreat_person" property="treatPerson" jdbcType="VARCHAR" />
<result column="fstatus" property="status" jdbcType="INTEGER" />
<result column="fcreate_time" property="createTime" jdbcType="DATE" />
</resultMap>


<select id="findObjectByProperty" resultMap="ResultMap" parameterType="map">
SELECT
<include refid="Column_List" />
FROM t_msg_schedule${tenantId}
<trim prefix="WHERE" prefixOverrides="AND"> 
<if test="parameter.id != null and parameter.id != ''">
AND fid = #{parameter.id,jdbcType=VARCHAR}
</if>
<if test="parameter.projectId != null and parameter.projectId != ''">
AND fproject_id = #{parameter.projectId,jdbcType=VARCHAR}
</if>
<if test="parameter.projectHandleStatus != null and parameter.projectHandleStatus != ''">
AND fproject_handle_status = #{parameter.projectHandleStatus,jdbcType=INTEGER}
</if>
<if test="parameter.content != null and parameter.content != ''">
AND fcontent = #{parameter.content,jdbcType=VARCHAR}
</if>
<if test="parameter.treatPerson != null and parameter.treatPerson != ''">
AND ftreat_person = #{parameter.treatPerson,jdbcType=VARCHAR}
</if>
<if test="parameter.status != null and parameter.status != ''">
AND fstatus = #{parameter.status,jdbcType=INTEGER}
</if>
<if test="parameter.createTime != null and parameter.createTime != ''">
AND fcreate_time = #{parameter.createTime,jdbcType=DATE}
</if>
        </trim>
</select>

猜你喜欢

转载自blog.csdn.net/wangweirong1205/article/details/68483426
今日推荐