源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目分为前后台,前台为普通用户登录,后台为管理员登录;
用户角色包含以下功能:
用户登录与注册,查看首页,查看菜品详情,查看购物车,提交订单,查看订单,修改个人信息等功能。
管理员角色包含以下功能:
管理员登录,员工信息管理,菜品信息管理,订单信息管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+CSS+JavaScript+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
用户管理控制层:
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/users" , produces = "text/plain;charset=utf-8")
public class UsersAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private UsersService usersService;
// 准备添加数据
@RequestMapping("createUsers.action")
public String createUsers() {
return "admin/addusers";
}
// 添加数据
@RequestMapping("addUsers.action")
public String addUsers(Users users) {
users.setRegdate(VeDate.getStringDateShort());
this.usersService.insertUsers(users);
return "redirect:/users/createUsers.action";
}
// 通过主键删除数据
@RequestMapping("deleteUsers.action")
public String deleteUsers(String id) {
this.usersService.deleteUsers(id);
return "redirect:/users/getAllUsers.action";
}
// 批量删除数据
@RequestMapping("deleteUsersByIds.action")
public String deleteUsersByIds() {
String[] ids = this.getRequest().getParameterValues("usersid");
for (String usersid : ids) {
this.usersService.deleteUsers(usersid);
}
return "redirect:/users/getAllUsers.action";
}
// 更新数据
@RequestMapping("updateUsers.action")
public String updateUsers(Users users) {
this.usersService.updateUsers(users);
return "redirect:/users/getAllUsers.action";
}
// 显示全部数据
@RequestMapping("getAllUsers.action")
public String getAllUsers(String number) {
List<Users> usersList = this.usersService.getAllUsers();
PageHelper.getPage(usersList, "users", null, null, 10, number, this.getRequest(), null);
return "admin/listusers";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryUsersByCond.action")
public String queryUsersByCond(String cond, String name, String number) {
Users users = new Users();
if(cond != null){
if ("username".equals(cond)) {
users.setUsername(name);
}
if ("password".equals(cond)) {
users.setPassword(name);
}
if ("realname".equals(cond)) {
users.setRealname(name);
}
if ("sex".equals(cond)) {
users.setSex(name);
}
if ("birthday".equals(cond)) {
users.setBirthday(name);
}
if ("contact".equals(cond)) {
users.setContact(name);
}
if ("regdate".equals(cond)) {
users.setRegdate(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.usersService.getUsersByLike(users), "users", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryusers";
}
// 按主键查询数据
@RequestMapping("getUsersById.action")
public String getUsersById(String id ) {
Users users = this.usersService.getUsersById(id);
this.getRequest().setAttribute("users", users);
return "admin/editusers";
}
public UsersService getUsersService() { return usersService; }
public void setUsersService(UsersService usersService) { this.usersService = usersService; }
}
购物车管理控制层:
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cart", produces = "text/plain;charset=utf-8")
public class CartAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private CartService cartService;
@Autowired
@Resource
private UsersService usersService;
@Autowired
@Resource
private JiancaiService jiancaiService;
// 准备添加数据
@RequestMapping("createCart.action")
public String createCart() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
this.getRequest().setAttribute("jiancaiList", jiancaiList);
return "admin/addcart";
}
// 添加数据
@RequestMapping("addCart.action")
public String addCart(Cart cart) {
this.cartService.insertCart(cart);
return "redirect:/cart/createCart.action";
}
// 通过主键删除数据
@RequestMapping("deleteCart.action")
public String deleteCart(String id) {
this.cartService.deleteCart(id);
return "redirect:/cart/getAllCart.action";
}
// 批量删除数据
@RequestMapping("deleteCartByIds.action")
public String deleteCartByIds() {
String[] ids = this.getRequest().getParameterValues("cartid");
for (String cartid : ids) {
this.cartService.deleteCart(cartid);
}
return "redirect:/cart/getAllCart.action";
}
// 更新数据
@RequestMapping("updateCart.action")
public String updateCart(Cart cart) {
this.cartService.updateCart(cart);
return "redirect:/cart/getAllCart.action";
}
// 显示全部数据
@RequestMapping("getAllCart.action")
public String getAllCart(String number) {
List<Cart> cartList = this.cartService.getAllCart();
PageHelper.getPage(cartList, "cart", null, null, 10, number, this.getRequest(), null);
return "admin/listcart";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryCartByCond.action")
public String queryCartByCond(String cond, String name, String number) {
Cart cart = new Cart();
if (cond != null) {
if ("username".equals(cond)) {
cart.setUsername(name);
}
if ("jiancainame".equals(cond)) {
cart.setJiancainame(name);
}
if ("num".equals(cond)) {
cart.setNum(name);
}
if ("price".equals(cond)) {
cart.setPrice(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.cartService.getCartByLike(cart), "cart", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querycart";
}
// 按主键查询数据
@RequestMapping("getCartById.action")
public String getCartById(String id) {
Cart cart = this.cartService.getCartById(id);
this.getRequest().setAttribute("cart", cart);
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
this.getRequest().setAttribute("jiancaiList", jiancaiList);
return "admin/editcart";
}
public CartService getCartService() {
return cartService;
}
public void setCartService(CartService cartService) {
this.cartService = cartService;
}
}
订单管理控制层:
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/orders" , produces = "text/plain;charset=utf-8")
public class OrdersAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private UsersService usersService;
// 准备添加数据
@RequestMapping("createOrders.action")
public String createOrders() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
return "admin/addorders";
}
// 添加数据
@RequestMapping("addOrders.action")
public String addOrders(Orders orders) {
this.ordersService.insertOrders(orders);
return "redirect:/orders/createOrders.action";
}
// 通过主键删除数据
@RequestMapping("deleteOrders.action")
public String deleteOrders(String id) {
this.ordersService.deleteOrders(id);
return "redirect:/orders/getAllOrders.action";
}
// 批量删除数据
@RequestMapping("deleteOrdersByIds.action")
public String deleteOrdersByIds() {
String[] ids = this.getRequest().getParameterValues("ordersid");
for (String ordersid : ids) {
this.ordersService.deleteOrders(ordersid);
}
return "redirect:/orders/getAllOrders.action";
}
// 更新数据
@RequestMapping("updateOrders.action")
public String updateOrders(Orders orders) {
this.ordersService.updateOrders(orders);
return "redirect:/orders/getAllOrders.action";
}
// 显示全部数据
@RequestMapping("getAllOrders.action")
public String getAllOrders(String number) {
List<Orders> ordersList = this.ordersService.getAllOrders();
PageHelper.getPage(ordersList, "orders", null, null, 10, number, this.getRequest(), null);
return "admin/listorders";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryOrdersByCond.action")
public String queryOrdersByCond(String cond, String name, String number) {
Orders orders = new Orders();
if(cond != null){
if ("ordercode".equals(cond)) {
orders.setOrdercode(name);
}
if ("username".equals(cond)) {
orders.setUsername(name);
}
if ("total".equals(cond)) {
orders.setTotal(name);
}
if ("status".equals(cond)) {
orders.setStatus(name);
}
if ("addtime".equals(cond)) {
orders.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.ordersService.getOrdersByLike(orders), "orders", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryorders";
}
// 按主键查询数据
@RequestMapping("getOrdersById.action")
public String getOrdersById(String id ) {
Orders orders = this.ordersService.getOrdersById(id);
this.getRequest().setAttribute("orders", orders);
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
return "admin/editorders";
}
public OrdersService getOrdersService() { return ordersService; }
public void setOrdersService(OrdersService ordersService) { this.ordersService = ordersService; }
}
源码获取:俺的博客首页 "资源" 里下载!