Xml代码:
<resultMap id="BaseResultMap" type="com.yc.pojo.Crouse">
<id column="crouse_id" property="crouseId" jdbcType="BIGINT"/>
<result column="title" property="title" jdbcType="VARCHAR"/>
<result column="crouse_code" property="crouseCode" jdbcType="VARCHAR"/>
<result column="user_id" property="userId" jdbcType="BIGINT"/>
<result column="max_persons" property="maxPersons" jdbcType="INTEGER"/>
<result column="price" property="price" jdbcType="DECIMAL"/>
<result column="crouse_all_times" property="crouseAllTimes" jdbcType="INTEGER"/>
<result column="create_time" property="createTime" jdbcType="VARCHAR"/>
<result column="state" property="state" jdbcType="INTEGER"/>
<association property="students" javaType="com.yc.pojo.CrouseStudent"> <!--association用于对象 -->
<result column="s_id" property="id"
jdbcType="BIGINT"/>
<result column="s_user_id" property="userId"
jdbcType="BIGINT"/>
<result column="s_notes" property="notes"
jdbcType="VARCHAR"/>
<result column="s_state" property="state"
jdbcType="INTEGER"/>
<result column="s_user_status" property="userStatus"
jdbcType="INTEGER"/>
</association>
<collection column="user_id" property="user" ofType="com.yc.pojo.User"> <!--collection用于数组 -->
<result column="u_email" property="email"
jdbcType="VARCHAR"/>
<result column="u_name" property="name"
jdbcType="VARCHAR"/>
<result column="u_head_img" property="headImg"
jdbcType="VARCHAR"/>
<result column="u_tel" property="tel"
jdbcType="VARCHAR"/>
<result column="u_wx_number" property="wxNumber"
jdbcType="VARCHAR"/>
<result column="u_sex" property="sex"
jdbcType="VARCHAR"/>
<result column="u_create_time" property="createTime"
jdbcType="VARCHAR"/>
</collection>
</resultMap>
<select id="selectByQuery" resultMap="BaseResultMap" parameterType="com.yc.query.CrouseQuery">
SELECT
c.*, u.user_id AS u_user_id,
u.email AS u_email,
u. NAME AS u_name,
u.head_img AS u_head_img,
u.tel AS u_tel,
u.wx_number AS u_wx_number,
u.sex AS u_sex,
s.id AS s_id,
s.user_id AS s_user_id,
s.notes AS s_notes,
s.state AS s_state,
s.state AS s_state,
s.user_status AS s_user_status
FROM
crouse c
LEFT JOIN USER u ON u.user_id = c.user_id
LEFT JOIN crouse_details d ON d.crouse_id = c.crouse_id
LEFT JOIN crouse_code cc ON c.crouse_id = cc.code_id
LEFT JOIN crouse_img i ON cc. CODE = c.crouse_code
LEFT JOIN rating r ON r.crouse_id = c.crouse_id
LEFT JOIN crouse_student s ON s.crouse_id = c.crouse_id
<where>c.crouse_id is not null <if test="crouseCode != null">and c.crouseCode LIKE CONCAT('%',
CONCAT(#{crouseCode}, '%'))
</if>
<if test="minPrice != null">and c.price >= #{minPrice}</if>
<if test="maxPrice != null">and c.price
<
#{minPrice}
</if>
<if test="maxPersons != null">and c.max_persons<= #{maxPersons}
</if>
<if test="minTimes != null">and c.price >= #{minPrice}</if>
<if test="maxTimes != null">and c.price
<
#{maxTimes}
</if>
<if test="crouceState == null">and d.state =1</if>
<if test="address == null">and d.address is not null</if>
<if test="startTime == null">and d.address is not null</if>
</where>
</select>