前端展示系统用来对店铺信息和商品信息进行展示,是顾客了解商品的门户。
首页开发:
- 1.头条读取以及滚动播放
- 2.一级类别列表的获取,之前只是二级类别的获取
1.头条Dao层
1.1 Dao接口
package com.csj2018.o2o.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.csj2018.o2o.entity.HeadLine;
public interface HeadLineDao {
/**
* 9-1根据传入的查询条件返回头角
* @param headLineCondition
* @return
*/
List<HeadLine> queryHeadLine(@Param("headLineCondition") HeadLine headLineCondition);
}
1.2 mapper实现
<?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.csj2018.o2o.dao.HeadLineDao">
<!-- 9-1 -->
<select id="queryHeadLine" resultType="com.csj2018.o2o.entity.HeadLine">
select
line_id,line_name,line_link,line_img,priority,enable_status,create_time,last_edit_time
from tb_head_line;
<where>
<if test="headLineCondition.enableStatus!=null">
and enable_status = #{headLineCondition.enableStatus}
</if>
</where>
order by priority desc
</select>
</mapper>
1.3 Dao单元测试
package com.csj2018.o2o.dao;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.csj2018.o2o.BaseTest;
import com.csj2018.o2o.entity.HeadLine;
public class HeadLineTest extends BaseTest{
@Autowired
private HeadLineDao headLineDao;
@Test
public void testQueryHeadLine() {
List<HeadLine> headLineList = headLineDao.queryHeadLine(new HeadLine());
assertEquals(headLineList.size(),0);
}
}
![](https://img2020.cnblogs.com/blog/1418970/202003/1418970-20200323223446421-839184339.png)
2.商品类别Dao层
商品列别queryShopCategory只支持二级类别,现在改写支持一级类别
<?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.csj2018.o2o.dao.ShopCategoryDao">
<!-- 9-1 -->
<select id="queryShopCategory" resultType="com.csj2018.o2o.entity.ShopCategory" >
select
shop_category_id,
shop_category_name,
shop_category_desc,
shop_category_img,
priority,create_time,
last_edit_time,
parent_id
from tb_shop_category
<where>
<if test="shopCategoryCondition == null">
and parent_id is null
</if>
<if test="shopCategoryCondition != null">
and parent_id is not null
</if>
<if test="shopCategoryCondition != null and shopCategoryCondition.parent != null and shopCategoryCondition.parent.shopCategoryId != null">
and parent_id = #{shopCategoryCondition.parent.shopCategoryId}
</if>
</where>
order by priority desc;
</select>
<select id="queryAllShopCategory" resultType="com.csj2018.o2o.entity.ShopCategory">
select shop_category_id,
shop_category_name,
shop_category_desc,
shop_category_img,
priority,
create_time,
last_edit_time,
parent_id
from tb_shop_category order by priority desc
</select>
</mapper>
2.2 单元测试
package com.csj2018.o2o.dao;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.csj2018.o2o.BaseTest;
import com.csj2018.o2o.entity.ShopCategory;
public class ShopCategoryDaoTest extends BaseTest {
@Autowired
private ShopCategoryDao shopCategoryDao;
@Test
@Ignore
public void testQueryShopCategory() {
//parent_id为1
ShopCategory sonCategory = new ShopCategory();
ShopCategory parentCategory = new ShopCategory();
parentCategory.setShopCategoryId(1L);
sonCategory.setParent(parentCategory);
List<ShopCategory>shopCategoryList = shopCategoryDao.queryShopCategory(sonCategory);
System.out.println(shopCategoryList.get(0).getShopCategoryName());
assertEquals(1,shopCategoryList.size());
}
@Test
@Ignore
public void testAllCategory() {
//传入空的类
List<ShopCategory> shopCategoryList = shopCategoryDao.queryAllShopCategory();
assertEquals(2,shopCategoryList.size());
}
//9-1
@Test
public void testQueryShopCategory2() {
List<ShopCategory> shopCategoryList = shopCategoryDao.queryShopCategory(null);
assertEquals(shopCategoryList.size(),0);
}
}