今天我发现同样的http请求到后端API服务器,有时它可以获取文章,有时它不能获取文章,这是我的代码:
Article article = articleMapper.selectByPrimaryKey(id);
这是使用MyBatis Generator自动生成的代码:
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
from article
where id = #{id,jdbcType=BIGINT}
</select>
相同的HTTP请求,具有相同的文章ID。我不知道哪里出了问题。我的PostgreSQL版本是13。这是我的自动生成xml配置:
<table tableName="article"
enableCountByExample="true"
enableUpdateByExample="true"
enableDeleteByExample="true"
enableSelectByExample="true"
selectByExampleQueryId="true">
<generatedKey column="ID" sqlStatement="JDBC" identity="true" />
</table>
有没有线索能查出代码的错误我是一个新手关于PostgreSQL作为后端数据库。
- 您要查询的文章是否存在?我相信ID是存在的。
- 是否会同时进行修改?不,不可能。我再也不会编辑写进数据库后的文章。没有交易,文章是旧文章。
1条答案
按热度按时间2jcobegt1#
我在使用
selectByPrimaryKey(null)
查询记录后观察到了这一点。我在selectByPrimaryKey
之前添加了一个检查,以确保它不会获得空参数。其他selectByPrimary(id)
都可以。