mybatis 返回复合类型

标签: mybatis 复合引用
15人阅读 评论(0) 收藏 举报
分类:

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>





查看评论

struts2-OGNL和类型转换(structs 自动数据表单获取)

OGNL和类型转换 前面已经做了简单的介绍,将用户提交的内容映射成动作的属性,将属性内容通过标签显示在JSP页面中。这些过程是通过OGNL(Object-Graph Navigation L...
  • u011001084
  • u011001084
  • 2015-12-17 19:16:29
  • 457

JS复合类型

复合类型有函数,数组,类 一、函数 function 函数名([参数1],[参数2]){ //函数体 //返回值 ...
  • qq_24082497
  • qq_24082497
  • 2016-06-19 13:41:29
  • 1403

复合类型(一):引用

C++有好几种复合类型,这里介绍一下其中最重要的两种:引用和指针。 首先我们要知道,在C++中,一条声明语句是由一个基本数据类型和紧随其后的一个声明符列表组成。其中每个声明符命名了一个变量并指定该变...
  • troll__zhao
  • troll__zhao
  • 2016-01-11 13:35:57
  • 360

pgsql复合类型

PostgreSQL 8.1 中文文档 Prev Fast Backward Chapter 8. 数据类型 Fast Forward Next 8.11....
  • cdnight
  • cdnight
  • 2014-06-05 15:32:41
  • 1059

Mybatis使用注解版传递两个参数时如果保证传参数正确

两个方法:        1 使用User封装起来,可以自动的查询 @Select("select * from wj_user where name=#{name}#{password}") ...
  • jintianhen1
  • jintianhen1
  • 2013-07-09 13:43:07
  • 1599

c++ 中复合类型之-引用

周末无事,翻开自己尘封已久的C++,复习下~~~定义引用是为对象起了另外一个名字,引用类型(引用)另外一种类型。 引用并非对象,相反的,它只是为一个已经存在的对象所起的另外一个名字。报错原因 ...
  • u013266600
  • u013266600
  • 2017-02-12 14:22:58
  • 266

54.Scala中复合类型实战详解

A extends B with C with D A必须同时是B、C、D的类型。比如某个类既具有某种功能,又能序列化 eg:可以规定List或者Array里的元素, 比如必须实现序列化接口又必须...
  • KongMingJue
  • KongMingJue
  • 2017-09-29 18:38:28
  • 78

postgresql 复合数据类型的使用方法

postgresq 数据库的数据类型分为4种:基本数据类型、复合数据类型、域以及伪类型 基本类型:数据库内置数据类型,例如integer、char、varchar等 复合数据类型:需要用户自定义,所谓...
  • u013992330
  • u013992330
  • 2017-11-28 11:04:30
  • 136

mybatis 返回基本类型

接口mapper 类  public Long getUserIdByOpenId(String openid); mapper.xml文件       select id...
  • weixin_38570967
  • weixin_38570967
  • 2017-04-28 16:30:18
  • 477

Mybatis3 返回布尔值

在Mybatis中,有时候需要返回布尔值 ,来确定某个记录行是否存在。 例如:     说明: Mybatis是根据查询到的记录数进行转换的(1=true,0=f...
  • u014263805
  • u014263805
  • 2014-10-28 11:53:20
  • 3003
    个人资料
    持之以恒
    等级:
    访问量: 7604
    积分: 610
    排名: 8万+