错误代码
<mapper namespace="com.axr.mypro.mapper.PastebinMapper"><insert id="add" useGeneratedKeys="true" keyProperty="id">insert into pastebin(language, content)values (#{language}, #{content})</insert>
</mapper>
Integer add(Pastebin pastebin);
Integer id = pastebinMapper.add(pastebin).getId();System.out.println(id);
return Result.success(id);
查看控制台,输出内容为1
正确代码
<mapper namespace="com.axr.mypro.mapper.PastebinMapper"><insert id="add" useGeneratedKeys="true" keyProperty="id">insert into pastebin(language, content)values (#{language}, #{content})</insert>
</mapper>
void add(Pastebin pastebin);
pastebinMapper.add(pastebin);
Integer id = pastebin.getId();
return Result.success(id);return Result.success(id);
希望可以帮助到你