===================resultMap:实体类的属性和通过resultMap映射后的property属性一致
<resultMap id="workerSelect" type="com.eaju.soms.entity.vo.WorkerSelectEntity">
<result column="worker_id" property="workerId" jdbcType="VARCHAR" />
<result column="NAME" property="workerName" jdbcType="VARCHAR" />
<result column="phone" property="workerPhone" jdbcType="VARCHAR" />
</resultMap>
<select id="getSelectWorkers" resultMap="workerSelect">
SELECT t.`worker_id`,t.`name`,t.`phone` FROM t_workers t WHERE t.certification_status = 1 AND t.is_locking = 0 AND t.is_delete = 0 AND t.user_status = 1 AND t.`leader_id`=#{leaderId}
</select>
------------------------------------------resultMap关联两个实体类:<collection>
<resultMap id="userMap" type="org.tedu.cloudnote.entity.User">
<id property="cn_user_id" column="cn_user_id">
<result property="cn_user_name" column="cn_user_name"/>
.................
<!-- 指定books属性装载数据-->
<collection property="books" javaType="java.util.list" ofType="org.tedu.cloudnote.entity.Book">
<id property="cn_notebook_id" column="cn_notebook_id"/>
<result property="cn_user_id" column="cn_user_id"/>
<result property="cn_notebook_type_id" column="cn_notebook_type_id"/>
<result property="cn_notebook_name" column="cn_notebook_name"/>
</collection>
</resultMap>
<select id="findUserAndBooks"
parameterType="string" resultMap="userMap">
select *
from cn_user u
join cn_notebook b
on(u.cn_user_id=b.cn_user_id)
where u.cn_user_id=#{userId}
</select>
-----------------------------entity
public class User implements Serializable
{
private String cn_user_id;
private String cn_user_name;
private String cn_user_password;
private String cn_user_token;
private List<Book> books;
}
----------------------------------------------
<resultMap id="bookMap" type="org.tedu.cloudnote.entity.Book">
<id property="cn_notebook_id" column="cn_notebook_id"/>
<result property="cn_user_id" column="cn_user_id"/>
.....
<!-- 加载user关联属性值 -->
<association property="user"
javaType="org.tedu.cloudnote.entity.User">
<id property="cn_user_id" column="cn_user_id"/>
<result property="cn_user_name" column="cn_user_name"/>
..........................
</association>
</resultMap>
<!-- 提取所有笔记信息 -->
<select id="findAllBooksAndUser" resultMap="bookMap">
select *
from cn_notebook b
join cn_user u
on(b.cn_user_id=u.cn_user_id)
</select>
======================resultType:实体类的属性必须和数据库的字段一致
<select id="findById" parameterType="string"
resultType="org.tedu.cloudnote.entity.Note">
select * from cn_note
where cn_note_id=#{noteId}
</select>
public class Note implements Serializable
{
private String cn_note_id;
private String cn_notebook_id;
private String cn_user_id;
private String cn_note_status_id;
private String cn_note_type_id;
private String cn_note_title;
private String cn_note_body;
private Long cn_note_create_time;
private Long cn_note_last_modify_time;
}
======================insert
<insert id="insertOperateLog" parameterType="com.eaju.soms.entity.TWorkOrderOperateLog">
INSERT INTO t_work_order_operate_log (
operate_log_id,
work_order_id,
operate_id,
operate_status,
operate_display,
remark,
create_time
)
VALUES
(#{operateLogId},#{workOrderId},#{operateId},#{operateStatus},#{operateDisplay},#{remark},#{createTime})
</insert>
====================update
<update id="quitWorkOrder">
UPDATE t_work_order_transform t
SET t.`transform_status` = 'INACTIVE',
t.`update_time` = now()
WHERE t.work_order_owner_id=#{leaderId}
AND t.work_order_id=#{workOrderId}
</update>
---------------------------------------------------entity
public class Book implements Serializable
{ private String cn_notebook_id; private String cn_user_id; private String cn_notebook_type_id; private String cn_notebook_name; private String cn_notebook_desc; private Timestamp cn_notebook_createtime; //追加关联属性,加载User信息 private User user;
}