一个电商项目的Web服务化改造
CREATE TABLE `brand` (
`id` varchar(50) NOT NULL COMMENT 'ID',
`name` varchar(30) DEFAULT NULL COMMENT '品牌名称',
`logo` varchar(100) DEFAULT NULL COMMENT '品牌LOGO',
`isDelete` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除',
`createTime` datetime DEFAULT NULL COMMENT '创建日期',
`updateTime` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='品牌表';
/**
* 品牌
*
*/
public class Brand {
private String id;
private String name;
private String logo;
private Date createTime;
private Date updateTime;
private Integer isDelete; }
import java.util.List;
public interface BaseMapper<ID, Entity> {
Entity get(ID id);
List<Entity> listByIdList(List<String> idList);
List<Entity> listAll();
int add(Entity entity);
int update(Entity entity);
int remove(ID id);
int removeByIdList(List<ID> idList);
}
@Mapper
public interface BrandMapper extends BaseMapper<String, Brand> {
// read List<Brand> listByShopIdList(List<String> shopIdList); List<Brand> list(BrandBean brandBean); // write }
<?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.webservice.mapper.BrandMapper">
<sql id="columns">
id,name,logo,createTime,updateTime,isDelete
</sql> <select id="get" resultType="Brand">
select
<include refid="columns" />
from brand
where id =
#{id}
</select> <select id="list" resultType="Brand">
select
<include refid="columns" />
from brand where
isDelete=0
<if test="name != null and name !=''">
and name like '%${name}%'
</if>
order by createTime desc
</select> ...
}
import java.util.List;
public interface BaseDao<ID, Entity,Bean> {
//read
Entity get(ID id);
List<Entity> listByIdList(List<String> idList);
List<Entity> list(Bean bean);
List<Entity> listAll();
//write
int add(Entity entity);
int update(Entity entity);
int remove(ID id);
int removeByIdList(List<ID> idList);
}
import java.util.List;
public interface BrandDao extends BaseDao<String, Brand,BrandBean> {
// read
List<Brand> listByShopIdList(List<String> shopIdList);
List<String> listLogoByIdList(List<String> idList);
// write
}
@Component
public class BrandDaoImpl implements BrandDao { @Autowired
private BrandMapper brandMapper; private Logger logger = Logger.getLogger(getClass()); @Override
public Brand get(String id) {
if(StringUtils.isEmpty(id)){
logger.error("The id is null");
return null;
}
return brandMapper.get(id);
} @Override
public List<Brand> listByIdList(List<String> idList) {
if (CollectionUtils.isEmpty(idList)) {
logger.error("The idList is empty");
return null;
}
return brandMapper.listByIdList(idList);
} }
//单元测试的mysql数据库,最好是单独的一套库,没有任何数据。如果开发和单元测试共用数据库,listAll之类的方法会有影响。
//单元测试:1.构造数据,2.执行操作,3.断言,4.回滚
//设置自动回滚
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
@ContextConfiguration(locations={"classpath*:spring-dataSource.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class BaseDaoTest {
public static final String NOT_EXIST_ID_STRING="not_exist_id_string";
public static final String NOT_EXIST_ID_INT="not_exist_id_int";
public static final String EXIST_NAME = "test";
public static final String NOT_EXIST_NAME = "not_exist_name";
} BrandDaoTest.java:brand的基础测试用例
public class BrandDaoTest extends BaseDaoTest { @Autowired
private BrandDao brandDao; // //////////////////////read//////////////////////////
@Test
public void testGet() {
Brand brand = TestDataCenter.brand();
brandDao.add(brand);
Brand dbBrand = brandDao.get(brand.getId());
assertNotNull(dbBrand);
} @Test
public void testGetNotExist() {
Brand brand = TestDataCenter.brand();
brandDao.add(brand);
Brand nullBrand = brandDao.get(NOT_EXIST_ID_STRING);
assertNull(nullBrand);
}
}
一个电商项目的Web服务化改造的更多相关文章
- 一个电商项目的Web服务化改造6:单元测试4步走,构造数据、执行操作、断言、回滚
最近一直在做一个电商项目,需要把原有单系统架构的项目,改造成基于服务的架构,SOA. 有点挑战,做完了,会有很大进步. 单元测试,在很早之前的文章已经介绍过. 可以在这里看到相关的 ...
- 一个电商项目的Web服务化改造3:改进方案の规范和约定、单表、单一职责
最近一直在做一个电商项目,需要把原有单系统架构的项目,改造成基于服务的架构,SOA. 有点挑战,做完了,会有很大进步. 上一篇,我们描述了原有项目中的问题. 或者说是,本篇的基本 ...
- 一个电商项目的Web服务化改造5:面向服务的分层架构设计(有图有真相)
最近一直在做一个电商项目,需要把原有单系统架构的项目,改造成基于服务的架构,SOA. 有点挑战,做完了,会有很大进步. 本篇,以我亲自画的3个图,阐述一下架构设计. 一.分层架构-总体图 ...
- 一个电商项目的Web服务化改造4:方案和架构,通用接口的定义和实现
最近一直在做一个电商项目,需要把原有单系统架构的项目,改造成基于服务的架构,SOA. 有点挑战,做完了,会有很大进步. 上一篇,我们明确了我们的"规范和约定". 从 ...
- 一个电商项目的Web服务化改造2:现有项目的5个问题
最近一直在做一个电商项目,需要把原有单系统架构的项目,改造成基于服务的架构,SOA. 有点挑战,做完了,会有很大进步, 1.现有项目的问题 1.1代码风格不统一 不同的 ...
- 一个电商项目的Web服务化改造7:Dubbo服务的调用,4个项目
使用dubbo服务的过程,很简单,和之前学习的WebService完全一样,和本地接口调用也基本一致. dubbo和WebService的区别:我认为dubbo就是封装了WebService,然后提供 ...
- 如何一步一步用DDD设计一个电商网站(六)—— 给购物车加点料,集成售价上下文
阅读目录 前言 如何在一个项目中实现多个上下文的业务 售价上下文与购买上下文的集成 结语 一.前言 前几篇已经实现了一个最简单的购买过程,这次开始往这个过程中增加一些东西.比如促销.会员价等,在我们的 ...
- 如何一步一步用DDD设计一个电商网站(十)—— 一个完整的购物车
阅读目录 前言 回顾 梳理 实现 结语 一.前言 之前的文章中已经涉及到了购买商品加入购物车,购物车内购物项的金额计算等功能.本篇准备把剩下的购物车的基本概念一次处理完. 二.回顾 在动手之前我对之 ...
- 如何一步一步用DDD设计一个电商网站(七)—— 实现售价上下文
阅读目录 前言 明确业务细节 建模 实现 结语 一.前言 上一篇我们已经确立的购买上下文和销售上下文的交互方式,传送门在此:http://www.cnblogs.com/Zachary-Fan/p/D ...
随机推荐
- caffe to tensorflow alexnet model
from kaffe.tensorflow import Network class AlexNet(Network): def setup(self): (self.feed('data') .co ...
- [转]Dialog
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...
- jQuery Uploadify在ASP.NET MVC3中的使用
1.Uploadify简介 Uploadify是基于jQuery的一种上传插件,支持多文件.带进度条显示上传,在项目开发中常被使用. Uploadify官方网址:http://www.uploadif ...
- iframe高度100%,自适应高度
声明:有更好的方法在下一篇内容中 100% http://www.360doc.com/content/11/1102/15/55892_161105115.shtml iframe自适应高度 转自: ...
- Datatable转换为Json 的方法
/// <summary> /// Datatable转换为Json /// </summary> /// <param n ...
- openstack Aio env deubg
- CSS3径向渐变实现优惠券波浪造型
效果看下图: 左右的波浪边框用CSS搞定这个效果.利用CSS radial-gradient() 函数 CSS 语法: background: radial-gradient(shape size a ...
- Android点9图的运用
在Android UI设计开发中,我们经常会用到一些图标.图片来做背景等. 相信很多同学都会遇到一个问题,就是我们让美工做好一张图,一个图标,呃,看起来挺好看的,但是放进app中,扩大或缩小.在不同分 ...
- 51nod1446 Kirchhoff矩阵+Gauss消元+容斥+折半DFS
思路: //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using ...
- 【Leetcode】115. Distinct Subsequences
Description: Given two string S and T, you need to count the number of T's subsequences appeared in ...