首页 > 解决方案 > 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 作为后端数据库的新手。

标签: javamybatis

解决方案


推荐阅读