58,454
社区成员
发帖
与我相关
我的任务
分享
<?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.jubobo.dcmanager.mapper.BrandMapper">
<select id="getAllBrands" resultType="Brand">
select MesId,Name,Prod_typ,LastTime,Mask from brand where 1=1
</select>
<select id="getBrandByMesID" resultType="Brand">
select MesId,Name,Prod_typ,LastTime,Mask from brand where MesId=#{mesid}
</select>
<insert id="Insert">
insert into brand (MesId,Name,Prod_typ,LastTime,Mask)
values(#{MesId},#{Name},#{Prod_typ},#{LastTime},#{Mask})
</insert>
<delete id="Delete">
delete from brand where MesId=#{mesid}
</delete>
<update id="Update">
update brand set MesId=#{MesId},Name=#{Name},Prod_typ=#{Prod_typ},LastTime=#{LastTime},Mask=#{Mask}
where MesId=#{mesid}
</update>
</mapper>
package com.jubobo.dcmanager.entities;
import java.sql.Timestamp;
import org.apache.ibatis.annotations.Param;
/*
* 牌号数据
*/
public class Brand{
/*
* Mes系统唯一标识
*/
private int MesId;
/*
* 牌号名称
*/
private String Name;
/*
* 产品类型(如:卷包)
*/
private String Prod_typ;
/*
* 最后修改时间
*/
private String LastTime;
/*
* 是否屏蔽
*/
private String Mask;
public Brand(int mesid,String name,String prod_type,String lasttime,String mask)
{
super();
this.MesId = mesid;
this.Name = name;
this.Prod_typ = prod_type;
this.LastTime = lasttime;
this.Mask = mask;
}
public int getMesId() {
return MesId;
}
public void setMesId(int mesId) {
MesId = mesId;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getProd_typ() {
return Prod_typ;
}
public void setProd_typ(String prod_typ) {
Prod_typ = prod_typ;
}
public String getLastTime() {
return LastTime;
}
public void setLastTime(String lastTime) {
LastTime = lastTime;
}
public String getMask() {
return Mask;
}
public void setMask(String mask) {
Mask = mask;
}
}
package com.jubobo.dcmanager.service;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jubobo.dcmanager.entities.Brand;
import com.jubobo.dcmanager.mapper.BrandMapper;
@Service
public class BrandService{
@Resource
BrandMapper branddao;
public List<Brand> getAllBrands()
{
return branddao.getAllBrands();
}
public Brand getBrandByMesID(String mesid)
{
return branddao.getBrandByMesID(mesid);
}
public int Insert(Brand brand)throws Exception
{
if(brand.getMesId()<0){
throw new Exception("MesId不能小于0");
}
if(brand.getName().equals("")||brand.getName()==null){
throw new Exception("牌号名称不能为空");
}
if(brand.getProd_typ().equals("")||brand.getProd_typ()==null){
throw new Exception("牌号类型不能为空");
}
if(brand.getMask().equals("")||brand.getMask()==null){
throw new Exception("屏蔽属性不能为空");
}
return branddao.Insert(brand);
}
public int Insert(Brand entity1,Brand entityBak){
int rows=0;
rows=branddao.Insert(entity1);
rows=branddao.Insert(entityBak);
return rows;
}
public int Delete(String id)
{
return branddao.Delete(id);
}
/**
* 多删除
*/
public int Delete(String[] ids){
int rows=0;
for (String idStr : ids) {
//int id=Integer.parseInt(idStr);
rows+=Delete(idStr);
}
return rows;
}
public int Update(Brand brand)
{
return branddao.Update(brand);
}
}
package com.jubobo.dcmanager.test;
import static org.junit.Assert.*;
import java.sql.Timestamp;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.jubobo.dcmanager.entities.Brand;
import com.jubobo.dcmanager.service.BrandService;
public class TestBrandService {
static BrandService brandService;
@Before
public void before()
{
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
brandService = ctx.getBean(BrandService.class);
}
@Test
public void testGetAllBrands()
{
List<Brand> brands = brandService.getAllBrands();
assertNotNull(brands);
}
}