基于javaweb+mysql的ssm在线商城购物商城水果蔬菜批发商城(前台、后台)(java+javabean+mysql+jsp+ssm)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
后台管理:用户、新闻公告、果蔬类型、城市信息、配货点、果蔬商品、订单、评价等管理等
前台购物:注册登录、公告、商品、购买、评价等
idea:
eclipse/myeclipse:
前台购物:
后台管理:
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) MySQL Bootstrap JavaScript
基于javaweb+mysql的SSM在线商城购物商城水果蔬菜批发商城(前台、后台)(java+javabean+mysql+jsp+ssm)
}
if ("contents".equals(cond)) {
jiancai.setContents(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.jiancaiService.getJiancaiByLike(jiancai), "jiancai", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryjiancai";
}
// 按主键查询数据
@RequestMapping("getJiancaiById.action")
public String getJiancaiById(String id) {
Jiancai jiancai = this.jiancaiService.getJiancaiById(id);
this.getRequest().setAttribute("jiancai", jiancai);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/editjiancai";
}
public JiancaiService getJiancaiService() {
return jiancaiService;
}
public void setJiancaiService(JiancaiService jiancaiService) {
this.jiancaiService = jiancaiService;
}
}
if (password.equals(users.getPassword())) {
users.setPassword(repassword);
this.usersService.updateUsers(users);
} else {
this.getSession().setAttribute("message", "旧密码错误");
return "redirect:/index/prePwd.action";
}
return "redirect:/index/prePwd.action";
}
@RequestMapping("usercenter.action")
public String usercenter() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/usercenter";
}
@RequestMapping("userinfo.action")
public String userinfo() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
this.getSession().setAttribute("users", this.usersService.getUsersById(userid));
return "users/userinfo";
}
@RequestMapping("personal.action")
public String personal(Users users) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.usersService.updateUsers(users);
return "redirect:/index/userinfo.action";
}
// 添加产品到购物车
@RequestMapping("addcart.action")
flimList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
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/all.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 查询果蔬商品
@RequestMapping("query.action")
public String query(String name) {
this.front();
Jiancai goods = new Jiancai();
goods.setJiancainame(name);
List<Jiancai> flimList = this.jiancaiService.getJiancaiByLike(goods);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 果蔬商品详情
@RequestMapping("detail.action")
public String detail(String id) {
}
String userid = (String) this.getSession().getAttribute("userid");
Cart cart1 = new Cart();
cart1.setUsersid(userid);
List<Cart> cartList = this.cartService.getCartByCond(cart1);
if (cartList.size() == 0) {
this.getRequest().setAttribute("message", "请选购果蔬商品");
return "redirect:/index/cart.action";
} else {
// 获取一个1200-9999的随机数 防止同时提交
String ordercode = "PD" + VeDate.getStringDatex();
double total = 0;
for (Cart cart : cartList) {
Details details = new Details();
details.setDetailsid(VeDate.getStringDatex() + (Math.random() * 9 + 1) * 1200);
details.setJiancaiid(cart.getJiancaiid());
details.setNum(cart.getNum());
details.setOrdercode(ordercode);
details.setPrice(cart.getPrice());
details.setPeihuoid(this.getRequest().getParameter("peihuoid"));
details.setCityid(this.getRequest().getParameter("cityid"));
details.setViewdate(this.getRequest().getParameter("viewdate"));
this.detailsService.insertDetails(details);
Jiancai goods = this.jiancaiService.getJiancaiById(cart.getJiancaiid());
goods.setSellnum("" + (Integer.parseInt(goods.getSellnum()) + Integer.parseInt(cart.getNum())));
this.jiancaiService.updateJiancai(goods);
total += Double.parseDouble(cart.getPrice()) * Double.parseDouble(cart.getNum());
this.cartService.deleteCart(cart.getCartid());
}
Orders orders = new Orders();
orders.setAddtime(VeDate.getStringDateShort());
orders.setOrdercode(ordercode);
orders.setStatus("未付款");
orders.setTotal("" + total);
orders.setUsersid(userid);
this.ordersService.insertOrders(orders);
}
return "redirect:/index/showOrders.action";
}
// 查看订购
@RequestMapping("showOrders.action")
public String showOrders(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();
peihuo.setAddress(name);
}
if ("contact".equals(cond)) {
peihuo.setContact(name);
}
if ("memo".equals(cond)) {
peihuo.setMemo(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.peihuoService.getPeihuoByLike(peihuo), "peihuo", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querypeihuo";
}
// 按主键查询数据
@RequestMapping("getPeihuoById.action")
public String getPeihuoById(String id) {
Peihuo peihuo = this.peihuoService.getPeihuoById(id);
this.getRequest().setAttribute("peihuo", peihuo);
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
return "admin/editpeihuo";
}
public PeihuoService getPeihuoService() {
return peihuoService;
}
public void setPeihuoService(PeihuoService peihuoService) {
this.peihuoService = peihuoService;
}
}
this.getRequest().setAttribute("jiancaiList", jiancaiList);
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
List<Peihuo> peihuoList = this.peihuoService.getAllPeihuo();
this.getRequest().setAttribute("peihuoList", peihuoList);
return "admin/editdetails";
}
public DetailsService getDetailsService() {
return detailsService;
}
public void setDetailsService(DetailsService detailsService) {
this.detailsService = detailsService;
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/jiancai", produces = "text/plain;charset=utf-8")
public class JiancaiAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private JiancaiService jiancaiService;
@Autowired
@Resource
private CateService cateService;
// 准备添加数据
@RequestMapping("createJiancai.action")
public String createJiancai() {
List<Cate> cateList = this.cateService.getAllCate();
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 (password.equals(users.getPassword())) {
this.getSession().setAttribute("userid", users.getUsersid());
this.getSession().setAttribute("username", users.getUsername());
this.getSession().setAttribute("users", users);
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());
List<Users> usersList = this.usersService.getUsersByCond(u);
if (usersList.size() == 0) {
users.setRegdate(VeDate.getStringDateShort());
this.usersService.insertUsers(users);
} else {
this.getSession().setAttribute("message", "用户名已存在");
return "redirect:/index/preReg.action";
}
return "redirect:/index/preLogin.action";
}
// 退出登录
@RequestMapping("exit.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);
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 ("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");
// 通过主键删除数据
@RequestMapping("deleteJiancai.action")
public String deleteJiancai(String id) {
this.jiancaiService.deleteJiancai(id);
return "redirect:/jiancai/getAllJiancai.action";
}
// 批量删除数据
@RequestMapping("deleteJiancaiByIds.action")
public String deleteJiancaiByIds() {
String[] ids = this.getRequest().getParameterValues("jiancaiid");
for (String jiancaiid : ids) {
this.jiancaiService.deleteJiancai(jiancaiid);
}
return "redirect:/jiancai/getAllJiancai.action";
}
// 更新数据
@RequestMapping("updateJiancai.action")
public String updateJiancai(Jiancai jiancai) {
this.jiancaiService.updateJiancai(jiancai);
return "redirect:/jiancai/getAllJiancai.action";
}
// 显示全部数据
@RequestMapping("getAllJiancai.action")
public String getAllJiancai(String number) {
List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
PageHelper.getPage(jiancaiList, "jiancai", null, null, 10, number, this.getRequest(), null);
return "admin/listjiancai";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryJiancaiByCond.action")
public String queryJiancaiByCond(String cond, String name, String number) {
Jiancai jiancai = new Jiancai();
if (cond != null) {
if ("jiancainame".equals(cond)) {
jiancai.setJiancainame(name);
}
if ("image".equals(cond)) {
jiancai.setImage(name);
}
if ("cateid".equals(cond)) {
jiancai.setCatename(name);
}
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("ordersList", ordersList);
return "users/orderlist";
}
// 准备付款
@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);
return "users/pay";
}
// 付款
@RequestMapping("pay.action")
public String pay(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("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("getAllAdmin.action")
public String getAllAdmin(String number) {
List<Admin> adminList = this.adminService.getAllAdmin();
PageHelper.getPage(adminList, "admin", null, null, 10, number, this.getRequest(), null);
return "admin/listadmin";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryAdminByCond.action")
public String queryAdminByCond(String cond, String name, String number) {
Admin admin = new Admin();
if (cond != null) {
if ("username".equals(cond)) {
admin.setUsername(name);
}
if ("password".equals(cond)) {
admin.setPassword(name);
}
if ("realname".equals(cond)) {
admin.setRealname(name);
}
if ("contact".equals(cond)) {
admin.setContact(name);
}
if ("addtime".equals(cond)) {
admin.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.adminService.getAdminByLike(admin), "admin", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryadmin";
}
// 按主键查询数据
@RequestMapping("getAdminById.action")
public String getAdminById(String id) {
Admin admin = this.adminService.getAdminById(id);
this.getRequest().setAttribute("admin", admin);
return "admin/editadmin";
}
public AdminService getAdminService() {
return adminService;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
topic.setJiancainame(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();
this.getRequest().setAttribute("usersList", usersList);
List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
this.getRequest().setAttribute("jiancaiList", jiancaiList);
return "admin/edittopic";
}
public TopicService getTopicService() { return topicService; }
public void setTopicService(TopicService topicService) { this.topicService = topicService; }
}
@Resource
private CityService cityService;
@Autowired
@Resource
private PeihuoService peihuoService;
// 准备添加数据
@RequestMapping("createDetails.action")
public String createDetails() {
List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
this.getRequest().setAttribute("jiancaiList", jiancaiList);
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
List<Peihuo> peihuoList = this.peihuoService.getAllPeihuo();
this.getRequest().setAttribute("peihuoList", peihuoList);
return "admin/adddetails";
}
// 添加数据
@RequestMapping("addDetails.action")
public String addDetails(Details details) {
this.detailsService.insertDetails(details);
return "redirect:/details/createDetails.action";
}
// 通过主键删除数据
@RequestMapping("deleteDetails.action")
public String deleteDetails(String id) {
this.detailsService.deleteDetails(id);
return "redirect:/details/getAllDetails.action";
}
// 批量删除数据
@RequestMapping("deleteDetailsByIds.action")
public String deleteDetailsByIds() {
String[] ids = this.getRequest().getParameterValues("detailsid");
for (String detailsid : ids) {
this.detailsService.deleteDetails(detailsid);
}
return "redirect:/details/getAllDetails.action";
jiancai.setThestart(name);
}
if ("theend".equals(cond)) {
jiancai.setTheend(name);
}
if ("hits".equals(cond)) {
jiancai.setHits(name);
}
if ("sellnum".equals(cond)) {
jiancai.setSellnum(name);
}
if ("contents".equals(cond)) {
jiancai.setContents(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.jiancaiService.getJiancaiByLike(jiancai), "jiancai", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryjiancai";
}
// 按主键查询数据
@RequestMapping("getJiancaiById.action")
public String getJiancaiById(String id) {
Jiancai jiancai = this.jiancaiService.getJiancaiById(id);
this.getRequest().setAttribute("jiancai", jiancai);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/editjiancai";
}
public JiancaiService getJiancaiService() {
return jiancaiService;
}
public void setJiancaiService(JiancaiService jiancaiService) {
this.jiancaiService = jiancaiService;
}
}
public TopicService getTopicService() { return topicService; }
public void setTopicService(TopicService topicService) { this.topicService = topicService; }
}
//定义为控制器
@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();
public String queryArticleByCond(String cond, String name, String number) {
Article article = new Article();
if (cond != null) {
if ("title".equals(cond)) {
article.setTitle(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);
return "admin/editarticle";
}
public ArticleService getArticleService() {
return articleService;
}
public void setArticleService(ArticleService articleService) {
this.articleService = articleService;
}
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Orders o = tempList.get(i);
ordersList.add(o);
}
String html = "";
StringBuffer buffer = new StringBuffer();
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/showOrders.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("ordersList", ordersList);
@Resource
private PeihuoService peihuoService;
@Autowired
@Resource
private JiancaiService jiancaiService;
@Autowired
@Resource
private CartService cartService;
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private DetailsService detailsService;
@Autowired
@Resource
private TopicService topicService;
// 公共方法 提供公共查询数据
private void front() {
this.getRequest().setAttribute("title", "优品果蔬网-力作中国最大的果蔬网站");
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
List<Jiancai> hotList = this.jiancaiService.getJiancaiByHot();
Collections.shuffle(hotList);
this.getRequest().setAttribute("hotList", hotList);
}
// 首页显示
@RequestMapping("index.action")
public String index() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Jiancai> flimList = this.jiancaiService.getJiancaiByCate(cate.getCateid());
cate.setFlimList(flimList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/index";
}