java - MyBatis 偶尔使用 selectByPrimaryKey 时无法获取记录
问题描述
今天发现后端api服务器同样的http请求,有时候可以获取文章,有时候不能获取文章,这是我的代码:
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 的文章是否存在?是的,我确定该 ID 存在。
可以同时进行修改吗?不,这是不可能的。写入数据库后,我永远不会编辑文章。无交易,文章为旧文章。
解决方案
推荐阅读
- html - 如何使用 HTML 和 CSS 在图像上添加文本覆盖
- next.js - Next.js 图像组件不显示 Cloudinary 图像
- javascript - 点击确认 HTML 不适用于 Sweetalert2,但它适用于本机浏览器确认
- python - 如何编写函数来检查集合是否连续?
- java - 如何从 Firebase 获取特定用户信息并在 RecyclerView 中显示?
- python - 如何将字符串转换为日期?
- python - 在 pip 和 pip3 中安装 psycopg2 时出现安装错误
- reactjs - 可以在构造函数中获取值,但是在render函数中输出TypeError: Cannot read property 'xxx' of undefined
- haskell - 在为守卫执行模块表达式时,在我的 Haskell 代码中出现三个“变量不在范围内”错误
- c# - 为什么我不能用T?作为 C# 中的泛型参数