(1)客户信息表user_info,用于记录前台客户基本信息。
(2)管理员信息表admin_info,用于记录管理员基本信息。
(3)商品类型表type,用于记录各种商品类型。
(4)商品信息表product_info,用于记录商品信息。
(5)订单信息表order_info,用于记录订单主要信息。
(6)订单明细表order_detail,用于记录订单详细信息。
(7)系统功能表functions,用于记录系统功能信息。
(8)权限表powers,用于记录管理员权限。
与Spring整合MyBatis配置相同,有一点不同,在修改pom.xml文件是多填了几个依赖
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
</dependency>
web.xml的配置与那一章一样
dispatcherServlet.xml与上一张相比,多了文件上传的bean
<!-- 文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件的最大尺寸为1MB -->
<property name="maxUploadSize" value="1048576" />
<!-- 字符编码 -->
<property name="defaultEncoding" value="UTF-8" />
</bean>
编写Spring配置文件与上一张一致,记得改一个配置的包名
db.properties与上一张一样
创建目录结构:
com.ecpbm.dao.provider包用于存放DynaSqlProvider类,也就是动态SQL那一章里对应的mapper包。其他的包上一章有说明
实体类放com.ecpbm.pojo包下
UserInfo用于封装客户信息
public class UserInfo {
private int id;
private String userName;
private String password;
private String realName;
private String sex;
private String address;
private String email;
private String regDate;
private int status;
//这里省略getter,setter方法
}
实体类AdminInfo用于封装管理员信息
import java.util.List;
public class AdminInfo {
private int id;
private String name;
private String pwd;
// 关联属性
private List<Functions> fs;
//这里省略getter,setter方法
}
实体类Functions用于封装系统功能信息
import java.util.HashSet;
import java.util.Set;
public class Functions implements Comparable<Functions> {
private int id;
private String name;
private int parentid;
private boolean isleaf;
//关联属性
private Set ais = new HashSet();
//这里省略getter,setter方法
//重写compareTo(Functions arg0)方法,
//该方法用于在排序时将两个Functions对象的id进行比较
//根据比较的结果是小于,等于或者大于而返回一个负数,零或者正数
@Override
public int compareTo(Functions arg0) {
return ((Integer) this.getId()).compareTo((Integer) (arg0.getId()));
}
}
实体类Powers用于封装权限信息
public class Powers {
private AdminInfo ai;
private Functions f;
//这里省略getter,setter,toString方法
}
实体类ProductInfo用于封装商品信息
public class ProductInfo {
// 商品基本信息(部分)
private int id; // 商品编号
private String code; // 商品编码
private String name; // 商品名称
// 关联属性
private Type type; // 商品类型
private String brand; // 商品品牌
private String pic; // 商品小图
private int num; // 商品数量
private double price; // 商品价格
private String intro; // 商品介绍
private int status; // 商品状态
private double priceFrom;
private double priceTo;
//这里省略getter,setter方法
}
实体类Type用于封装商品类型信息
public class Type {
private int id; // 产品类型编号
private String name; // 产品类型名称
//这里省略getter,setter方法
}
实体类OrderInfo用于封装订单信息
public class OrderInfo {
private Integer id;
private int uid;
private UserInfo ui;
private String status;
private String ordertime;
private double orderprice;
private String orderTimeFrom;
private String orderTimeTo;
//这里省略getter,setter方法
}
实体类OrderDetail用于封装订单明细信息
public class OrderInfo {
private Integer id;
private int uid;
private UserInfo ui;
private String status;
private String ordertime;
private double orderprice;
private String orderTimeFrom;
private String orderTimeTo;
//这里省略getter,setter方法
}
辅助类Pager用于封装分页信息
public class Pager {
private int curPage;// 待显示页
private int perPageRows;// 每页显示的记录数
private int rowCount; // 记录总数
private int pageCount; // 总页数
// 根据rowCount和perPageRows计算总页数
public int getPageCount() {
return (rowCount + perPageRows - 1) / perPageRows;
}
// 分页显示时,获取当前页的第一条记录的索引
public int getFirstLimitParam() {
return (this.curPage - 1) * this.perPageRows;
}
//这里省略getter,setter方法
}
辅助类SearchProductInfo用于封装商品查询条件
public class SearchProductInfo {
// 产品基本信息(部分)
private int id; // 产品编号
private String code; // 产品编码
private String name; // 产品名称
private String brand; // 产品品牌
private double priceFrom;
private double priceTo;
private int tid;
//这里省略getter,setter方法
}
会使用到Easy UI提供的Tree控件来显示菜单,TreeNode辅助类用于封装树形控件的节点信息
import java.util.List;
public class TreeNode {
private int id; // 节点id
private String text; // 节点名称
private int fid; // 父节点id
private List<TreeNode> children; // 包含的子节点
//这里省略getter,setter方法
}
在Dao接口中,使用MyBatis注解完成数据表的操作
UserInfoDao
package com.ecpbm.dao;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import com.ecpbm.dao.provider.UserInfoDynaSqlProvider;
import com.ecpbm.pojo.UserInfo;
public interface UserInfoDao {
//获取系统合法用户,即数据表user_info中status字段为1的用户列表
@Select("select * from user_info where status=1")
public List<UserInfo> getValidUser();
// 根据用户id号获取客户对象
@Select("select * from user_info where id=#{id}")
public UserInfo getUserInfoById(int id);
// 分页获取客户信息
@SelectProvider(type = UserInfoDynaSqlProvider.class, method = "selectWithParam")
List<UserInfo> selectByPage(Map<String, Object> params);
// 根据条件查询客户总数
@SelectProvider(type = UserInfoDynaSqlProvider.class, method = "count")
Integer count(Map<String, Object> params);
// 更新客户状态
@Update("update user_info set status=#{flag} where id in (${ids})")
void updateState(@Param("ids") String ids, @Param("flag") int flag);
}
同时完成类中提到的动态提供类,写在provider里
UserInfoDynaSqlProvider
package com.ecpbm.dao.provider;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;
import com.ecpbm.pojo.UserInfo;
public class UserInfoDynaSqlProvider {
// 分页动态查询
public String selectWithParam(Map<String, Object> params) {
String sql = new SQL() {
{
SELECT("*");
FROM("user_info");
if (params.get("userInfo") != null) {
UserInfo userInfo = (UserInfo) params.get("userInfo");
if (userInfo.getUserName() != null && !userInfo.getUserName().equals("")) {
WHERE(" userName LIKE CONCAT ('%',#{userInfo.userName},'%') ");
}
}
}
}.toString();
if (params.get("pager") != null) {
sql += " limit #{pager.firstLimitParam} , #{pager.perPageRows} ";
}
return sql;
}
// 根据条件动态查询总记录数
public String count(Map<String, Object> params) {
return new SQL() {
{
SELECT("count(*)");
FROM("user_info");
if (params.get("userInfo") != null) {
UserInfo userInfo = (UserInfo) params.get("userInfo");
if (userInfo.getUserName() != null && !userInfo.getUserName().equals("")) {
WHERE(" userName LIKE CONCAT ('%',#{userInfo.userName},'%') ");
}
}
}
}.toString();
}
}
FunctionDao
package com.ecpbm.dao;
import java.util.List;
import org.apache.ibatis.annotations.Select;
import com.ecpbm.pojo.Functions;
public interface FunctionDao {
// 根据管理员id,获取功能权限
@Select("select * from functions where id in (select fid from powers where aid = #{aid} )")
public List<Functions> selectByAdminId(Integer aid);
}
AdminInfoDao
package com.ecpbm.dao;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import com.ecpbm.pojo.AdminInfo;
public interface AdminInfoDao {
// 根据登录名和密码查询管理员
@Select("select * from admin_info where name = #{name} and pwd = #{pwd}")
public AdminInfo selectByNameAndPwd(AdminInfo ai);
// 根据管理员id获取管理员对象及关联的功能集合
@Select("select * from admin_info where id = #{id}")
@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "name", property = "name"),
@Result(column = "pwd", property = "pwd"),
@Result(column = "id", property = "fs", many = @Many(select = "com.ecpbm.dao.FunctionDao.selectByAdminId", fetchType = FetchType.EAGER)) })
AdminInfo selectById(Integer id);
}
TypeDao
package com.ecpbm.dao;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.ecpbm.pojo.Type;
public interface TypeDao {
// 查询所有商品类型
@Select("select * from type")
public List<Type> selectAll();
// 根据类型编号查询商品类型
@Select("select * from type where id = #{id}")
Type selectById(int id);
// 添加商品类型
@Insert("insert into type(name) values(#{name})")
@Options(useGeneratedKeys = true, keyProperty = "id")
public int add(Type type);
// 更新商品类型
@Update("update type set name = #{name} where id = #{id}")
public int update(Type type);
}
ProductInfoDao
package com.ecpbm.dao;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.mapping.FetchType;
import com.ecpbm.dao.provider.ProductInfoDynaSqlProvider;
import com.ecpbm.pojo.ProductInfo;
public interface ProductInfoDao {
// 分页获取商品
@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "code", property = "code"),
@Result(column = "name", property = "name"), @Result(column = "brand", property = "brand"),
@Result(column = "pic", property = "pic"), @Result(column = "num", property = "num"),
@Result(column = "price", property = "price"), @Result(column = "intro", property = "intro"),
@Result(column = "status", property = "status"),
@Result(column = "tid", property = "type", one = @One(select = "com.ecpbm.dao.TypeDao.selectById", fetchType = FetchType.EAGER)) })
@SelectProvider(type = ProductInfoDynaSqlProvider.class, method = "selectWithParam")
List<ProductInfo> selectByPage(Map<String, Object> params);
// 根据条件查询商品总数
@SelectProvider(type = ProductInfoDynaSqlProvider.class, method = "count")
Integer count(Map<String, Object> params);
// 添加商品
@Insert("insert into product_info(code,name,tid,brand,pic,num,price,intro,status) "
+ "values(#{code},#{name},#{type.id},#{brand},#{pic},#{num},#{price},#{intro},#{status})")
@Options(useGeneratedKeys = true, keyProperty = "id")
void save(ProductInfo pi);
// 修改商品
@Update("update product_info set code=#{code},name=#{name},tid=#{type.id},"
+ "brand=#{brand},pic=#{pic},num=#{num},price=#{price},intro=#{intro}," + "status=#{status} where id=#{id}")
void edit(ProductInfo pi);
// 更新商品状态
@Update("update product_info set status=#{flag} where id in (${ids})")
void updateState(@Param("ids") String ids, @Param("flag") int flag);
// 获取在售商品列表
@Select("select * from product_info where status=1")
List<ProductInfo> getOnSaleProduct();
// 根据产品id获取商品对象
@Select("select * from product_info where id=#{id}")
ProductInfo getProductInfoById(int id);
}
ProductInfoDynaSqlProvider SQL提供类
package com.ecpbm.dao.provider;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;
import com.ecpbm.pojo.ProductInfo;
public class ProductInfoDynaSqlProvider {
// 分页动态查询
public String selectWithParam(Map<String, Object> params) {
String sql = new SQL() {
{
SELECT("*");
FROM("product_info");
if (params.get("productInfo") != null) {
ProductInfo productInfo = (ProductInfo) params.get("productInfo");
if (productInfo.getCode() != null && !"".equals(productInfo.getCode())) {
WHERE(" code = #{productInfo.code} ");
}
if (productInfo.getName() != null && !productInfo.getName().equals("")) {
WHERE(" name LIKE CONCAT ('%',#{productInfo.name},'%') ");
}
if (productInfo.getBrand() != null && !productInfo.getBrand().equals("")) {
WHERE(" brand LIKE CONCAT ('%',#{productInfo.brand},'%') ");
}
if (productInfo.getType() != null && productInfo.getType().getId() > 0) {
WHERE(" tid = #{productInfo.type.id} ");
}
if (productInfo.getPriceFrom() > 0) {
WHERE(" price > #{productInfo.priceFrom} ");
}
if (productInfo.getPriceTo() > 0) {
WHERE(" price <= #{productInfo.priceTo} ");
}
}
}
}.toString();
if (params.get("pager") != null) {
sql += " limit #{pager.firstLimitParam} , #{pager.perPageRows} ";
}
return sql;
}
// 根据条件动态查询商品总记录数
public String count(Map<String, Object> params) {
return new SQL() {
{
SELECT("count(*)");
FROM("product_info");
if (params.get("productInfo") != null) {
ProductInfo productInfo = (ProductInfo) params.get("productInfo");
if (productInfo.getCode() != null && !"".equals(productInfo.getCode())) {
WHERE(" code = #{productInfo.code} ");
}
if (productInfo.getName() != null && !productInfo.getName().equals("")) {
WHERE(" name LIKE CONCAT ('%',#{productInfo.name},'%') ");
}
if (productInfo.getBrand() != null && !productInfo.getBrand().equals("")) {
WHERE(" brand LIKE CONCAT ('%',#{productInfo.brand},'%') ");
}
if (productInfo.getType() != null && productInfo.getType().getId() > 0) {
WHERE(" tid = #{productInfo.type.id} ");
}
if (productInfo.getPriceFrom() > 0) {
WHERE(" price > #{productInfo.priceFrom} ");
}
if (productInfo.getPriceTo() > 0) {
WHERE(" price <= #{productInfo.priceTo} ");
}
}
}
}.toString();
}
}
OrderInfo
package com.ecpbm.dao;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.mapping.FetchType;
import com.ecpbm.dao.provider.OrderInfoDynaSqlProvider;
import com.ecpbm.pojo.OrderDetail;
import com.ecpbm.pojo.OrderInfo;
public interface OrderInfoDao {
//分页获取订单信息
@Results({
@Result(column = "uid", property = "ui", one = @One(select = "com.ecpbm.dao.UserInfoDao.getUserInfoById", fetchType = FetchType.EAGER)) })
@SelectProvider(type = OrderInfoDynaSqlProvider.class, method = "selectWithParam")
List<OrderInfo> selectByPage(Map<String, Object> params);
// 根据条件查询订单总数
@SelectProvider(type = OrderInfoDynaSqlProvider.class, method = "count")
Integer count(Map<String, Object> params);
// 保存订单主表
@Insert("insert into order_info(uid,status,ordertime,orderprice) "
+ "values(#{uid},#{status},#{ordertime},#{orderprice})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int saveOrderInfo(OrderInfo oi);
// 保存订单明细
@Insert("insert into order_detail(oid,pid,num) values(#{oid},#{pid},#{num})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int saveOrderDetail(OrderDetail od);
// 根据订单编号获取订单对象
@Results({
@Result(column = "uid", property = "ui", one = @One(select = "com.ecpbm.dao.UserInfoDao.getUserInfoById", fetchType = FetchType.EAGER)) })
@Select("select * from order_info where id = #{id}")
public OrderInfo getOrderInfoById(int id);
// 根据订单编号获取订单明细
@Results({
@Result(column = "pid", property = "pi", one = @One(select = "com.ecpbm.dao.ProductInfoDao.getProductInfoById", fetchType = FetchType.EAGER)) })
@Select("select * from order_detail where oid = #{oid}")
public List<OrderDetail> getOrderDetailByOid(int oid);
// 删除订单主表记录
@Delete("delete from order_info where id=#{id}")
public int deleteOrderInfo(int id);
// 根据订单编号,删除订单明细记录
@Delete("delete from order_detail where oid=#{id}")
public int deleteOrderDetail(int id);
}
OrderInfoDynaSqlProvider SQL提供类
package com.ecpbm.dao.provider;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;
import com.ecpbm.pojo.OrderInfo;
public class OrderInfoDynaSqlProvider {
// 分页动态查询
public String selectWithParam(Map<String, Object> params) {
String sql = new SQL() {
{
SELECT("*");
FROM("order_info");
if (params.get("orderInfo") != null) {
OrderInfo orderInfo = (OrderInfo) params.get("orderInfo");
if (orderInfo.getId() != null && orderInfo.getId() > 0) {
WHERE(" id = #{orderInfo.id} ");
} else {
if (orderInfo.getStatus() != null && !"请选择".equals(orderInfo.getStatus())) {
WHERE(" status = #{orderInfo.status} ");
}
if (orderInfo.getOrderTimeFrom() != null && !"".equals(orderInfo.getOrderTimeFrom())) {
WHERE(" ordertime >= #{orderInfo.orderTimeFrom} ");
}
if (orderInfo.getOrderTimeTo() != null && !"".equals(orderInfo.getOrderTimeTo())) {
WHERE(" ordertime < #{orderInfo.orderTimeTo} ");
}
if (orderInfo.getUid() > 0) {
WHERE(" uid = #{orderInfo.uid} ");
}
}
}
}
}.toString();
if (params.get("pager") != null) {
sql += " limit #{pager.firstLimitParam} , #{pager.perPageRows} ";
}
return sql;
}
// 根据条件动态查询订单总记录数
public String count(Map<String, Object> params) {
return new SQL() {
{
SELECT("count(*)");
FROM("order_info");
if (params.get("orderInfo") != null) {
OrderInfo orderInfo = (OrderInfo) params.get("orderInfo");
if (orderInfo.getId() != null && orderInfo.getId() > 0) {
WHERE(" id = #{orderInfo.id} ");
} else {
if (orderInfo.getStatus() != null && !"请选择".equals(orderInfo.getStatus())) {
WHERE(" status = #{orderInfo.status} ");
}
if (orderInfo.getOrderTimeFrom() != null && !"".equals(orderInfo.getOrderTimeFrom())) {
WHERE(" ordertime >= #{orderInfo.orderTimeFrom} ");
}
if (orderInfo.getOrderTimeTo() != null && !"".equals(orderInfo.getOrderTimeTo())) {
WHERE(" ordertime < #{orderInfo.orderTimeTo} ");
}
if (orderInfo.getUid() > 0) {
WHERE(" uid = #{orderInfo.uid} ");
}
}
}
}
}.toString();
}
}
UserInfoService
package com.ecpbm.service;
import java.util.List;
import java.util.Map;
import com.ecpbm.pojo.Pager;
import com.ecpbm.pojo.UserInfo;
public interface UserInfoService {
//获取合法客户
public List<UserInfo> getValidUser();
// 根据用户编号查询客户
public UserInfo getUserInfoById(int id);
// 分页显示客户
List<UserInfo> findUserInfo(UserInfo userInfo, Pager pager);
// 客户计数
Integer count(Map<String, Object> params);
// 修改指定编号的客户状态
void modifyStatus(String ids, int flag);
}
UserInfoServiceImpl
package com.ecpbm.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.ecpbm.dao.UserInfoDao;
import com.ecpbm.pojo.Pager;
import com.ecpbm.pojo.UserInfo;
import com.ecpbm.service.UserInfoService;
@Service("userInfoService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class UserInfoServiceImpl implements UserInfoService {
@Autowired
UserInfoDao userInfoDao;
@Override
public List<UserInfo> getValidUser() {
return userInfoDao.getValidUser();
}
@Override
public UserInfo getUserInfoById(int id) {
return userInfoDao.getUserInfoById(id);
}
@Override
public List<UserInfo> findUserInfo(UserInfo userInfo, Pager pager) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("userInfo", userInfo);
int recordCount = userInfoDao.count(params);
pager.setRowCount(recordCount);
if (recordCount > 0) {
params.put("pager", pager);
}
return userInfoDao.selectByPage(params);
}
@Override
public Integer count(Map<String, Object> params) {
return userInfoDao.count(params);
}
@Override
public void modifyStatus(String ids, int flag) {
userInfoDao.updateState(ids, flag);
}
}
AdminInfoService
package com.ecpbm.service;
import com.ecpbm.pojo.AdminInfo;
public interface AdminInfoService {
// 登录验证
public AdminInfo login(AdminInfo ai);
// 根据管理员编号获取管理员对象及关联的功能权限
public AdminInfo getAdminInfoAndFunctions(Integer id);
}
AdminInfoServiceImpl
package com.ecpbm.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.ecpbm.dao.AdminInfoDao;
import com.ecpbm.pojo.AdminInfo;
import com.ecpbm.service.AdminInfoService;
@Service("adminInfoService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class AdminInfoServiceImpl implements AdminInfoService {
@Autowired
private AdminInfoDao adminInfoDao;
@Override
public AdminInfo login(AdminInfo ai) {
return adminInfoDao.selectByNameAndPwd(ai);
}
@Override
public AdminInfo getAdminInfoAndFunctions(Integer id) {
return adminInfoDao.selectById(id);
}
}
TypeService
package com.ecpbm.service;
import java.util.List;
import com.ecpbm.pojo.Type;
public interface TypeService {
// 获取所示商品类型
public List<Type> getAll();
// 添加商品类型
public int addType(Type type);
// 更新商品类型
public void updateType(Type type);
}
TypeServiceImpl
package com.ecpbm.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.ecpbm.dao.TypeDao;
import com.ecpbm.pojo.Type;
import com.ecpbm.service.TypeService;
@Service("typeService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class TypeServiceImpl implements TypeService {
@Autowired
private TypeDao typeDao;
@Override
public List<Type> getAll() {
return typeDao.selectAll();
}
@Override
public int addType(Type type) {
return typeDao.add(type);
}
@Override
public void updateType(Type type) {
typeDao.update(type);
}
}
ProductInfoService
package com.ecpbm.service;
import java.util.List;
import java.util.Map;
import com.ecpbm.pojo.Pager;
import com.ecpbm.pojo.ProductInfo;
public interface ProductInfoService {
// 分页显示商品
List<ProductInfo> findProductInfo(ProductInfo productInfo, Pager pager);
// 商品计数
Integer count(Map<String, Object> params);
// 添加商品
public void addProductInfo(ProductInfo pi);
// 修改商品
public void modifyProductInfo(ProductInfo pi);
// 更新商品状态
void modifyStatus(String ids, int flag);
// 获取在售商品列表
List<ProductInfo> getOnSaleProduct();
// 根据产品id获取产品对象
ProductInfo getProductInfoById(int id);
}
ProductInfoServiceImpl
package com.ecpbm.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.ecpbm.dao.ProductInfoDao;
import com.ecpbm.pojo.Pager;
import com.ecpbm.pojo.ProductInfo;
import com.ecpbm.service.ProductInfoService;
@Service("productInfoService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class ProductInfoServiceImpl implements ProductInfoService {
@Autowired
ProductInfoDao productInfoDao;
@Override
public List<ProductInfo> findProductInfo(ProductInfo productInfo, Pager pager) {
// 创建对象params
Map<String, Object> params = new HashMap<String, Object>();
// 将封装有查询条件的productInfo对象放入params
params.put("productInfo", productInfo);
// 根据条件计算商品总数
int recordCount = productInfoDao.count(params);
// 给pager对象设置rowCount属性值(记录总数)
pager.setRowCount(recordCount);
if (recordCount > 0) {
// 将page对象放入params
params.put("pager", pager);
}
// 分页获取商品信息
return productInfoDao.selectByPage(params);
}
@Override
public Integer count(Map<String, Object> params) {
return productInfoDao.count(params);
}
@Override
public void addProductInfo(ProductInfo pi) {
productInfoDao.save(pi);
}
@Override
public void modifyProductInfo(ProductInfo pi) {
productInfoDao.edit(pi);
}
@Override
public void modifyStatus(String ids, int flag) {
productInfoDao.updateState(ids, flag);
}
@Override
public List<ProductInfo> getOnSaleProduct() {
return productInfoDao.getOnSaleProduct();
}
@Override
public ProductInfo getProductInfoById(int id) {
return productInfoDao.getProductInfoById(id);
}
}
OrderInfoService
package com.ecpbm.service;
import java.util.List;
import java.util.Map;
import com.ecpbm.pojo.*;
public interface OrderInfoService {
// 分页显示订单
List<OrderInfo> findOrderInfo(OrderInfo orderInfo, Pager pager);
// 订单计数
Integer count(Map<String, Object> params);
// 添加订单主表
public int addOrderInfo(OrderInfo oi);
// 添加订单明细
public int addOrderDetail(OrderDetail od);
// 根据订单编号获取订单信息
public OrderInfo getOrderInfoById(int id);
// 更加订单编号获取订单明细信息
public List<OrderDetail> getOrderDetailByOid(int oid);
// 删除订单
public int deleteOrder(int id);
}
OrderInfoServiceImpl
package com.ecpbm.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.ecpbm.dao.OrderInfoDao;
import com.ecpbm.pojo.OrderDetail;
import com.ecpbm.pojo.OrderInfo;
import com.ecpbm.pojo.Pager;
import com.ecpbm.service.OrderInfoService;
@Service("orderInfoService")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class OrderInfoServiceImpl implements OrderInfoService {
@Autowired
OrderInfoDao orderInfoDao;
@Override
public List<OrderInfo> findOrderInfo(OrderInfo orderInfo, Pager pager) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("orderInfo", orderInfo);
int recordCount = orderInfoDao.count(params);
pager.setRowCount(recordCount);
if (recordCount > 0) {
params.put("pager", pager);
}
return orderInfoDao.selectByPage(params);
}
@Override
public Integer count(Map<String, Object> params) {
return orderInfoDao.count(params);
}
@Override
public int addOrderInfo(OrderInfo oi) {
return orderInfoDao.saveOrderInfo(oi);
}
@Override
public int addOrderDetail(OrderDetail od) {
return orderInfoDao.saveOrderDetail(od);
}
@Override
public OrderInfo getOrderInfoById(int id) {
return orderInfoDao.getOrderInfoById(id);
}
@Override
public List<OrderDetail> getOrderDetailByOid(int oid) {
return orderInfoDao.getOrderDetailByOid(oid);
}
@Override
public int deleteOrder(int id) {
int result = 1;
try {
orderInfoDao.deleteOrderDetail(id);
orderInfoDao.deleteOrderInfo(id);
} catch (Exception e) {
result = 0;
}
return result;
}
}
这都两万七千字了,后面的换下一张吧,我看了下,这个EasyUi还是有必要多花点篇幅说明下。
ProcessOn:画图
SQLyog:图形化管理MYSQL数据库的工具
eclipse