6-1 店铺信息编辑之Dao层的实现

1、编写Dao接口

2、编写Dao的实现

做查询

首先要编写resultMap(输出结果),<id>是主键,<result>是数据库字段和属性的对应,<association>是外键里的属性

在<select>标签中resultMap 引用的就是上面的id

<mapper namespace="com.imooc.o2o.dao.ShopDao">
    <resultMap type="com.imooc.o2o.entity.Shop" id="shopMap">
    	<id column="shop_id" property="shopId"/>
    	<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="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.o2o.entity.Area">
    		<id column="area_id" property="areaId"/>
    		<result column="area_name" property="areaName"/>
    	</association>
    	<association property="shopCategory" column="shop_category_id" javaType="com.imooc.o2o.entity.ShopCategory">
    		<id column="shop_category_id" property="shopCategoryId"/>
    		<result column="shop_category_name" property="shopCategoryName"/>
    	</association>
    	<association property="owner" column="user_id" javaType="com.imooc.o2o.entity.PersonInfo">
    		<id column="user_id" property="userId"/>
    		<result column="name" property="name"/>
    	</association>
    </resultMap>
   <select id="queryByShopId" resultMap="shopMap" parameterType="Long">
   	SELECT 
   		s.shop_id,
   		s.shop_name,
   		s.shop_desc,
   		s.shop_addr,
   		s.phone,
		s.shop_img,
		s.priority,
		s.create_time,
		s.last_edit_time,
		s.enable_status,
		s.advice,
		a.area_id,
		a.area_name,
		sc.shop_category_id,
		sc.shop_category_name
		FROM
		tb_shop s,
		tb_area a,
		tb_shop_category sc
		WHERE
		s.area_id=a.area_id
		AND
		s.shop_category_id=sc.shop_category_id
		AND
		s.shop_id=#{shopId}
   </select>

3、测试

猜你喜欢

转载自blog.csdn.net/weixin_40703303/article/details/89387727
6-1