基于javaweb+mysql的ssm水果商城管理系统(java+ssm+jsp+jquery+mysql)(平台、卖家、买家)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM水果商城管理系统(java+ssm+jsp+jquery+mysql)(平台、卖家、买家)
管理员(后台管理):
admin 123456
农户(即卖家,可以发布商品):
user1 123456
经销商(即买家,可以购买商品):
user2 123456
项目介绍
该系统主要分为前台和后台两大功能模块,共包含三个角色:农户、经销商和管理员。 具体的系统功能如下: 1.前台功能 前台首页、用户注册、用户登录、新闻公告、水果行情、查看水果、水果详情、加入购物车、加入收藏、购买水果、付款结算、添加评论、留言交流、个人中心、我的订单、我的收藏、意见反馈、发布水果、我的销售等功能。 2.后台功能 后台系统登陆、用户管理、管理员管理、网站内容管理、水果类型管理、水果信息管理、采购订单管理、用户评价管理、意见反馈管理、留言交流管理等功能。
环境需要
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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目; 6.数据库:MySql 5.7/8.0等版本均可;
技术栈
后台框架:Spring、SpringMVC、MyBatis UI界面:JSP、jQuery 数据库:MySQL
使用说明
-
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
-
使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
return "redirect:/fav/getAllFav.action";
}
// 更新数据
@RequestMapping("updateFav.action")
public String updateFav(Fav fav) {
this.favService.updateFav(fav);
return "redirect:/fav/getAllFav.action";
}
// 显示全部数据
@RequestMapping("getAllFav.action")
public String getAllFav(String number) {
List<Fav> favList = this.favService.getAllFav();
PageHelper.getPage(favList, "fav", null, null, 10, number, this.getRequest(), null);
return "admin/listfav";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryFavByCond.action")
public String queryFavByCond(String cond, String name, String number) {
Fav fav = new Fav();
if(cond != null){
if ("usersid".equals(cond)) {
fav.setUsersid(name);
}
if ("goodsid".equals(cond)) {
fav.setGoodsid(name);
}
if ("addtime".equals(cond)) {
fav.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.favService.getFavByLike(fav), "fav", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
String userid = (String) this.getSession().getAttribute("userid");
Orders orders = new Orders();
orders.setUsersid(userid);
List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
PageHelper.getIndexPage(tempList, "orders", "showOrders", null, 10, number, this.getRequest());
return "users/orderlist";
}
@RequestMapping("mySell.action")
public String mySell(String number) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Orders orders = new Orders();
orders.setSellerid(userid);
List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
PageHelper.getIndexPage(tempList, "orders", "mySell", null, 10, number, this.getRequest());
return "users/sorderlist";
}
@RequestMapping("send.action")
public String send(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
orders.setStatus("已发货");
this.ordersService.updateOrders(orders);
return "redirect:/index/mySell.action";
}
// 准备付款
@RequestMapping("prePay.action")
public String prePay(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.getRequest().setAttribute("id", id);
Orders orders = this.ordersService.getOrdersById(id);
this.getRequest().setAttribute("orders", orders);
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
private AdminService adminService;
// 管理员准备
@RequestMapping("index.action")
public String index() {
return "admin/index";
}
// 管理员登录 1 验证用户名是否存在 2 验证密码是否正确
@RequestMapping("login.action")
public String login() {
String username = this.getRequest().getParameter("username");
String password = this.getRequest().getParameter("password");
Admin adminEntity = new Admin();
adminEntity.setUsername(username);
List<Admin> adminlist = this.adminService.getAdminByCond(adminEntity);
if (adminlist.size() == 0) {
this.getRequest().setAttribute("message", "用户名不存在");
return "redirect:/admin/index.action";
} else {
Admin admin = adminlist.get(0);
if (password.equals(admin.getPassword())) {
this.getSession().setAttribute("adminid", admin.getAdminid());
this.getSession().setAttribute("adminname", admin.getUsername());
this.getSession().setAttribute("realname", admin.getRealname());
} else {
this.getRequest().setAttribute("message", "密码错误");
return "redirect:/admin/index.action";
}
}
return "admin/main";
}
// 管理员准备修改密码
@RequestMapping("prePwd.action")
public String prePwd() {
return "admin/editpwd";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
String adminid = (String) this.getSession().getAttribute("adminid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Admin admin = this.adminService.getAdminById(adminid);
if (password.equals(admin.getPassword())) {
admin.setPassword(repassword);
this.adminService.updateAdmin(admin);
} else {
this.getRequest().setAttribute("message", "旧密码错误");
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";
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/article" , produces = "text/plain;charset=utf-8")
public class ArticleController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
private ArticleService articleService;
@Autowired
private BannerService bannerService;
// 准备添加数据
@RequestMapping("createArticle.action")
public String createArticle() {
List<Banner> bannerList = this.bannerService.getAllBanner();
this.getRequest().setAttribute("bannerList", bannerList);
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Cart cart = new Cart();
cart.setAddtime(VeDate.getStringDateShort());
cart.setGoodsid(getRequest().getParameter("goodsid"));
cart.setNum(getRequest().getParameter("num"));
cart.setPrice(getRequest().getParameter("price"));
cart.setUsersid(userid);
this.cartService.insertCart(cart);
return "redirect:/index/cart.action";
}
// 查看购物车
@RequestMapping("cart.action")
public String cart() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Cart cart = new Cart();
cart.setUsersid(userid);
List<Cart> cartList = this.cartService.getCartByCond(cart);
this.getRequest().setAttribute("cartList", cartList);
return "users/cart";
}
// 删除购物车中的产品
@RequestMapping("deletecart.action")
public String deletecart(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.cartService.deleteCart(id);
return "redirect:/index/cart.action";
}
// 结算
@RequestMapping("checkout.action")
public String checkout() {
this.front();
this.favService.deleteFav(id);
return "redirect:/fav/getAllFav.action";
}
// 批量删除数据
@RequestMapping("deleteFavByIds.action")
public String deleteFavByIds() {
String[] ids = this.getRequest().getParameterValues("favid");
for (String favid : ids) {
this.favService.deleteFav(favid);
}
return "redirect:/fav/getAllFav.action";
}
// 更新数据
@RequestMapping("updateFav.action")
public String updateFav(Fav fav) {
this.favService.updateFav(fav);
return "redirect:/fav/getAllFav.action";
}
// 显示全部数据
@RequestMapping("getAllFav.action")
public String getAllFav(String number) {
List<Fav> favList = this.favService.getAllFav();
PageHelper.getPage(favList, "fav", null, null, 10, number, this.getRequest(), null);
return "admin/listfav";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryFavByCond.action")
public String queryFavByCond(String cond, String name, String number) {
Fav fav = new Fav();
if(cond != null){
if ("usersid".equals(cond)) {
fav.setUsersid(name);
}
if ("goodsid".equals(cond)) {
fav.setGoodsid(name);
}
if ("addtime".equals(cond)) {
fav.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
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);
List<Goods> goodsList = this.goodsService.getAllGoods();
this.getRequest().setAttribute("goodsList", goodsList);
return "admin/editorders";
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/goods" , produces = "text/plain;charset=utf-8")
public class GoodsController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
number = "0";
}
int start = Integer.parseInt(number) * pageSize;
int over = (Integer.parseInt(number) + 1) * pageSize;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Object obj = list.get(i);
objList.add(obj);
}
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"" + name + "/" + action + "?number=0" + path + "\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"" + name + "/" + action + "?number=" + (Integer.parseInt(number) - 1) + "" + path + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"" + name + "/" + action + "?number=" + (Integer.parseInt(number) + 1) + "" + path + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"" + name + "/" + action + "?number=" + (maxPage - 1) + "" + path + "\">尾页</a>");
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/goods" , produces = "text/plain;charset=utf-8")
public class GoodsController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
private GoodsService goodsService;
@Autowired
private UsersService usersService;
@Autowired
private CateService cateService;
// 准备添加数据
@RequestMapping("createGoods.action")
public String createGoods() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/addgoods";
}
// 添加数据
@RequestMapping("addGoods.action")
public String addGoods(Goods goods) {
goods.setAddtime(VeDate.getStringDateShort());
goods.setHits("0");
goods.setSellnum("0");
this.goodsService.insertGoods(goods);
return "redirect:/goods/createGoods.action";
}
// 通过主键删除数据
@RequestMapping("deleteGoods.action")
public String deleteGoods(String id) {
this.goodsService.deleteGoods(id);
return "redirect:/goods/getAllGoods.action";
}
bbs.setContents(name);
}
if ("addtime".equals(cond)) {
bbs.setAddtime(name);
}
if ("hits".equals(cond)) {
bbs.setHits(name);
}
if ("repnum".equals(cond)) {
bbs.setRepnum(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.bbsService.getBbsByLike(bbs), "bbs", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querybbs";
}
// 按主键查询数据
@RequestMapping("getBbsById.action")
public String getBbsById(String id) {
Bbs bbs = this.bbsService.getBbsById(id);
this.getRequest().setAttribute("bbs", bbs);
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
return "admin/editbbs";
}
}
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
orders.setStatus("已付款");
this.ordersService.updateOrders(orders);
return "redirect:/index/showOrders.action";
}
// 确认收货
@RequestMapping("over.action")
public String over(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
orders.setStatus("已收货");
this.ordersService.updateOrders(orders);
return "redirect:/index/showOrders.action";
}
// 取消订单
@RequestMapping("cancel.action")
public String cancel(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
orders.setStatus("已取消");
this.ordersService.updateOrders(orders);
return "redirect:/index/showOrders.action";
}
// 按分类查询
@RequestMapping("cate.action")
public String cate(String id, String number) {
this.front();
Goods goods = new Goods();
goods.setCateid(id);
List<Goods> tempList = this.goodsService.getGoodsByCond(goods);
//定义为控制器
@Controller
// 设置路径
@RequestMapping("/index")
public class IndexController extends BaseController {
@Autowired
private UsersService usersService;
@Autowired
private BannerService bannerService;
@Autowired
private ArticleService articleService;
@Autowired
private CateService cateService;
@Autowired
private GoodsService goodsService;
@Autowired
private CartService cartService;
@Autowired
private FavService favService;
@Autowired
private OrdersService ordersService;
@Autowired
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/chart", produces = "text/plain;charset=utf-8")
public class ChartController extends BaseController {
@Autowired
private OrdersService ordersService;
@Autowired
private TopicService topicService;
@RequestMapping("chartline.action")
@ResponseBody
public String chartline() throws JSONException {
String start = this.getRequest().getParameter("start");
String end = this.getRequest().getParameter("end");
long days = VeDate.getDays(end, start) + 1;
JSONArray total = new JSONArray();
JSONArray count = new JSONArray();// 定义count存放数值
JSONArray day = new JSONArray(); // 存放名称
for (int i = 0; i < days; i++) {
String nxtDay = VeDate.getNextDay(start, "" + i);
System.out.println(nxtDay);
Orders orders = new Orders();
orders.setAddtime(nxtDay);
List<Orders> list = this.ordersService.getOrdersByCond(orders);
double sellTotal = 0;
double sellCount = 0;
for (Orders x : list) {
sellTotal += Double.parseDouble(x.getTotal());
}
sellCount = list.size();
total.put(VeDate.getDouble(sellTotal));
count.put(sellCount);
day.put(nxtDay);
}
JSONArray cate = new JSONArray();
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cart" , produces = "text/plain;charset=utf-8")
public class CartController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
private CartService cartService;
@Autowired
private UsersService usersService;
@Autowired
private GoodsService goodsService;
// 准备添加数据
@RequestMapping("createCart.action")
public String createCart() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Goods> goodsList = this.goodsService.getAllGoods();
this.getRequest().setAttribute("goodsList", goodsList);
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);
}
}
String userid = (String) this.getSession().getAttribute("userid");
Fav fav = new Fav();
fav.setUsersid(userid);
List<Fav> favList = this.favService.getFavByCond(fav);
PageHelper.getIndexPage(favList, "fav", "myfav", null, 10, number, this.getRequest());
return "users/myfav";
}
// 删除收藏
@RequestMapping("deletefav.action")
public String deletefav() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.favService.deleteFav(this.getRequest().getParameter("id"));
return "redirect:/index/myfav.action";
}
@RequestMapping("preComplains.action")
public String preComplains() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/addComplains";
}
@RequestMapping("addComplains.action")
public String addComplains(Complains complains) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
complains.setAddtime(VeDate.getStringDateShort());
complains.setStatus("未回复");
complains.setUsersid(userid);
this.complainsService.insertComplains(complains);
return "redirect:/index/preComplains.action";
}
@RequestMapping("myComplains.action")
public String myComplains(String number) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
Complains complains = new Complains();
complains.setUsersid(userid);
List<Complains> complainsList = this.complainsService.getComplainsByCond(complains);
PageHelper.getIndexPage(complainsList, "complains", "myComplains", null, 10, number, this.getRequest());
List<Bbs> bbsList = this.bbsService.getAllBbs();
this.getRequest().setAttribute("bbsList", bbsList);
return "admin/editrebbs";
}
}
public class RandomValidateCode {
public static final String RANDOMCODEKEY = "RANDOMVALIDATECODEKEY";// 放到session中的key
// private String randString = "0123456789";//随机产生只有数字的字符串 private String
private String randString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";// 随机产生只有字母的字符串
// private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生数字与字母组合的字符串
private int width = 95;// 图片宽
private int height = 25;// 图片高
private int lineSize = 40;// 干扰线数量
private int stringNum = 4;// 随机产生字符数量
private Random random = new Random();
/*
* 获得字体
*/
private Font getFont() {
return new Font("Fixedsys", Font.CENTER_BASELINE, 18);
}
/*
* 获得颜色
*/
private Color getRandColor(int fc, int bc) {
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/bbs" , produces = "text/plain;charset=utf-8")
public class BbsController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
private BbsService bbsService;
@Autowired
private UsersService usersService;
// 准备添加数据
@RequestMapping("createBbs.action")
public String createBbs() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
return "admin/addbbs";
}
// 添加数据
@RequestMapping("addBbs.action")
public String addBbs(Bbs bbs) {
this.bbsService.insertBbs(bbs);
return "redirect:/bbs/createBbs.action";
}
// 通过主键删除数据
@RequestMapping("deleteBbs.action")
public String deleteBbs(String id) {
this.bbsService.deleteBbs(id);
return "redirect:/bbs/getAllBbs.action";
}
// 批量删除数据
@RequestMapping("deleteBbsByIds.action")
public String deleteBbsByIds() {
String[] ids = this.getRequest().getParameterValues("bbsid");
for (String bbsid : ids) {
this.bbsService.deleteBbs(bbsid);
}
return "redirect:/bbs/getAllBbs.action";
}
// 更新数据