[MyBatis] MyBatis Generator code generator problem

In MyBatis+SqlServer, the primary key field should not be generated in the insert statement

<table tableName="Customer">
    <columnOverride column="RowId" isGeneratedAlways="true"></columnOverride>
</table>

In MyBatis+SqlServer, the primary key value is returned after insertion

The original way of writing the code generator:

<table tableName="Customer">
    <generatedKey column="RowId" sqlStatement="JDBC" identity="true"/>
</table>

Generate Insert statement in Mapper:

<insert id="insert" parameterType="com.LTSolution.ShopApp.Model.Customer">
  <selectKey keyProperty="rowid" order="AFTER" resultType="java.lang.Integer">
    SELECT SCOPE_IDENTITY()
  </selectKey>
  insert into Company (...)
  values (...)
</insert>

According to the relevant books and materials, this writing method should be feasible, but it is not practical.

After testing, the primary key is returned after successful insertion using the following writing method

Code generator writing:

<table tableName="Customer">
    <generatedKey column="RowId" sqlStatement="JDBC" identity="true"/>
</table>

Generate Insert statement in Mapper:

<insert id="insert" keyColumn="RowId" keyProperty="rowid" parameterType="com.LTSolution.ShopApp.Model.Customer" useGeneratedKeys="true">
  insert into Customer (...)
  values (...)
</insert>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325628917&siteId=291194637
Recommended