亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

java - How to obtain the newly added id in mybatis
天蓬老師
天蓬老師 2017-06-30 09:53:48
0
6
1297

<insert id="saveCustomer" parameterType="com.xiaonatech.dsx.entity.CustomerEntity" useGeneratedKeys="true" keyProperty="policyID">

        insert into customer                 (certType,code,password,name,mobile,effDate,expDate,address,createID,createTime,updateID,updateTime) 
        values
             (#{certType},#{code}, #{password}, #{name}, #{mobile},  #{effDate},#{expDate},#{address},#{createID},#{createTime} ,#{updateID},#{updateTime})
</insert>

dao layer
public int saveCustomer(CustomerEntity cs);
This method always returns 1. The value of object.id is always empty. The database is mysql
CustomerEntity applyRecord = new CustomerEntity();

    applyRecord.setCertType("0");
    applyRecord.setCode("423565462256");
    applyRecord.setPassword("123456");
    applyRecord.setName("sds");
    applyRecord.setMobile("12345678978");
    applyRecord.setCreateID("150");
    applyRecord.setUpdateID("150");
    applyRecord.setUpdateTime(new Date());
    int i = dao.saveCustomer(cs);
    System.out.println("i========="+i+"  id================"+applyRecord.getCarOwnerID());
天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見(jiàn)證您的進(jìn)步~~

reply all(6)
伊謝爾倫

@福生百記 Add useGeneratedKeys="true"

on its basis
學(xué)霸

What this method returns is actually the number of records affected.
You can directly get the ID of the entity class after inserting.

ApplyRecord applyRecord = new ApplyRecord();
applyRecord.setAccount("1234");
applyRecord.setCode("123");
Timestamp now = new Timestamp(System.currentTimeMillis());
applyRecord.setGmtCreate(now);
applyRecord.setGmtModified(now);
int i = applyRecordDao.insert(applyRecord);
logger.info("{}",applyRecord.getId());
淡淡煙草味

Can we take a look at the entity class?

僅有的幸福

useGeneratedKeys="true" keyProperty="id" In the xml configuration, keyProperty is the primary key. Check whether your data number is set with id as the primary key and the period as auto-increment. If so, after the insert is executed, the value of the primary key will be reflected to In the primary key of your entity class

扔個(gè)三星炸死你

<insert id="save" parameterType="atyy.model.ArticleCategoryPO" useGeneratedKeys="true">
</insert>
Just add an attribute useGeneratedKeys="true"

為情所困

1. The database id must be auto_increment
2. Configure useGeneratedKeys="true" and keyProoerty
3. The value you get by calling the mapper interface method, that is, the total 1 you get is the number of records affected. If you want to get the object id, please click and use the corresponding getter method

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template