mybatis中生成key及for:
一、生成主键:
<insert id="addUserMas" parameterType="user.beans.UUserMas">
<selectKey keyColumn="USER_CODE" keyProperty="userCode" resultType="java.lang.String" order="BEFORE">
select (to_char(sysdate,'yyyymmdd')||'0000'||lpad(USER_CODE_SEQ.nextval,8,'0')) from DUAL
</selectKey>
insert into U_USER_MAS (USER_CODE,
WORK_CODE, USER_TYPE,
REALNAME, "PASSWORD", DEPARTMENT,
"POSITION", AGENT_CODE, "STATUS",
CHANGE_PASSWD_FLAG, CREATOR, CREATE_TIME,
LAST_UPD_PASSWD_TIME, LAST_LOGIN_TIME, CITY_CODE,
BRANCH_CODE)
values (#{userCode,jdbcType=VARCHAR},
#{workCode,jdbcType=VARCHAR}, #{userType,jdbcType=VARCHAR},
#{realname,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{department,jdbcType=VARCHAR},
#{position,jdbcType=VARCHAR}, #{agentCode,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{changePasswdFlag,jdbcType=VARCHAR}, #{creator,jdbcType=VARCHAR}, sysdate,
#{lastUpdPasswdTime,jdbcType=TIMESTAMP}, #{lastLoginTime,jdbcType=TIMESTAMP}, #{cityCode,jdbcType=VARCHAR},
#{branchCode,jdbcType=VARCHAR})
</insert>
二、foreach使用:
1、serviceImp:
List ids = new ArrayList();
ids.add("值");
aApPlanLedgMasMapper.updateByPrimaryKeySelective(ids);
2、进入xml之前
int updateByPrimaryKeySelective(List ids);
3、.xml:
<update id="updateByPrimaryKeySelective">
update A_AP_PLAN_LEDG_MAS
set IS_SUCCESS = '',
apBatchNo = ''
where 1=1 and
AP_LEDG_SEQ_NO in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>
一、生成主键:
<insert id="addUserMas" parameterType="user.beans.UUserMas">
<selectKey keyColumn="USER_CODE" keyProperty="userCode" resultType="java.lang.String" order="BEFORE">
select (to_char(sysdate,'yyyymmdd')||'0000'||lpad(USER_CODE_SEQ.nextval,8,'0')) from DUAL
</selectKey>
insert into U_USER_MAS (USER_CODE,
WORK_CODE, USER_TYPE,
REALNAME, "PASSWORD", DEPARTMENT,
"POSITION", AGENT_CODE, "STATUS",
CHANGE_PASSWD_FLAG, CREATOR, CREATE_TIME,
LAST_UPD_PASSWD_TIME, LAST_LOGIN_TIME, CITY_CODE,
BRANCH_CODE)
values (#{userCode,jdbcType=VARCHAR},
#{workCode,jdbcType=VARCHAR}, #{userType,jdbcType=VARCHAR},
#{realname,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{department,jdbcType=VARCHAR},
#{position,jdbcType=VARCHAR}, #{agentCode,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{changePasswdFlag,jdbcType=VARCHAR}, #{creator,jdbcType=VARCHAR}, sysdate,
#{lastUpdPasswdTime,jdbcType=TIMESTAMP}, #{lastLoginTime,jdbcType=TIMESTAMP}, #{cityCode,jdbcType=VARCHAR},
#{branchCode,jdbcType=VARCHAR})
</insert>
二、foreach使用:
1、serviceImp:
List ids = new ArrayList();
ids.add("值");
aApPlanLedgMasMapper.updateByPrimaryKeySelective(ids);
2、进入xml之前
int updateByPrimaryKeySelective(List ids);
3、.xml:
<update id="updateByPrimaryKeySelective">
update A_AP_PLAN_LEDG_MAS
set IS_SUCCESS = '',
apBatchNo = ''
where 1=1 and
AP_LEDG_SEQ_NO in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>