VO层:V指的是View,这不是指的前端的页面意思,而是指的将后台的数据(可以简单理解成SQL语句查询的来的数据),直接查询出的数据直接传给前端,前端需要对数据进行筛选处理才会展示到页面,而VO对象,可以理解成后台重新将查询出的数据进行一个简单的封装,目的就是方便提供给前端调用,所以取名叫做VO。
BO层是business Object 业务对象
我自己简单的理解就是前台传递给后台的数据,数据在后台的数据库表中不是一个个字段相对应。所以需要重新封装一个对象接受前台传递过来的数据。 ?
mybatis的resultMap的代码书写
categoryVO中包含了subCategoryList的列表
<resultMap id="categoryVO" type="com.imooc.pojo.vo.CategoryVO">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="type" property="type" />
<result column="fatherId" property="fatherId" />
<collection property="subCategoryList" ofType="com.imooc.pojo.vo.SubCategoryVO">
<id column="subId" property="subId" />
<result column="subName" property="subName" />
<result column="subType" property="subType" />
<result column="subFatherId" property="subFatherId" />
</collection>
</resultMap>
<select id="getSubCatList" resultMap="categoryVO" parameterType="integer">
<?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.imooc.mapper.ItemsCustomMapper" >
<select id="queryItemComments" parameterType="Map" resultType="com.imooc.pojo.vo.ItemCommentVO">
select
ic.comment_level commentLevel,
ic.content content,
ic.sepc_name sepcName,
ic.created_time createdTime,
u.face userFace,
u.nickname nickname
from items_comments ic
LEFT JOIN users u
ON ic.user_id = u.id
where ic.item_id = #{paramsMap.itemId}
<if test="paramsMap.level!=null and paramsMap.level!=''">
AND ic.comment_level = #{paramsMap.level}
</if>
</select>
<select id="searchItems" parameterType="map" resultType="com.imooc.pojo.vo.SearchItemsVO">
SELECT
i.id AS itemId,
i.item_name AS itemName,
i.sell_counts AS sellCounts,
ii.url AS imgUrl,
tempSpec.price_discount as price
FROM
items i
LEFT JOIN items_img ii ON i.id = ii.item_id
LEFT JOIN ( SELECT item_id, MIN( price_discount ) price_discount FROM items_spec GROUP BY item_id ) AS tempSpec ON i.id = tempSpec.item_id
WHERE
ii.is_main = 1
<if test="paramsMap.keywords!=null and paramsMap.keywords!=''">
AND i.item_name like '%${paramsMap.keywords}%'
</if>
order by
<choose>
<when test="paramsMap.sort == "c"">
sellCounts desc
</when>
<when test="paramsMap.sort == "p"">
price asc
</when>
<otherwise>
itemName asc
</otherwise>
</choose>
</select>
</mapper>
?
?
|