Spring ibatis return primary key after insert ibatis

북마크 추가

1. query xml

 

<insert id="insertSome" parameterClass="vo">

--query--

<selectKey keyProperty="seq(auto_increment column name)" resultClass="int">

SELECT LAST_INSERT_ID()

</selectKey>

</insert>

 

 

2. controller, service, service implement , dao -> void

 

 

2-1     controller

Vo vo = new VO();

vo.setSome("some value");

someservice.insertsome(vo);

2-2     service

          void someservice(Vo vo) throws Exception;

 

2-3     service imple

@Override

void someservice(Vo vo) throws Exception{

    someDAO.insertSome(vo);

}

 

2-4   dao

        public void inserSome(Vo vo) throws Exception{

            insert("id",vo);

        }

 

3. result

 

controller

 

Vo vo = new VO();

vo.setSome("some value");

someservice.insertsome(vo);  -> execute query

 

System.out.println(vo.getSeq());   -> returned key value

 

 

 

 

 

AD
통관알리미
2016-03-17 14:14
SHARE