mybatis mysql 插入物件返回資料主鍵id
阿新 • • 發佈:2019-01-26
RuleTypeMapper.xml 檔案原始碼
<insert id="insertRuleType" useGeneratedKeys="true" keyProperty="id" parameterType="com.haier.gsp.core.model.rule.RuleType" > insert into rule_type (type_name, create_user, create_date) values ( #{typeName,jdbcType=VARCHAR}, #{createUser,jdbcType=BIGINT},NOW()) </insert>
RuleTypeServiceImpl.java 檔案原始碼
/** * 儲存規則類別 * @param ruleType,uid * @return */ @Override @Transactional public Response<String> insertRuleType(RuleType ruleType,Long uid) { Response<String> response = new Response<>(); ruleType.setCreateUser(uid);
System.out.println("前:"+ ruleType.getId());
Integer id = ruleTypeDao .insertRuleType(ruleType);
System.out.println("後:"+ ruleType.getId());
//結果 前:0 後:18List<ComBoxObj> users = ruleType.getUsers(); List<RuleType> records = new ArrayList<RuleType>(); for (ComBoxObj user:users){ RuleType types = new RuleType(); types.setId(ruleType.getId()); types.setUserId(Long.valueOf