Mybatis multi parameter and entity object passing examples
- 2020-05-26 08:34:49
- OfStack
When using Mybatis, there are often various parameters passed, different types and different Numbers of parameters.
Let's start with the last example:
public List<LifetouchRelease> findOfficeList(@Param("lifetouchRelease") LifetouchRelease lifetouchRelease,
@Param("advertisementId") String advertisementId, @Param("officeName") String officeName,
@Param("isOnline") Integer isOnline);
<select id="findOfficeList" resultType="LifetouchRelease">
SELECT
<include refid="lifetouchReleaseColumns"/>
FROM lifetouch_release a
<include refid="lifetouchReleaseJoins"/>
<where>
<if test="lifetouchRelease.typeIdentification > 0">
AND a.type_identification = #{lifetouchRelease.typeIdentification}
</if>
<if test="lifetouchRelease.category != null andlifetouchRelease.category.id != null and lifetouchRelease.category.id != ''">
AND a.release_type_id = #{lifetouchRelease.category.id}
</if>
AND a.office_id is not null
AND a.advertisement_id like '%${advertisementId}%'
AND (select name from sys_office where id=a.office_id) like '%${officeName}%'
<if test="isOnline != null">
AND a.del_flag = #{isOnline}
</if>
</where>
<choose>
<when test="lifetouchRelease.page !=null andlifetouchRelease.page.orderBy != null and lifetouchRelease.page.orderBy != ''">
ORDER BY ${lifetouchRelease.page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
Above is one containing: entity object, common type, multiple parameter passing.
Multiple parameters: implemented using annotations
Entity object: entity object is just like normal type parameter passing method 1, only when used, it can be called in the way of object name and (point) object property name.
Other transfers, but the same is true for complex data types.