发表于: 2020-02-12 23:47:11
1 1259
今天完成的事情:
解决了关于1对多表查询的问题
问题:
查询two表时 我还需要查询one表的名字
我用join方法
数据库two表已经添加了one表的ID 用作逻辑外键
查询语句没问题,数据库内查询正常
可是显示总是出错误
one的name就是无法显示
因为涉及到下划线对应问题 我添加了resultMap
<resultMap id="twoWorkMap" type="pojo.twowork" >
<id property="twoId" column="two_id" jdbcType="BIGINT"/>
<result property="twoworkName" column="twowork_name" jdbcType="VARCHAR" />
<result property="state" column="state" jdbcType="TINYINT"/>
<result property="createAt" column="create_at" jdbcType="BIGINT"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="updateAt" column="update_at" jdbcType="BIGINT"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="oneId" column="one_id" jdbcType="BIGINT"/>
<association property="onework" javaType="pojo.onework">
<id property="oneId" column="one_id" javaType="BIGINT"/>
<result property="oneworkName" column="onework_name" javaType="VARCHAR"/>
</association>
</resultMap>
之前的resultMap一直是这个 也没改过
后面想了半天,我数据库的表,和我代码里pojo的表 可以根据需求来
没必要字段非得一致啊
然后
修改two的 pojo表
添加了oneworkName
修改了resultMap
postman 终于成功了
成功了
这个困扰我挺长时间的
一直觉得sql语句 resultMap有问题
其实并不是 是代码的pojo可以变动,没必要和数据库字段一致
明天计划的事情:
推进任务
评论