一、问题
报错:必须为元素类型 "insert" 声明属性 "resultMap"的解决。
代码:
<resultMap id="result" type="com.example.demo.bean.Node">
<result property="nodeID" column="nodeID" />
<result property="nodeType" column="nodeType" />
<result property="relation" column="relation" />
</resultMap>
<insert id="addNode" parameterType="com.example.demo.bean.Node"
keyProperty="nodeID" useGeneratedKeys="true" resultMap="java.lang.Integer">
INSERT INTO tb_nodetree
(
nodeId,nodeType,relation
)
VALUES (
#{nodeId},#{nodeType},#{relation}
)
</insert>
2.原因
因为接口中想返回一个整数来查看是否添加进数据库,所以在insert方法中加了resultMap属性,结果就出错了。
3.解决
把insert中的resultMap删掉就行了,仍然会返回整数(数据库受影响的行数)。