import java.util.List;
public interface BaseMapper {
Entity get(ID id);
List listByIdList(List idList);
List listAll();
int add(Entity entity);
int update(Entity entity);
int remove(ID id);
int removeByIdList(List idList);
}
BrandMapper.java:品牌的sql映射,Java接口定义
import java.util.List;
@Mapper
public interface BrandMapper extends BaseMapper {
// read
List listByShopIdList(List shopIdList);
List list(BrandBean brandBean);
// write
}
BrandMapper.xml:品牌的sql映射,sql语句
id,name,logo,createTime,updateTime,isDelete
...
}
BaseDao.java:定义最基础、最通用的dao层接口。
import java.util.List;
public interface BaseDao {
//read
Entity get(ID id);
List listByIdList(List idList);
List list(Bean bean);
List listAll();
//write
int add(Entity entity);
int update(Entity entity);
int remove(ID id);
int removeByIdList(List idList);
}
BrandDao.java: 品牌的dao接口
import java.util.List;
public interface BrandDao extends BaseDao {
// read
List listByShopIdList(List shopIdList);
List listLogoByIdList(List idList);
// write
}
BrandDaoImpl.java:品牌的dao接口实现类
@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 listByIdList(List idList) {
if (CollectionUtils.isEmpty(idList)) {
logger.error("The idList is empty");
return null;
}
return brandMapper.listByIdList(idList);
}
}
BrandService.java: 品牌,业务层的接口定义
代码类似
BrandServiceImpl.java:品牌,业务层的接口实现
代码类似
junit单元测试:测dao和service层,mapper层忽视
BaseDaoTest.java:dao基础配置
//单元测试的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);
}
}
在数据库系统中存储过程是必不可少的利器,存储过程是预先编译好的为实现一个复杂功能的一段Sql语句集合。它的优点我就不多说了,说一下我碰到的问题吧。我在项目开发的过程中需要用存储过程来实现一个功能,其中涉及到判断一张表是否已经建立,没有建立就由存储过程来建立这张表。
CREATE OR REPLACE PROCEDURE TestProc
IS
fla
使用jsonp不能发起POST请求。
It is not possible to make a JSONP POST request.
JSONP works by creating a <script> tag that executes Javascript from a different domain; it is not pos
(一)Keepalived
(1)安装
# cd /usr/local/src
# wget http://www.keepalived.org/software/keepalived-1.2.15.tar.gz
# tar zxvf keepalived-1.2.15.tar.gz
# cd keepalived-1.2.15
# ./configure
# make &a