一、通过使用@Options注解,将数据库的自增字段id中的值写到eemLeader对象的id字段,之后在其他地方使用
(useGeneratedKeys = true, keyColumn = "id" , keyProperty = "id")
@Insert("insert into eem_leader(code,dept_id,name,gender,birthday,nation,politics_status,education,hire_date,working_state," +
"del_flag,create_by,create_time,update_by,update_time,remark) " +
"values(#{code},#{deptId},#{name},#{gender},#{birthday},#{nation},#{politicsStatus},#{education},#{hireDate},#{workingState}," +
"#{delFlag},#{createBy},null,null,null,remark)")
int addLeaderBasicInfo(EemLeader eemLeader);
二、通过动态SQL写入List类型的数据
("<script>" +
"insert into eem_leader_duty(admin_group,position,external_director_type,external_director_source,begin_date,end_date,leader_id)" +
" values " +
"<foreach collection='eemLeaderDutyList' item='oneDuty' separator=','>" +
"(#{oneDuty.adminGroup},#{oneDuty.position},#{oneDuty.externalDirectorType},#{oneDuty.externalDirectorSource}," +
"#{oneDuty.beginDate},#{oneDuty.endDate},#{leaderId})" +
"</foreach>" +
"</script>")
int addLeaderDutyInfo(@Param("leaderId") long leaderId,@Param("eemLeaderDutyList") List<EemLeaderDuty> eemLeaderDutyList);
三、通过动态SQL查询数据
("<script>" +
"select * from eem_leader,sys_dept,eem_leader_duty,eem_position where " +
"eem_leader.dept_id=sys_dept.dept_id and eem_leader.id=eem_leader_duty.leader_id " +
"and eem_leader_duty.position=eem_position.id " +
"and eem_leader_duty.admin_group in(select dict_code from sys_dict_data where dict_type='eems_admin_group') " +
"<if test='deptName !=null '> and dept_name =#{deptName} </if> " +
"<if test='name !=null '> and eem_leader.name =#{name} </if> " +
"<if test='adminGroupId!=0 '> and eem_leader_duty.admin_group =#{adminGroupId} </if> " +
"<if test='positionId!=0'> and eem_leader_duty.position =#{positionId} </if> "+
"</script>")
List<Map<String,Object>> getLeaderListByQueryCondition(QueryCondition queryCondition);