JSON在线解析

提问人:SOJSON用户 提问日期:2016-05-26 11:24 热度:264
问题标签 Mybatis SQL
<insert id="insert" parameterType="com.bj.common.model.UPermission" >
  insert into u_permission (id, url, name)
  values (#{id,jdbcType=BIGINT}, #{url,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR})
</insert>

数据ID是自增的。

然后要插入对象后,返回对象的ID。

1条回答 我来回答
soゝso| 2016-05-26 11:27

如果ID是自增的。那么在sqlMapper上加入:

 useGeneratedKeys="true" keyProperty="id" 

即可解决,当你插入后,你看实体,发现实体的Id属性是有值。

  <insert id="insert"  useGeneratedKeys="true" keyProperty="id"  parameterType="com.bj.common.model.UPermission" >
    insert into u_permission (id, url, name)
    values (#{id,jdbcType=BIGINT}, #{url,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR})
  </insert>