基于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
卖家
saler1 123456
买家
buyer1 123456
SSM的茶叶商城网站
#项目介绍
该系统主要分为前台和后台两大功能模块,共包含三个角色:卖家、买家和管理员。
具体的系统功能如下:
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.数据库:MySql 5.7/8.0等版本均可;
#技术栈
后台框架:Spring、SpringMVC、MyBatis
UI界面:JSP、jQuery
数据库:MySQL
}
// 更新数据
@RequestMapping("updateOrders.action")
public String updateOrders(Orders orders) {
this.ordersService.updateOrders(orders);
return "redirect:/orders/getAllOrders.action";
}
// 更新状态
@RequestMapping("status.action")
public String status(String id) {
String status = "";
Orders orders = this.ordersService.getOrdersById(id);
if (status.equals(orders.getStatus())) {
status = "";
}
orders.setStatus(status);
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 ("usersid".equals(cond)) {
orders.setUsersid(name);
}
if ("storage".equals(cond)) {
goods.setStorage(name);
}
if ("addtime".equals(cond)) {
goods.setAddtime(name);
}
if ("hits".equals(cond)) {
goods.setHits(name);
}
if ("sellnum".equals(cond)) {
goods.setSellnum(name);
}
if ("contents".equals(cond)) {
goods.setContents(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.goodsService.getGoodsByLike(goods), "goods", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querygoods";
}
// 按主键查询数据
@RequestMapping("getGoodsById.action")
public String getGoodsById(String id) {
Goods goods = this.goodsService.getGoodsById(id);
this.getRequest().setAttribute("goods", goods);
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/editgoods";
}
}
// 管理员准备修改密码
@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", "旧密码错误");
}
return "redirect:/admin/prePwd.action";
}
// 管理员退出登录
@RequestMapping("exit.action")
public String exit() {
this.getSession().removeAttribute("adminid");
this.getSession().removeAttribute("adminname");
this.getSession().removeAttribute("realname");
return "redirect:/admin/index.action";
}
// 准备添加数据
@RequestMapping("createAdmin.action")
public String createAdmin() {
return "admin/addadmin";
}
// 添加数据
@RequestMapping("addAdmin.action")
public String addAdmin(Admin admin) {
admin.setAddtime(VeDate.getStringDateShort());
this.adminService.insertAdmin(admin);
return "redirect:/admin/createAdmin.action";
// 注入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);
return "admin/addarticle";
}
// 添加数据
@RequestMapping("addArticle.action")
public String addArticle(Article article) {
article.setAddtime(VeDate.getStringDateShort());
article.setHits("0");
this.articleService.insertArticle(article);
return "redirect:/article/createArticle.action";
}
// 通过主键删除数据
@RequestMapping("deleteArticle.action")
public String deleteArticle(String id) {
this.articleService.deleteArticle(id);
return "redirect:/article/getAllArticle.action";
}
// 批量删除数据
@RequestMapping("deleteArticleByIds.action")
public String deleteArticleByIds() {
String[] ids = this.getRequest().getParameterValues("articleid");
for (String articleid : ids) {
this.articleService.deleteArticle(articleid);
}
return "redirect:/article/getAllArticle.action";
}
// 更新数据
@RequestMapping("updateArticle.action")
public String updateArticle(Article article) {
this.articleService.updateArticle(article);
return "redirect:/article/getAllArticle.action";
}
// 显示全部数据
@RequestMapping("getAllArticle.action")
public String getAllArticle(String number) {
List<Article> articleList = this.articleService.getAllArticle();
PageHelper.getPage(articleList, "article", null, null, 10, number, this.getRequest(), null);
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;
cond = null;
return "admin/queryfav";
}
// 按主键查询数据
@RequestMapping("getFavById.action")
public String getFavById(String id) {
Fav fav = this.favService.getFavById(id);
this.getRequest().setAttribute("fav", fav);
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Goods> goodsList = this.goodsService.getAllGoods();
this.getRequest().setAttribute("goodsList", goodsList);
return "admin/editfav";
}
}
//定义为控制器
@Controller
// 设置路径
return "users/read";
}
// 准备登录
@RequestMapping("preLogin.action")
public String prelogin() {
this.front();
return "users/login";
}
// 用户登录
@RequestMapping("login.action")
public String login() {
this.front();
String username = this.getRequest().getParameter("username");
String password = this.getRequest().getParameter("password");
Users u = new Users();
u.setUsername(username);
List<Users> usersList = this.usersService.getUsersByCond(u);
if (usersList.size() == 0) {
this.getSession().setAttribute("message", "用户名不存在");
return "redirect:/index/preLogin.action";
} else {
Users users = usersList.get(0);
if ("锁定".equals(users.getStatus())) {
this.getSession().setAttribute("message", "账户被锁定");
return "redirect:/index/preLogin.action";
}
if (password.equals(users.getPassword())) {
this.getSession().setAttribute("userid", users.getUsersid());
this.getSession().setAttribute("username", users.getUsername());
this.getSession().setAttribute("users", users);
this.getSession().setAttribute("role", users.getRole());
return "redirect:/index/index.action";
} else {
this.getSession().setAttribute("message", "密码错误");
return "redirect:/index/preLogin.action";
}
}
}
// 准备注册
@RequestMapping("preReg.action")
public String preReg() {
this.front();
return "users/register";
}
// 用户注册
@RequestMapping("register.action")
public String register(Users users) {
this.front();
Users u = new Users();
u.setUsername(users.getUsername());
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=\"index/" + action + "?number=0" + path + "\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/" + action + "?number=" + (Integer.parseInt(number) - 1) + "" + path + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/" + action + "?number=" + (Integer.parseInt(number) + 1) + "" + path + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/" + action + "?number=" + (maxPage - 1) + "" + path + "\">尾页</a>");
}
String html = buffer.toString();
request.setAttribute("html", html);
request.setAttribute(name + "List", objList);
}
}
//定义为控制器
@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";
}
// 批量删除数据
@RequestMapping("deleteGoodsByIds.action")
public String deleteGoodsByIds() {
String[] ids = this.getRequest().getParameterValues("goodsid");
for (String goodsid : ids) {
// 显示全部数据
@RequestMapping("getAllArticle.action")
public String getAllArticle(String number) {
List<Article> articleList = this.articleService.getAllArticle();
PageHelper.getPage(articleList, "article", null, null, 10, number, this.getRequest(), null);
return "admin/listarticle";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryArticleByCond.action")
public String queryArticleByCond(String cond, String name, String number) {
Article article = new Article();
if(cond != null){
if ("title".equals(cond)) {
article.setTitle(name);
}
if ("bannerid".equals(cond)) {
article.setBannerid(name);
}
if ("image".equals(cond)) {
article.setImage(name);
}
if ("contents".equals(cond)) {
article.setContents(name);
}
if ("addtime".equals(cond)) {
article.setAddtime(name);
}
if ("hits".equals(cond)) {
article.setHits(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.articleService.getArticleByLike(article), "article", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryarticle";
}
// 按主键查询数据
@RequestMapping("getArticleById.action")
public String getArticleById(String id) {
Article article = this.articleService.getArticleById(id);
this.getRequest().setAttribute("article", article);
List<Banner> bannerList = this.bannerService.getAllBanner();
this.getRequest().setAttribute("bannerList", bannerList);
return "admin/editarticle";
}
maxPage = maxPage / pageSize;
} else {
maxPage = maxPage / pageSize + 1;
}
if (number == null) {
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>");
}
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";
}
}
this.topicService.updateTopic(topic);
return "redirect:/topic/getAllTopic.action";
}
// 显示全部数据
@RequestMapping("getAllTopic.action")
public String getAllTopic(String number) {
List<Topic> topicList = this.topicService.getAllTopic();
PageHelper.getPage(topicList, "topic", null, null, 10, number, this.getRequest(), null);
return "admin/listtopic";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryTopicByCond.action")
public String queryTopicByCond(String cond, String name, String number) {
Topic topic = new Topic();
if(cond != null){
if ("usersid".equals(cond)) {
topic.setUsersid(name);
}
if ("ordersid".equals(cond)) {
topic.setOrdersid(name);
}
if ("goodsid".equals(cond)) {
topic.setGoodsid(name);
}
if ("num".equals(cond)) {
topic.setNum(name);
}
if ("contents".equals(cond)) {
topic.setContents(name);
}
if ("addtime".equals(cond)) {
topic.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.topicService.getTopicByLike(topic), "topic", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querytopic";
}
// 按主键查询数据
@RequestMapping("getTopicById.action")
public String getTopicById(String id) {
Topic topic = this.topicService.getTopicById(id);
this.getRequest().setAttribute("topic", topic);
List<Users> usersList = this.usersService.getAllUsers();
}
// 添加数据
@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";
}
// 更新数据
@RequestMapping("updateBbs.action")
public String updateBbs(Bbs bbs) {
this.bbsService.updateBbs(bbs);
return "redirect:/bbs/getAllBbs.action";
}
// 显示全部数据
@RequestMapping("getAllBbs.action")
public String getAllBbs(String number) {
List<Bbs> bbsList = this.bbsService.getAllBbs();
PageHelper.getPage(bbsList, "bbs", null, null, 10, number, this.getRequest(), null);
return "admin/listbbs";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryBbsByCond.action")
public String queryBbsByCond(String cond, String name, String number) {
Bbs bbs = new Bbs();
if(cond != null){
if ("usersid".equals(cond)) {
bbs.setUsersid(name);
}
if ("title".equals(cond)) {
bbs.setTitle(name);
}
@RequestMapping("preEdit.action")
public String preEdit(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Goods goods = this.goodsService.getGoodsById(id);
this.getRequest().setAttribute("goods", goods);
return "users/editGoods";
}
@RequestMapping("updateGoods.action")
public String updateGoods(Goods goods) {
this.goodsService.updateGoods(goods);
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "redirect:/index/myGoods.action";
}
@RequestMapping("deleteGoods.action")
public String deleteGoods(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.goodsService.deleteGoods(id);
return "redirect:/index/myGoods.action";
}
@RequestMapping("preTopic.action")
public String preTopic(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
Orders orders = this.ordersService.getOrdersById(id);
this.getRequest().setAttribute("id", id);
this.getRequest().setAttribute("orders", orders);
return "users/addTopic";
}
JSONObject json = new JSONObject();
json.put("sellTotal", total.toString());
json.put("days", day.toString().replaceAll("\"", ""));
json.put("cate", cate.toString().replaceAll("\"", ""));
System.out.println(json.toString());
return json.toString();
}
@RequestMapping("chartPie.action")
@ResponseBody
public String chartPie() throws JSONException {
JSONArray names = new JSONArray();
JSONArray count = new JSONArray();// 定义count存放数值
int stars1 = 0;
int stars2 = 0;
int stars3 = 0;
int stars4 = 0;
int stars5 = 0;
names.put("非常满意");
names.put("满意");
names.put("一般");
names.put("不满意");
names.put("非常不满意");
List<Topic> topicList = this.topicService.getAllTopic();
for (Topic topic : topicList) {
if ("1".equals(topic.getNum())) {
stars1++;
}
if ("2".equals(topic.getNum())) {
stars2++;
}
if ("3".equals(topic.getNum())) {
stars3++;
}
if ("4".equals(topic.getNum())) {
stars4++;
}
if ("5".equals(topic.getNum())) {
stars5++;
}
}
count.put(stars5);
count.put(stars4);
count.put(stars3);
count.put(stars2);
count.put(stars1);
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";
}
}
//定义为控制器
@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")
public String index() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Goods> goodsList = this.goodsService.getGoodsByCate(cate.getCateid());
cate.setGoodsList(goodsList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/index";
}
// 新闻公告
@RequestMapping("article.action")
public String article(String id, String number) {
this.front();
Article article = new Article();
article.setBannerid(id);
List<Article> articleList = this.articleService.getArticleByCond(article);
PageHelper.getIndexPage(articleList, "article", "article", id, 10, number, this.getRequest());
Banner banner = this.bannerService.getBannerById(id);
this.getRequest().setAttribute("banner", banner);
return "users/article";
}
// 阅读公告
@RequestMapping("read.action")
public String read(String id) {
this.front();
Article article = this.articleService.getArticleById(id);
article.setHits("" + (Integer.parseInt(article.getHits()) + 1));
this.articleService.updateArticle(article);
this.getRequest().setAttribute("article", article);
return "users/read";
}
// 准备登录
@RequestMapping("preLogin.action")
public String prelogin() {
this.front();
return "users/login";
}
// 用户登录
@RequestMapping("login.action")
public String login() {
this.front();
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);
return "users/pay";
}
// 付款
@RequestMapping("pay.action")