mybatis 返回复合类型

entity

package com.imooc.myo2o.entity;

import java.util.Date;
import java.util.List;

public class Shop {

	private Long shopId;
	private Long ownerId;
	private Long shopCategoryId;
	private String shopName;
	private String shopDesc;
	private String shopAddr;
	private String phone;
	private String shopImg;
	private Double longitude;
	private Double latitude;
	private Integer priority;
	private Date createTime;
	private Date lastEditTime;
	private Integer enableStatus;
	private String advice;

	private List<ShopAuthMap> staffList;
	private Area area;
	private ShopCategory shopCategory;
	private ShopCategory parentCategory;

	public Long getShopId() {
		return shopId;
	}

	public void setShopId(Long shopId) {
		this.shopId = shopId;
	}

	public Long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(Long ownerId) {
		this.ownerId = ownerId;
	}

	public Long getShopCategoryId() {
		return shopCategoryId;
	}

	public void setShopCategoryId(Long shopCategoryId) {
		this.shopCategoryId = shopCategoryId;
	}

	public String getShopName() {
		return shopName;
	}

	public void setShopName(String shopName) {
		this.shopName = shopName;
	}

	public String getShopDesc() {
		return shopDesc;
	}

	public void setShopDesc(String shopDesc) {
		this.shopDesc = shopDesc;
	}

	public String getShopAddr() {
		return shopAddr;
	}

	public void setShopAddr(String shopAddr) {
		this.shopAddr = shopAddr;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getShopImg() {
		return shopImg;
	}

	public void setShopImg(String shopImg) {
		this.shopImg = shopImg;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastEditTime() {
		return lastEditTime;
	}

	public void setLastEditTime(Date lastEditTime) {
		this.lastEditTime = lastEditTime;
	}

	public Integer getEnableStatus() {
		return enableStatus;
	}

	public void setEnableStatus(Integer enableStatus) {
		this.enableStatus = enableStatus;
	}

	public List<ShopAuthMap> getStaffList() {
		return staffList;
	}

	public void setStaffList(List<ShopAuthMap> staffList) {
		this.staffList = staffList;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public ShopCategory getShopCategory() {
		return shopCategory;
	}

	public void setShopCategory(ShopCategory shopCategory) {
		this.shopCategory = shopCategory;
	}

	public String getAdvice() {
		return advice;
	}

	public void setAdvice(String advice) {
		this.advice = advice;
	}

	public String toString() {
		return "[shopId=" + shopId + ", shopName=" + shopName + "]";
	}

	public ShopCategory getParentCategory() {
		return parentCategory;
	}

	public void setParentCategory(ShopCategory parentCategory) {
		this.parentCategory = parentCategory;
	}

}

mapper

<mapper namespace="com.imooc.myo2o.dao.ShopDao">
	<resultMap id="shopMap" type="com.imooc.myo2o.entity.Shop">
		<id column="shop_id" property="shopId" />
		<result column="owner_id" property="ownerId" />
		<result column="shop_category_id" property="shopCategoryId" />
		<result column="shop_name" property="shopName" />
		<result column="shop_desc" property="shopDesc" />
		<result column="shop_addr" property="shopAddr" />
		<result column="phone" property="phone" />
		<result column="shop_img" property="shopImg" />
		<result column="longitude" property="longitude" />
		<result column="latitude" property="latitude" />
		<result column="priority" property="priority" />
		<result column="create_time" property="createTime" />
		<result column="last_edit_time" property="lastEditTime" />
		<result column="enable_status" property="enableStatus" />
		<result column="advice" property="advice" />
		<association property="area" column="area_id"
			javaType="com.imooc.myo2o.entity.Area">
			<id column="area_id" property="areaId" />
			<result column="area_name" property="areaName" />
			<result column="area_desc" property="areaDesc" />
			<result column="priority" property="priority" />
			<result column="create_time" property="createTime" />
			<result column="last_edit_time" property="lastEditTime" />
		</association>
		<association property="shopCategory" column="shop_category_id"
			javaType="com.imooc.myo2o.entity.ShopCategory">
			<id column="shop_category_id" property="shopCategoryId" />
			<result column="shop_category_name" property="shopCategoryName" />
			<result column="shop_category_desc" property="shopCategoryDesc" />
			<result column="shop_category_img" property="shopCategoryImg" />
			<result column="priority" property="priority" />
			<result column="create_time" property="createTime" />
			<result column="last_edit_time" property="lastEditTime" />
		</association>
		<association property="parentCategory" column="parent_category_id"
			javaType="com.imooc.myo2o.entity.ShopCategory">
			<id column="parent_category_id" property="shopCategoryId" />
			<result column="shop_category_name" property="shopCategoryName" />
			<result column="shop_category_desc" property="shopCategoryDesc" />
			<result column="shop_category_img" property="shopCategoryImg" />
			<result column="priority" property="priority" />
			<result column="create_time" property="createTime" />
			<result column="last_edit_time" property="lastEditTime" />
		</association>
		<collection property="staffList" column="shop_id"
			ofType="com.imooc.myo2o.entity.ShopAuthMap">
			<id column="shop_auth_id" property="shopAuthId" />
			<result column="employee_id" property="employeeId" />
			<result column="shop_id" property="shopId" />
			<result column="name" property="name" />
			<result column="title" property="title" />
			<result column="title_flag" property="titleFlag" />
			<result column="create_time" property="createTime" />
			<result column="last_edit_time" property="lastEditTime" />
			<result column="enable_status" property="enableStatus" />
		</collection>
	</resultMap>
	<select id="queryShopList" resultMap="shopMap">
		SELECT
		shop_id,
		owner_id,
		area_id,
		shop_category_id,
		parent_category_id,
		shop_name,
		shop_desc,
		shop_addr,
		phone,
		shop_img,
		longitude,
		latitude,
		priority,
		create_time,
		last_edit_time,
		enable_status,
		advice
		FROM
		tb_shop
		<where>
			<if test="shopCondition.shopId!=null">
				and shop_id = #{shopCondition.shopId}
			</if>
			<if
				test="shopCondition.shopCategory!=null
				 and shopCondition.shopCategory.shopCategoryId!=null">
				and shop_category_id =
				#{shopCondition.shopCategory.shopCategoryId}
			</if>
			<if
				test="shopCondition.parentCategory!=null
				 and shopCondition.parentCategory.shopCategoryId!=null">
				and parent_category_id =
				#{shopCondition.parentCategory.shopCategoryId}
			</if>
			<if
				test="shopCondition.area!=null
				 and shopCondition.area.areaId!=null">
				and area_id =
				#{shopCondition.area.areaId}
			</if>
			<!-- 写like语句的时候 一般都会写成 like '% %' 在mybatis里面写就是应该是 like '%${name} %' 而不是 
				'%#{name} %' ${name} 是不带单引号的,而#{name} 是带单引号的 -->
			<if test="shopCondition.shopName!=null">
				and shop_name like '%${shopCondition.shopName}%'
			</if>
			<if test="shopCondition.enableStatus!=null">
				and enable_status = #{shopCondition.enableStatus}
			</if>
		</where>
		ORDER BY
		priority DESC
		LIMIT #{rowIndex},#{pageSize};
	</select>





猜你喜欢

转载自blog.csdn.net/qq_24192465/article/details/79963907