mybatis: 一对一关联查询

  • 注意
  • 代码部分
    • 实体类(extity)
    • mybatis
    • mapper
    • service
    • controller

注意

.xml文件编写中有报错,The content of element type "resultMap" must match ...。参考了这篇博客的解答https://blog.csdn.net/chenxing1990/article/details/79649958

<resultMap>标签中要按照

<id>
<result>
<association>
<collection>

的顺序来排列

代码部分

实体类(extity)

实体类Product_orderextends扩展类Product_orderExtend

public class Product_order extends Product_orderExtend {private Long orderId;private Integer sellerId;private Long goodId;private Integer purchaserId;private Integer addressId;private BigDecimal price;private Integer shippingMethod;private Integer pickupMethod;private Boolean usePoint;private Integer orderState;private Integer gainPoint;private Date createDate;
}

在扩展类Product_orderExtend

public class Product_orderExtend {private Good good;private User seller;private User purchaser;private Address address;
}

mybatis

mybatis/mapper/extend下的xml文件中写扩展mapper

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.group5.springboot.crud.mapper.Product_orderMapper"><resultMap type="com.group5.springboot.crud.common.domain.Product_order" id="Product_orderAssociationResultMap"><id property="orderId" column="order_id"/><result property="price" column="price"/><result property="shippingMethod" column="shipping_method"/><result property="pickupMethod" column="pickup_method"/><result property="usePoint" column="use_point"/><result property="orderState" column="order_state"/><result property="gainPoint" column="gain_point"/><result property="createDate" column="create_date"/><association property="good" javaType="com.group5.springboot.crud.common.domain.Good"><id column="good_id" jdbcType="BIGINT" property="goodId" /><result column="image_path" jdbcType="VARCHAR" property="imagePath" /><result column="start_time" jdbcType="TIMESTAMP" property="startTime" /><result column="end_time" jdbcType="TIMESTAMP" property="endTime" /><result column="quantity" jdbcType="INTEGER" property="quantity" /><result column="origin_place" jdbcType="VARCHAR" property="originPlace" /><result column="type" jdbcType="INTEGER" property="type" /><result column="city" jdbcType="VARCHAR" property="city" /><result column="brand" jdbcType="VARCHAR" property="brand" /><result column="content" jdbcType="VARCHAR" property="content" /><result column="good_name" jdbcType="VARCHAR" property="goodName" /><result column="price" jdbcType="DECIMAL" property="price" /><result column="status" jdbcType="INTEGER" property="status" /><result column="current_price" jdbcType="DECIMAL" property="currentPrice" /></association><association property="seller" javaType="com.group5.springboot.crud.common.domain.User"><id column="id" jdbcType="INTEGER" property="id" /><result column="username" jdbcType="VARCHAR" property="username" /><result column="phone_num" jdbcType="VARCHAR" property="phoneNum" /><result column="email" jdbcType="VARCHAR" property="email" /><result column="password" jdbcType="VARCHAR" property="password" /><result column="rewardpoint" jdbcType="INTEGER" property="rewardpoint" /><result column="profile" jdbcType="VARCHAR" property="profile" /></association><association property="purchaser" javaType="com.group5.springboot.crud.common.domain.User"><id column="id" jdbcType="INTEGER" property="id" /><result column="username" jdbcType="VARCHAR" property="username" /><result column="phone_num" jdbcType="VARCHAR" property="phoneNum" /><result column="email" jdbcType="VARCHAR" property="email" /><result column="password" jdbcType="VARCHAR" property="password" /><result column="rewardpoint" jdbcType="INTEGER" property="rewardpoint" /><result column="profile" jdbcType="VARCHAR" property="profile" /></association><association property="address" javaType="com.group5.springboot.crud.common.domain.Address"><id column="address_id" jdbcType="INTEGER" property="addressId" /><result column="receiver" jdbcType="VARCHAR" property="receiver" /><result column="contact_number" jdbcType="VARCHAR" property="contactNumber" /><result column="user_id" jdbcType="INTEGER" property="userId" /><result column="adresss" jdbcType="VARCHAR" property="adresss" /><result column="isdefault" jdbcType="INTEGER" property="isdefault" /></association></resultMap><select id="selectAssociationPurchaser" parameterType="int" resultMap="Product_orderAssociationResultMap">select * from product_order p, user u1, user u2, good g, address awhere p.purchaser_id=#{purchaserId} and a.address_id=p.address_id and u1.id = p.seller_id and u2.id = p.purchaser_id and g.good_id=p.good_id</select><select id="selectAssociationSeller" parameterType="int" resultMap="Product_orderAssociationResultMap">select * from product_order p, user u1, user u2, good g, address awhere p.seller_id=#{sellerId} and a.address_id=p.address_id and u1.id = p.seller_id and u2.id = p.purchaser_id and g.good_id=p.good_id</select>
</mapper>

mapper

同理在mapper/extend中添加接口。

public interface Browsing_historyExtendMapper {List<Good> selectGoodsByUid(int user_id);List<Browsing_history> selectAssociationGood(int userId);
}

service

略。

controller

略。

【mybatis】一对一关联查询相关推荐

  1. mybatis一对一关联查询

    public class CardInfo implements java.io.Serializable{     private int id;     private String cardNu ...

  2. 企业级信息系统开发讲课笔记2.3 利用MyBatis实现关联查询

    文章目录 零.本节学习目标 一.查询需求 (一)针对三张表关联查询 (二)按班级编号查询班级信息 (三)查询全部班级信息 二.创建数据库表 (一)创建教师表 (二)创建班级表 (三)创建学生表 三.创 ...

  3. Spring整合Mybatis之关联查询示例

    Spring整合Mybatis之关联查询示例 目录结构: Dept表: employee表: pojo包 Dept.java(实体类): package com.xmm.springboot_lab. ...

  4. mybatis collection 关联查询多个参数

    mybatis collection 关联查询多个参数 column="{evtId=id,businessType=businessType1}" 描述:evtId是关联查询的参 ...

  5. 【Hadoop基础教程】7、Hadoop之一对一关联查询

    我们都知道一个产品唯一对应一个单价,本案例将通过两种类型输入文件:product类(产品)和price类(价格)进行一对一的关联查询,得到产品名(例如:手表)与产品价格(例如:$100)的关联信息. ...

  6. 一对一关联查询注解@OneToOne的实例详解(一)

    转载自: https://www.cnblogs.com/boywwj/p/8092915.html 一对一关联查询注解@OneToOne的实例详解 表的关联查询比较复杂,应用的场景很多,本文根据自己 ...

  7. Java基础-SSM之mybatis一对一关联

    Java基础-SSM之mybatis一对一关联 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.准备测试环境(创建数据库表)  1>.创建husbands和wifes表并建 ...

  8. MyBatis框架学习 DAY_03:如何解决无法封装问题 / 一对一关联查询 / 一对多关联查询

    1. 通过查询时自定义别名的方式解决名称不一致而导致的无法封装数据的问题 假设,向用户组数据表(t_group)表中插入一些测试数据: INSERT INTO t_group (name) VALUE ...

  9. 【MyBatis】关联查询

    关联查询: 一对一: a.业务扩展类 核心:用resultType指定类的属性 包含 多表查询的所有字段 b.resultMap i.通过 属性成员 将2个类建立起联系 2. <resultMa ...

最新文章

  1. Delphi Access violations 问题的解决之道
  2. python篮球-基于Python/Java的人工智能篮球训练系统的制作方法
  3. 其他信息: 线程间操作无效: 从不是创建控件“控件名”的线程访问它。
  4. 从中台、数仓与元数据不为人知的3个角度,看数据管理的生与死
  5. python怎么找一个矩阵_Python(NumPy,SciPy),找到矩阵的零空间
  6. MySql常用函数大全讲解
  7. Unity3D 最实用的插件推荐
  8. 核磁共振波谱仪基础知识及常见问题
  9. 【软件版本】软件版本GA、RC、Beta、Alpha等的详细解释和含义
  10. 去哪下载python项目_Python 项目实践二(下载数据)第三篇
  11. Ubuntu神奇地变成了只读文件系统的错误--修复方法
  12. MySQL大数据量查询方案
  13. 中国互联网公司和他们的口号
  14. DM8168 DMM/TILER简介
  15. 同时查询京东多个快递物流,并分析中转延误
  16. 从细胞发现到DNA分子结构的发现,人类经历了三百年
  17. 什么是拦截器?什么是过滤器?
  18. 【ML】单分量Metropolis-Hastings算法与Gibbs抽样
  19. android 群英传笔记,Android 群英传读书笔记1
  20. VBA从多张工作簿(workbooks)中多张工作表(worksheets)同一位置提取数据

热门文章

  1. LCDM--商品潜在互补性发现模型
  2. android实现计算器功能吗,安卓实现一个计算器的功能
  3. 洛谷P1102 A-B
  4. 【机器学习-西瓜书】八、Bagging;随机森林(RF)
  5. Anaconda prompt下常用命令
  6. 游戏match(【CCF】NOI Online能力测试2 提高组第三题 )
  7. 1007 素数对猜想(C语言)
  8. 《南溪的目标检测学习笔记》——训练PyTorch模型遇到显存不足的情况怎么办(“OOM: CUDA out of memory“)
  9. 目标检测————主干网络是否应该选用DenseNet(提问)
  10. GO语言中的几个关键思想