具体代码已经上传至GitHub
代码链接
一:前台展示页面:
对于该前台展示页面分为上中下三部分,上面的导航栏和中间的主体部分以及下面的未显示的一个底部信息
二,后台管理界面
1.登陆界面:
2.登陆后的展示的界面
**
一:
二:
三:
**
一个模块里面大致分为下面几个部分:
大致为一个实体类即entity类,一个控制器,一个dao层的接口,一个Service接口,一个SerrviceImpl的实现类,一个数据库对应的mapper映射文件,以及一个或多个前端页面所对应的jsp文件。
先说后台管理界面的:
控制器
dao层接口
entity实体类
拦截器
分页
service接口
serviceImpl实现类
util工具类
mapper映射文件,mybatis,spring,springmvc的配置文件,以及数据库连接文件和日志文件
前端界面
一、web.xml文件:
1. 首先在web.xml文件里面配置中文乱码过滤器
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
2. sprinf配置文件信息
contextConfigLocation
classpath:config/spring/applicationContext.xml
3. 日志配置
log4jConfigLocation
classpath:config/log4j.properties
org.springframework.web.util.Log4jConfigListener
4. 配置前端控制器
DispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:config/springmvc/springmvc.xml
1
DispatcherServlet
/
404
/WEB-INF/errors/404.jsp
500
/WEB-INF/errors/500.jsp
index.jsp
5. 监听器
org.springframework.web.context.ContextLoaderListener
二、entity实体类的解释
admin文件夹
1. User
/**
* 用户实体类
* @author 17877
*
*/
@Component
public class User {
private Long id;//用户id,设置自增
private String username;//用户名,登录名
private String password;//登录密码
private Long roleId;//所属角色id
private String photo;//头像照片地址
private int sex;//性别0,代表未知,1代表男,2代表女
private Integer age;//年龄
private String address;//家庭住址
2. Log
/**
* 系统日志
* @author 17877
*
*/
@Component
public class Log {
private Long id;
private String content;//日志内容
private Date createTime;//创建时间
3. Menu
/**
* 菜单实体类
* @author 17877
*
*/
@Component
public class Menu {
private Long id;
private Long parentId;//父类id
private Long _parentId;//父类id,用来匹配easyui的父类id
private String name;//菜单名称
private String url;//点击后的url
private String icon;//菜单icon图表
4. Role
/**
* 角色role实体
* @author 17877
*
*/
@Component
public class Role {
private Long id;
private String name;
private String remark;//角色备注
5. Authority
/**
* 权限实体
* @author llq
*
*/
@Component
public class Authority {
private Long id;
private Long roleId;//角色id
private Long menuId;//菜单id
common
1. Account
/**
* 客户实体
* @author17877
*
*/
@Component
public class Account {
private Long id;//客户id
private String name;//客户名称
private String password;//密码
private String email;//邮箱
private String trueName ;//真实姓名
private int sex;//性别:0:未知,1:男,2:女
private int status;//状态:0:表示冻结、1:表示可用
private Date createTime;//注册时间
2. Comment
/**
* 评论实体
* @author 17877
*
*/
@Component
public class Comment {
private Long id;//评论id
private Long productId;//所属商品id
private Product product;
private Long userId;//所属用户id
private Account account;
private int type;//评价类型,0:差评,1:好评,2:中评
private String content;//评论内容
private Date createTime;//评论时间
3. Order
/**
* 订单实体
* @author17877
*
*/
@Component
public class Order {
public static int ORDER_STATUS_WAITING = 0;//待发货
public static int ORDER_STATUS_SENT = 1;//已发货
public static int ORDER_STATUS_FINISH = 2;//已完成
private Long id;//订单分类id
private String sn;//订单编号
private Long userId;//所属用户id
private String address;//收货地址
private Double money;//订单总价
private int productNum;//订单商品数
private int status;//订单状态
private String remark;//订单备注
private Date createTime;//添加时间
private List orderItems = new ArrayList();
4. OrderItem
/**
* 订单子项实体
* @author17877
*
*/
@Component
public class OrderItem {
private Long id;//商品分类id
private Long orderId;//所属订单id
private Long productId;//所属商品id
private String name;//商品名称
private String imageUrl;//商品主图
private Double price;//商品价格
private int num;//商品数量
private Double money;//商品金额
5. Product
/**
* 商品实体
* @author17877
*
*/
@Component
public class Product {
private Long id;//商品分类id
private Long productCategoryId;//分类id
private String name;//商品名称
private String tags;//分类标签,用来按照商品分类搜索
private String imageUrl;//商品主图
private Double price;//商品价格
private int stock;//商品库存
private int sellNum;//销量
private int viewNum;//浏览量
private int commentNum;//评论数
private String content;//商品详情描述
private Date createTime;//添加时间
6. ProductCategory
/**
* 商品分类实体
* @author 17877
*
*/
@Component
public class ProductCategory {
private Long id;//商品分类id
private Long parentId;//分类父id
private Long _parentId;//父类id,用来匹配easyui的父类id
private String name;//商品分类名称
private String tags;//分类标签,用来标记识别分类的层级关系
private String remark;//商品分类备注
1.AuthorityDao
/**
* user用户的 dao
* @author 17877
*
*/
@Repository
public interface UserDao {
public User findByUsername(String username);
public int add(User user);
public int edit(User user);
public int editPassword(User user);
public int delete(String ids);
public List findList(Map queryMap);
public int getTotal(Map queryMap);
}
2.LogDao
/**
* 系统日志类Dao
* @author 17877
*
*/
@Repository
public interface LogDao {
public int add(Log log);
public List findList(Map queryMap);
public int getTotal(Map queryMap);
public int delete(String ids);
}
3.MenuDao
/**
* 菜单管理dao
* @author llq
*
*/
@Repository
public interface MenuDao {
public int add(Menu menu);
public List
4.RoleDao
/**
* 角色role dao
* @author llq
*
*/
@Repository
public interface RoleDao {
public int add(Role role);
public int edit(Role role);
public int delete(Long id);
public List findList(Map queryMap);
public int getTotal(Map queryMap);
public Role find(Long id);
}
5.UserDao
/**
* user用户的 dao
* @author 17877
*
*/
@Repository
public interface UserDao {
public User findByUsername(String username);
public int add(User user);
public int edit(User user);
public int editPassword(User user);
public int delete(String ids);
public List findList(Map queryMap);
public int getTotal(Map queryMap);
}
1.Account
/**
* 客户dao层
* @author 17877
*
*/
@Repository
public interface AccountDao {
/**
* 添加客户
* @param account
* @return
*/
public int add(Account account);
/**
* 编辑客户
* @param account
* @return
*/
public int edit(Account account);
/**
* 删除客户
* @param id
* @return
*/
public int delete(Long id);
/**
* 多条件搜索词查询客户
* @param queMap
* @return
*/
public List findList(Map queryMap);
/**
* 获取符合条件的总记录数
* @param queryMap
* @return
*/
public Integer getTotal(Map queryMap);
/**
* 根据id查询客户
* @param id
* @return
*/
public Account findById(Long id);
/**
* 根据用户名查找客户
* @param name
* @return
*/
public Account findByName(String name);
}
2.CommentDao
/**
* 商品dao层
* @author 17877
*
*/
@Repository
public interface CommentDao {
/**
* 添加评论
* @param comment
* @return
*/
public int add(Comment comment);
/**
* 编辑评论
* @param comment
* @return
*/
public int edit(Comment comment);
/**
* 删除评论
* @param id
* @return
*/
public int delete(Long id);
/**
* 多条件搜索词查询评论
* @param queMap
* @return
*/
public List findList(Map queryMap);
/**
* 获取符合条件的总记录数
* @param queryMap
* @return
*/
public Integer getTotal(Map queryMap);
/**
* 根据id查询评论
* @param id
* @return
*/
public Comment findById(Long id);
}
3.OrderDao
/**
* 订单dao层
* @author 17877
*
*/
@Repository
public interface OrderDao {
/**
* 添加订单
* @param order
* @return
*/
public int add(Order order);
/**
* 添加订单子项
* @param orderItem
* @return
*/
public int addItem(OrderItem orderItem);
/**
* 编辑订单
* @param order
* @return
*/
public int edit(Order order);
/**
* 删除订单
* @param id
* @return
*/
public int delete(Long id);
/**
* 多条件搜索词查询订单
* @param queMap
* @return
*/
public List findList(Map queryMap);
/**
* 获取符合条件的总记录数
* @param queryMap
* @return
*/
public Integer getTotal(Map queryMap);
/**
* 根据id查询订单
* @param id
* @return
*/
public Order findById(Long id);
/**
* 根据订单号查询所属的订单子项
* @param orderId
* @return
*/
public List findOrderItemList(Long orderId);
/**
* 获取统计信息
* @param queryMap
* @return
*/
public List
4.ProductCategoryDao
/**
* 商品分类dao层
* @author 17877
*
*/
@Repository
public interface ProductCategoryDao {
/**
* 添加商品分类
* @param productCategory
* @return
*/
public int add(ProductCategory productCategory);
/**
* 编辑商品分类
* @param productCategory
* @return
*/
public int edit(ProductCategory productCategory);
/**
* 删除商品分类
* @param id
* @return
*/
public int delete(Long id);
/**
* 多条件搜索词查询商品分类
* @param queMap
* @return
*/
public List findList(Map queMap);
/**
* 获取符合条件的总记录数
* @param queryMap
* @return
*/
public Integer getTotal(Map queryMap);
/**
* 根据id查询商品分类
* @param id
* @return
*/
public ProductCategory findById(Long id);
}
5.ProductDao
* 商品dao层信息
* @author 17877
*
*/
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import com.xieyunjie.programmer.entity.common.Product;
@Repository
public interface ProductDao {
/**
* 添加商品
* @param productCategory
* @return
*/
public int add(Product product);
/**
* 编辑商品
* @param productCategory
* @return
*/
public int edit(Product product);
/**
* 删除商品
* @param id
* @return
*/
public int delete(Long id);
/**
* 多条件搜索词查询商品
* @param queMap
* @return
*/
public List findList(Map queryMap);
/**
* 获取符合条件的总记录数
* @param queryMap
* @return
*/
public Integer getTotal(Map queryMap);
/**
* 根据id查询商品
* @param id
* @return
*/
public Product findById(Long id);
/**
* 更新统计信息
* @param product
* @return
*/
public int updateNum(Product product);
}
Service
例如:UserService
/**
* uesr用户service
* @author 17877
*
*/
@Service
public interface UserService {
public User findByUsername(String username);
public int add(User user);
public int edit(User user);
public int editPassword(User user);
public int delete(String ids);
public List findList(Map queryMap);
public int getTotal(Map queryMap);
}
其余方法同上,内容同dao层
Serviceimpl
例如:UserServiceImpl
/**
* user用户serviceImpl
* @author 17877
*
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User findByUsername(String username) {
// TODO Auto-generated method stub
return userDao.findByUsername(username);
}
@Override
public int add(User user) {
// TODO Auto-generated method stub
return userDao.add(user);
}
@Override
public int edit(User user) {
// TODO Auto-generated method stub
return userDao.edit(user);
}
@Override
public int delete(String ids) {
// TODO Auto-generated method stub
return userDao.delete(ids);
}
@Override
public List findList(Map queryMap) {
// TODO Auto-generated method stub
return userDao.findList(queryMap);
}
@Override
public int getTotal(Map queryMap) {
// TODO Auto-generated method stub
return userDao.getTotal(queryMap);
}
@Override
public int editPassword(User user) {
// TODO Auto-generated method stub
return userDao.editPassword(user);
}
}
其余方法同上,这里不再赘述
拦截器
后台登陆拦截器
/**
* 后台登录拦截器
* @author 17877
*
*/
public class LoginInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView arg3) throws Exception {
// TODO Auto-generated method stub
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object arg2) throws Exception {
// TODO Auto-generated method stub
String requestURI = request.getRequestURI();
Object admin = request.getSession().getAttribute("admin");
if(admin == null){
//表示未登录或者登录失效
System.out.println("链接"+requestURI+"进入拦截器!");
String header = request.getHeader("X-Requested-With");
//判断是否是ajax请求
if("XMLHttpRequest".equals(header)){
//表示是ajax请求
Map ret = new HashMap();
ret.put("type", "error");
ret.put("msg", "登录会话超时或还未登录,请重新登录!");
response.getWriter().write(JSONObject.fromObject(ret).toString());
return false;
}
//表示是普通链接跳转,直接重定向到登录页面
response.sendRedirect(request.getServletContext().getContextPath() + "/system/login");
return false;
}
//获取菜单id
String mid = request.getParameter("_mid");
if(!StringUtils.isEmpty(mid)){
List allThirdMenu = MenuUtil.getAllThirdMenu((List)request.getSession().getAttribute("userMenus"), Long.valueOf(mid));
request.setAttribute("thirdMenuList", allThirdMenu);
}
return true;
}
}
分页的基本信息
/**
* 分页基本信息
* @author 17877
*
*/
@Component
public class Page {
private int page = 1;//当前页码
private int rows;//每页显示数量
private int offset;//对应数据库中的偏移量
验证码的生成器
/**
* 验证码生成器
*
* @author llq
*/
public class CpachaUtil {
/**
* 验证码来源
*/
final private char[] code = {
'2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};
/**
* 字体
*/
final private String[] fontNames = new String[]{
"黑体", "宋体", "Courier", "Arial",
"Verdana", "Times", "Tahoma", "Georgia"};
/**
* 字体样式
*/
final private int[] fontStyles = new int[]{
Font.BOLD, Font.ITALIC|Font.BOLD
};
//代码过多这里不再赘述!
菜单操作的公用方法
/**
* 关于菜单操作的一些公用方法
* @author 17877
*
*/
public class MenuUtil {
/**
* 从给定的菜单中返回所有顶级菜单
* @param menuList
* @return
*/
public static List getAllTopMenu(List menuList){
List ret = new ArrayList();
for(Menu menu:menuList){
if(menu.getParentId() == 0){
ret.add(menu);
}
}
return ret;
}
/**
* 获取所有的二级菜单
* @param menuList
* @return
*/
public static List getAllSecondMenu(List menuList){
List ret = new ArrayList();
List allTopMenu = getAllTopMenu(menuList);
for(Menu menu:menuList){
for(Menu topMenu:allTopMenu){
if(menu.getParentId() == topMenu.getId()){
ret.add(menu);
break;
}
}
}
return ret;
}
//代码过多这里不再赘述!
mybatis
数据库的映射文件
1.admin
(1).AuthorityMapper.xml
insert into authority(id,roleId,menuId) values(null,#{roleId},#{menuId})
delete from authority where roleId = #{roleId}
(2).LogMapper.xml
insert into log(id,content,createTime) values(null,#{content},#{createTime})
delete from log where id in(${value})
(3).MenuMapper.xml
insert into menu(id,parentId,name,url,icon) values(null,#{parentId},#{name},#{url},#{icon})
update menu set name = #{name},parentId = #{parentId},url = #{url},icon = #{icon} where id = #{id}
delete from menu where id = #{id}
(4).RoleMapper.xml
insert into role(id,name,remark) values(null,#{name},#{remark})
update role set name = #{name},remark = #{remark} where id = #{id}
delete from role where id = #{id}
(5).UserMapper.xml
insert into user(id,username,password,roleId,photo,sex,age,address) values(null,#{username},#{password},#{roleId},#{photo},#{sex},#{age},#{address})
update user set username = #{username},roleId = #{roleId},photo = #{photo},sex = #{sex},age = #{age},address = #{address} where id = #{id}
update user set password = #{password} where id = #{id}
delete from user where id in(${value})
2.common文件夹下的目录为:
(1).AccountMapper.xml
(2).CommentMapper.xml
(3).OrderMapper.xml
(4).ProductCategoryMapper.xml
(5).ProductMapper.xml
具体代码这里不再赘述!
spring
1.加载过滤器
2. 加载配数据源配置文件 db.properties
3.配置 C3P0 数据源
4.事务管理器 (JDBC)
5.启动声明式事务驱动
6.spring 通过 sqlSessionFactoryBean 获取 sqlSessionFactory 工厂类
7.配置扫描 dao 包,动态实现 dao 接口,注入到 spring 容器中
8.具体代码不在赘述!
springmvc
1.扫描包中的 Controller 注解
2. 启动 mvc 注解驱动
3.启动定时任务
4.静态资源处理
*5.配置视图解析器 *
6.上传文件
7.后台访问拦截器
具体代码这里不再赘述!
数据库连接文件
datasource.connection.driver_class=com.mysql.jdbc.Driver
datasource.connection.url=jdbc:mysql://localhost:3306/db_online_shop?useUnicode=true&characterEncoding=utf-8
datasource.connection.username=root
datasource.connection.password=root
日志文件
### direct log message to stdout ###
log4j.appender.stdout.Target = System.out
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=INFO, stdout
#debug,info,warning,error
1.AccountController
客户管理控制器
@RequestMapping("/admin/account")
@Controller
public class AccountController {
@Autowired
private AccountService accountService;
/**
* 客户列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("account/list");
return model;
}
具体代码这里不再赘述!
2.CommentCotntroller
/**
* 评论管理控制器
* @author Administrator
*
*/
@RequestMapping("/admin/comment")
@Controller
public class CommentController {
@Autowired
private CommentService commentService;
/**
* 评论列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("comment/list");
return model;
}
具体代码这里不再赘述!
3.LogController
/**
* 日志管理控制器
* @author llq
*
*/
@RequestMapping("/admin/log")
@Controller
public class LogController {
@Autowired
private LogService logService;
/**
* 日志列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("log/list");
return model;
}
具体代码这里不再赘述!
4.MenuController
/**
* 菜单管理控制器
* @author llq
*
*/
@RequestMapping("/admin/menu")
@Controller
public class MenuController {
@Autowired
private MenuService menuService;
/**
* 菜单管理列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.addObject("topList", menuService.findTopList());
model.setViewName("menu/list");
return model;
}
5.OrderController
/**
* 订单管理控制器
* @author Administrator
*
*/
@RequestMapping("/admin/order")
@Controller
public class OrderController {
@Autowired
private OrderService orderService;
@Autowired
private AccountService accountService;
/**
* 订单列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("order/list");
model.addObject("accountList", JSONArray.fromObject(accountService.findList(new HashMap())));
return model;
}
6.ProductCategoryController
/**
* 商品分类管理控制器
* @author 17877
*
*/
@RequestMapping("/admin/product_category")
@Controller
public class ProductCategoryController {
@Autowired
private ProductCategoryService productCategoryService;
/**
* 商品分类列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model) {
model.setViewName("product_category/list");
return model;
}
7.ProductController
/**
* 商品管理控制器
* model.setViewName("product/list");
* 对应的是视图的.js文件
* @author Administrator
*
*/
@RequestMapping("/admin/product")
@Controller
public class ProductController {
@Autowired
private ProductCategoryService productCategoryService;
@Autowired
private ProductService productService;
/**
* 商品列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("product/list");
model.addObject("productCategoryList", JSONArray.fromObject(productCategoryService.findList(new HashMap())));
return model;
}
8.RoleController
/**
* 角色role控制器
* @author llq
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("/role/list");
return model;
}
9.StatsController
/**
* 统计管理控制器
* @author llq
*
*/
@RequestMapping("/admin/stats")
@Controller
public class StatsController {
@Autowired
private OrderService orderService;
/**
* 统计列表页面
* @param model
* @return
*/
@RequestMapping(value="/stats",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("stats/stats");
return model;
}
10.SystemController
/**
* 系统操作类控制器
* @author 17877
*
*/
@Controller
@RequestMapping("/system")
public class SystemController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
@Autowired
private LogService logService;
/**
* 系统登录后的主页
* @param model
* @return
*/
@RequestMapping(value="/index",method=RequestMethod.GET)
public ModelAndView index(ModelAndView model,HttpServletRequest request){
List userMenus = (List)request.getSession().getAttribute("userMenus");
model.addObject("topMenuList", MenuUtil.getAllTopMenu(userMenus));
model.addObject("secondMenuList", MenuUtil.getAllSecondMenu(userMenus));
model.setViewName("system/index");
return model;//WEB-INF/views/+system/index+.jsp = WEB-INF/views/system/index.jsp
}
11.UserControlle
/**
* 用户管理控制器
* @author llq
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 用户列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
Map queryMap = new HashMap();
model.addObject("roleList", roleService.findList(queryMap));
model.setViewName("user/list");
return model;
}
1.system/login.jsp后台登陆界面
2.system/index.jsp后台管理主页
3.system/welcome.jsp欢迎界面
4.system/edit_password.jsp修改密码界面
5.menu/list.jsp菜单管理界面
6.role/list.jsp角色管理界面
7.user/list.jsp用户列表界面
8.log/list.jsp日志界面
9.product_category/list.jsp商品分类,分类列表
10.product/list.jsp商品管理商品列表界面
11.account/list.jsp客户管理客户列表界面
12.order/list.jsp订单管理订单列表
13.comment/list.jsp评论管理评论列表
14.stats/ststs.jsp销售统计,统计图表
项目视频