ibatis annotations Annotations way to write sql return to growth since the primary key value of the newly inserted ID

mybatis ways to prepare for annotations sql, when inserting a data record, the data is not inserted into the ID value needs to be returned from the growth ID value, when writing one line of code needs to be added.

DAO layer Code: TestDAO

@Insert("insert into tablename(handler,title) " +
        "values(#{handler},#{title})")
@Options(useGeneratedKeys = true, keyProperty = "id")//添加该行,id值将自动添加到Measure
void insert(Measure measure);

Service-level code

testDAO.insert(measure);
long id = measure.getId();//取得id为自增长的值

 

Published 36 original articles · won praise 19 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_27182767/article/details/91468724