mybatis返回复合类型参数

川长思鸟来 2021-09-28 10:50 513阅读 0赞

返回的数据模型

  1. package com.imooc.myo2o.entity;
  2. import java.util.Date;
  3. import java.util.List;
  4. public class Shop {
  5. private Long shopId;
  6. private Long ownerId;
  7. private Long shopCategoryId;
  8. private String shopName;
  9. private String shopDesc;
  10. private String shopAddr;
  11. private String phone;
  12. private String shopImg;
  13. private Double longitude;
  14. private Double latitude;
  15. private Integer priority;
  16. private Date createTime;
  17. private Date lastEditTime;
  18. private Integer enableStatus;
  19. private String advice;
  20. private List<ShopAuthMap> staffList;
  21. private Area area;
  22. private ShopCategory shopCategory;
  23. private ShopCategory parentCategory;
  24. public Long getShopId() {
  25. return shopId;
  26. }
  27. public void setShopId(Long shopId) {
  28. this.shopId = shopId;
  29. }
  30. public Long getOwnerId() {
  31. return ownerId;
  32. }
  33. public void setOwnerId(Long ownerId) {
  34. this.ownerId = ownerId;
  35. }
  36. public Long getShopCategoryId() {
  37. return shopCategoryId;
  38. }
  39. public void setShopCategoryId(Long shopCategoryId) {
  40. this.shopCategoryId = shopCategoryId;
  41. }
  42. public String getShopName() {
  43. return shopName;
  44. }
  45. public void setShopName(String shopName) {
  46. this.shopName = shopName;
  47. }
  48. public String getShopDesc() {
  49. return shopDesc;
  50. }
  51. public void setShopDesc(String shopDesc) {
  52. this.shopDesc = shopDesc;
  53. }
  54. public String getShopAddr() {
  55. return shopAddr;
  56. }
  57. public void setShopAddr(String shopAddr) {
  58. this.shopAddr = shopAddr;
  59. }
  60. public String getPhone() {
  61. return phone;
  62. }
  63. public void setPhone(String phone) {
  64. this.phone = phone;
  65. }
  66. public String getShopImg() {
  67. return shopImg;
  68. }
  69. public void setShopImg(String shopImg) {
  70. this.shopImg = shopImg;
  71. }
  72. public Double getLongitude() {
  73. return longitude;
  74. }
  75. public void setLongitude(Double longitude) {
  76. this.longitude = longitude;
  77. }
  78. public Double getLatitude() {
  79. return latitude;
  80. }
  81. public void setLatitude(Double latitude) {
  82. this.latitude = latitude;
  83. }
  84. public Integer getPriority() {
  85. return priority;
  86. }
  87. public void setPriority(Integer priority) {
  88. this.priority = priority;
  89. }
  90. public Date getCreateTime() {
  91. return createTime;
  92. }
  93. public void setCreateTime(Date createTime) {
  94. this.createTime = createTime;
  95. }
  96. public Date getLastEditTime() {
  97. return lastEditTime;
  98. }
  99. public void setLastEditTime(Date lastEditTime) {
  100. this.lastEditTime = lastEditTime;
  101. }
  102. public Integer getEnableStatus() {
  103. return enableStatus;
  104. }
  105. public void setEnableStatus(Integer enableStatus) {
  106. this.enableStatus = enableStatus;
  107. }
  108. public List<ShopAuthMap> getStaffList() {
  109. return staffList;
  110. }
  111. public void setStaffList(List<ShopAuthMap> staffList) {
  112. this.staffList = staffList;
  113. }
  114. public Area getArea() {
  115. return area;
  116. }
  117. public void setArea(Area area) {
  118. this.area = area;
  119. }
  120. public ShopCategory getShopCategory() {
  121. return shopCategory;
  122. }
  123. public void setShopCategory(ShopCategory shopCategory) {
  124. this.shopCategory = shopCategory;
  125. }
  126. public String getAdvice() {
  127. return advice;
  128. }
  129. public void setAdvice(String advice) {
  130. this.advice = advice;
  131. }
  132. public String toString() {
  133. return "[shopId=" + shopId + ", shopName=" + shopName + "]";
  134. }
  135. public ShopCategory getParentCategory() {
  136. return parentCategory;
  137. }
  138. public void setParentCategory(ShopCategory parentCategory) {
  139. this.parentCategory = parentCategory;
  140. }
  141. }

mapper

  1. <mapper namespace="com.imooc.myo2o.dao.ShopDao">
  2. <resultMap id="shopMap" type="com.imooc.myo2o.entity.Shop">
  3. <id column="shop_id" property="shopId" />
  4. <result column="owner_id" property="ownerId" />
  5. <result column="shop_category_id" property="shopCategoryId" />
  6. <result column="shop_name" property="shopName" />
  7. <result column="shop_desc" property="shopDesc" />
  8. <result column="shop_addr" property="shopAddr" />
  9. <result column="phone" property="phone" />
  10. <result column="shop_img" property="shopImg" />
  11. <result column="longitude" property="longitude" />
  12. <result column="latitude" property="latitude" />
  13. <result column="priority" property="priority" />
  14. <result column="create_time" property="createTime" />
  15. <result column="last_edit_time" property="lastEditTime" />
  16. <result column="enable_status" property="enableStatus" />
  17. <result column="advice" property="advice" />
  18. <association property="area" column="area_id"
  19. javaType="com.imooc.myo2o.entity.Area">
  20. <id column="area_id" property="areaId" />
  21. <result column="area_name" property="areaName" />
  22. <result column="area_desc" property="areaDesc" />
  23. <result column="priority" property="priority" />
  24. <result column="create_time" property="createTime" />
  25. <result column="last_edit_time" property="lastEditTime" />
  26. </association>
  27. <association property="shopCategory" column="shop_category_id"
  28. javaType="com.imooc.myo2o.entity.ShopCategory">
  29. <id column="shop_category_id" property="shopCategoryId" />
  30. <result column="shop_category_name" property="shopCategoryName" />
  31. <result column="shop_category_desc" property="shopCategoryDesc" />
  32. <result column="shop_category_img" property="shopCategoryImg" />
  33. <result column="priority" property="priority" />
  34. <result column="create_time" property="createTime" />
  35. <result column="last_edit_time" property="lastEditTime" />
  36. </association>
  37. <association property="parentCategory" column="parent_category_id"
  38. javaType="com.imooc.myo2o.entity.ShopCategory">
  39. <id column="parent_category_id" property="shopCategoryId" />
  40. <result column="shop_category_name" property="shopCategoryName" />
  41. <result column="shop_category_desc" property="shopCategoryDesc" />
  42. <result column="shop_category_img" property="shopCategoryImg" />
  43. <result column="priority" property="priority" />
  44. <result column="create_time" property="createTime" />
  45. <result column="last_edit_time" property="lastEditTime" />
  46. </association>
  47. <collection property="staffList" column="shop_id"
  48. ofType="com.imooc.myo2o.entity.ShopAuthMap">
  49. <id column="shop_auth_id" property="shopAuthId" />
  50. <result column="employee_id" property="employeeId" />
  51. <result column="shop_id" property="shopId" />
  52. <result column="name" property="name" />
  53. <result column="title" property="title" />
  54. <result column="title_flag" property="titleFlag" />
  55. <result column="create_time" property="createTime" />
  56. <result column="last_edit_time" property="lastEditTime" />
  57. <result column="enable_status" property="enableStatus" />
  58. </collection>
  59. </resultMap>
  60. <select id="queryShopList" resultMap="shopMap">
  61. SELECT
  62. shop_id,
  63. owner_id,
  64. area_id,
  65. shop_category_id,
  66. parent_category_id,
  67. shop_name,
  68. shop_desc,
  69. shop_addr,
  70. phone,
  71. shop_img,
  72. longitude,
  73. latitude,
  74. priority,
  75. create_time,
  76. last_edit_time,
  77. enable_status,
  78. advice
  79. FROM
  80. tb_shop
  81. <where>
  82. <if test="shopCondition.shopId!=null">
  83. and shop_id = #{shopCondition.shopId}
  84. </if>
  85. <if
  86. test="shopCondition.shopCategory!=null
  87. and shopCondition.shopCategory.shopCategoryId!=null">
  88. and shop_category_id =
  89. #{shopCondition.shopCategory.shopCategoryId}
  90. </if>
  91. <if
  92. test="shopCondition.parentCategory!=null
  93. and shopCondition.parentCategory.shopCategoryId!=null">
  94. and parent_category_id =
  95. #{shopCondition.parentCategory.shopCategoryId}
  96. </if>
  97. <if
  98. test="shopCondition.area!=null
  99. and shopCondition.area.areaId!=null">
  100. and area_id =
  101. #{shopCondition.area.areaId}
  102. </if>
  103. <!-- 写like语句的时候 一般都会写成 like '% %' 在mybatis里面写就是应该是 like '%${name} %' 而不是
  104. '%#{name} %' ${name} 是不带单引号的,而#{name} 是带单引号的 -->
  105. <if test="shopCondition.shopName!=null">
  106. and shop_name like '%${shopCondition.shopName}%'
  107. </if>
  108. <if test="shopCondition.enableStatus!=null">
  109. and enable_status = #{shopCondition.enableStatus}
  110. </if>
  111. </where>
  112. ORDER BY
  113. priority DESC
  114. LIMIT #{rowIndex},#{pageSize};
  115. </select>

原文转自:mybatis 返回复合类型

发表评论

表情:
评论列表 (有 0 条评论,513人围观)

还没有评论,来说两句吧...

相关阅读

    相关 go 复合类型

    1、pointer:指针,默认值:nil 指针是一个代表着某个内存地址的值。这个内存地址往往是在内存中存储的另一个变量的值的起始位置,go语言对指针的支持介于java语言

    相关 【c++】复合类型

    什么是复合类型? 我在之前说过,具体的定义我说不出来,不过可以怎么理解,复合类型比基本类型高级一些,它可以存储别的变量。你要知道通过基本的数据类型的是无法完成什么大事情的。

    相关 JS复合类型

    1:JS复合类型 符合类型是由多个基本数据类型(也可以包括复合类型)组成的数据体。JS中大致可以分为3种符合类型: Object:对象。[详情点此][Link 1] Ar