Mybatis 手动插入PK

问题描述

我正在尝试使用指定的 PK 将数据单独插入到表中。手动分配PK。

XML 文件

<insert id = "insertStd" parameterType = "com.org.springboot.dao.StudentEntity" useGeneratedKeys = "false" keyProperty = "insertStd.id",keyColumn = "id">
      INSERT INTO STUDENT (ID,NAME,BRANCH,PERCENTAGE,PHONE,EMAIL ) 
      VALUES (ID=#{insertStd.id},NAME=#{insertStd.name},BRANCH=#{insertStd.branch},PERCENTAGE=#{insertStd.percentage},PHONE=#{insertStd.phone},EMAIL =#{insertStd.email});

   </insert>

服务调用方式

public boolean saveStudent(Student student){
    LOGGER.info("Student object save");
    int savedId= studentMapper.insertStd(student);
}

日志文件

org.springframework.jdbc.badsqlgrammarexception
### Error updating database Causes: cause org.postgresql.util.psqlexception error column id does not exist
HINT: There is a column named "id" in the table "student" but it can't be referenced from this part of the query. 
Position 200
### Error may exist in file [c:\.....\StudentMapper.xml]
### Error may involve in com.org.springboot.dao.StudentMapper.insertStd-InLine
### The error occurred while setting parameters
### SQL INSERT INTO STUDENT (ID,EMAIL ) 
  VALUES (ID=?,NAME=?,BRANCH=?,PERCENTAGE=?,PHONE=?,EMAIL=?);
### cause org.postgresql.util.psqlexception ERROR column "id" doesn't exist. //It did worked with JPA id assigned manually.
### There is a column named "ID" in the table "STUDENT",Bbut it cannot be referenced from the part of the query. 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)