基于javaweb+mysql的ssm在线共享洗衣机预约平台(java+ssm+jsp+mybatis+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM在线共享洗衣机预约平台(java+ssm+jsp+mybatis+mysql)
项目介绍
本项目分为前后台,前台为普通用户登录,后台为管理员登录; 管理员角色包含以下功能: 管理员登录,管理员信息管理,查看用户信息,新闻公告管理,类型信息管理,楼栋信息管理,楼层信息管理,洗衣机信息管理,查询订单信息,查看评价信息等功能。
用户角色包含以下功能: 查看首页,用户登录,查看商品详情,查看购物车,提交订单,查看我的订单,修改用户信息,修改密码等功能。
环境需要
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项目: 否; 6.数据库:MySql 5.7等版本均可;
技术栈
- 后端:Spring springmvc mybatis 2. 前端:JSP+css+javascript+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/ 登录 用户账号/密码: user/123456 管理员账号/密码:admin/admin
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();
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 (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")
HttpServletRequest request, ModelMap model) {
String path = request.getSession().getServletContext().getRealPath("/") + "upfiles/";
String fileName = file.getOriginalFilename();
int i = fileName.lastIndexOf(".");
String name = String.valueOf(VeDate.getStringDatex());
String type = fileName.substring(i + 1);
fileName = name + "." + type;
File targetFile = new File(path, fileName);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("imageFileName", fileName);
return "saveimage";
}
@RequestMapping(value = "/files.action")
public String files(@RequestParam(value = "image", required = false) MultipartFile file, HttpServletRequest request,
ModelMap model) {
String path = request.getSession().getServletContext().getRealPath("/") + "upfiles/";
String fileName = file.getOriginalFilename();
int i = fileName.lastIndexOf(".");
String name = String.valueOf(VeDate.getStringDatex());
String type = fileName.substring(i + 1);
fileName = name + "." + type;
File targetFile = new File(path, fileName);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("imageFileName", fileName);
return "savefile";
}
}
package com.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")
public String exit() {
this.front();
this.getSession().removeAttribute("userid");
this.getSession().removeAttribute("username");
this.getSession().removeAttribute("users");
return "index";
}
// 准备修改密码
@RequestMapping("prePwd.action")
public String prePwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/editpwd";
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/recommend.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 推荐产品
@RequestMapping("hot.action")
public String getHost(String number) {
this.front();
Jiancai goods = new Jiancai();
goods.setRecommend("是");
List<Jiancai> flimList = new ArrayList<Jiancai>();
List<Jiancai> tempList = this.jiancaiService.getJiancaiByHot();
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
return "redirect:/index/cart.action";
}
// 准备结算
@RequestMapping("preCheckout.action")
public String preCheckout() {
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);
if (cartList.size() == 0) {
this.getRequest().setAttribute("message", "请选购洗衣机");
return "redirect:/index/cart.action";
}
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
return "users/checkout";
}
// 结算
@RequestMapping("checkout.action")
public String checkout() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
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"));
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;
}
}
package com.action;
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; }
}
package com.action;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cart", produces = "text/plain;charset=utf-8")
public class CartAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private CartService cartService;
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);
}
if ("price".equals(cond)) {
jiancai.setPrice(name);
}
if ("recommend".equals(cond)) {
jiancai.setRecommend(name);
}
if ("thestart".equals(cond)) {
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);
public String network() {
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/network";
}
// 公告
@RequestMapping("article.action")
public String article(String number) {
this.front();
List<Article> articleList = new ArrayList<Article>();
List<Article> tempList = this.articleService.getAllArticle();
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Article x = tempList.get(i);
articleList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
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")
public String addcart() {
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.setJiancaiid(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);
}
}
package com.action;
//定义为控制器
@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.getSession().removeAttribute("realname");
return "admin/index";
}
// 准备添加数据
@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";
}
// 通过主键删除数据
@RequestMapping("deleteAdmin.action")
public String deleteAdmin(String id) {
this.adminService.deleteAdmin(id);
return "redirect:/admin/getAllAdmin.action";
}
// 批量删除数据
@RequestMapping("deleteAdminByIds.action")
public String deleteAdminByIds() {
String[] ids = this.getRequest().getParameterValues("adminid");
for (String adminid : ids) {
this.adminService.deleteAdmin(adminid);
}
return "redirect:/admin/getAllAdmin.action";
}
// 更新数据
@RequestMapping("updateAdmin.action")
public String updateAdmin(Admin admin) {
this.adminService.updateAdmin(admin);
return "redirect:/admin/getAllAdmin.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);
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)) {
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.detailsService.getDetailsByLike(details), "details", nameList, valueList, 10, number, this.getRequest(),
"query");
name = null;
cond = null;
return "admin/querydetails";
}
// 按主键查询数据
@RequestMapping("getDetailsById.action")
public String getDetailsById(String id) {
Details details = this.detailsService.getDetailsById(id);
this.getRequest().setAttribute("details", details);
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/editdetails";
}
public DetailsService getDetailsService() {
return detailsService;
}
public void setDetailsService(DetailsService detailsService) {
this.detailsService = detailsService;
}
}
package com.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; }
}
package com.action;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/article", produces = "text/plain;charset=utf-8")
public class ArticleAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private ArticleService articleService;
// 准备添加数据
@RequestMapping("createArticle.action")
public String createArticle() {
return "admin/addarticle";
name = null;
cond = null;
return "admin/querydetails";
}
// 按主键查询数据
@RequestMapping("getDetailsById.action")
public String getDetailsById(String id) {
Details details = this.detailsService.getDetailsById(id);
this.getRequest().setAttribute("details", details);
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/editdetails";
}
public DetailsService getDetailsService() {
return detailsService;
}
public void setDetailsService(DetailsService detailsService) {
this.detailsService = detailsService;
}
}
package com.action;
}
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();
orders.setUsersid(userid);
List<Orders> ordersList = new ArrayList<Orders>();
List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
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 ("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; }
}
package com.action;
//定义为控制器
@Controller
return "redirect:/index/preLogin.action";
}
Details details = new Details();
details.setOrdercode(id);
List<Details> detailsList = this.detailsService.getDetailsByCond(details);
this.getRequest().setAttribute("detailsList", detailsList);
return "users/orderdetail";
}
// 按分类查询
@RequestMapping("cate.action")
public String cate(String id, String number) {
this.front();
Jiancai goods = new Jiancai();
goods.setCateid(id);
List<Jiancai> flimList = new ArrayList<Jiancai>();
List<Jiancai> tempList = this.jiancaiService.getJiancaiByCond(goods);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Jiancai x = tempList.get(i);
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) {
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";
}
// 首页显示
@RequestMapping("network.action")
public String network() {
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/network";
}
this.usersService.insertUsers(users);
} else {
this.getSession().setAttribute("message", "用户名已存在");
return "redirect:/index/preReg.action";
}
return "redirect:/index/preLogin.action";
}
// 退出登录
@RequestMapping("exit.action")
public String exit() {
this.front();
this.getSession().removeAttribute("userid");
this.getSession().removeAttribute("username");
this.getSession().removeAttribute("users");
return "index";
}
// 准备修改密码
@RequestMapping("prePwd.action")
public String prePwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/editpwd";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Users users = this.usersService.getUsersById(userid);
if (password.equals(users.getPassword())) {
users.setPassword(repassword);
this.usersService.updateUsers(users);
} else {
this.getSession().setAttribute("message", "旧密码错误");
return "redirect:/index/prePwd.action";
public String deleteCity(String id) {
this.cityService.deleteCity(id);
return "redirect:/city/getAllCity.action";
}
// 批量删除数据
@RequestMapping("deleteCityByIds.action")
public String deleteCityByIds() {
String[] ids = this.getRequest().getParameterValues("cityid");
for (String cityid : ids) {
this.cityService.deleteCity(cityid);
}
return "redirect:/city/getAllCity.action";
}
// 更新数据
@RequestMapping("updateCity.action")
public String updateCity(City city) {
this.cityService.updateCity(city);
return "redirect:/city/getAllCity.action";
}
// 显示全部数据
@RequestMapping("getAllCity.action")
public String getAllCity(String number) {
List<City> cityList = this.cityService.getAllCity();
PageHelper.getPage(cityList, "city", null, null, 10, number, this.getRequest(), null);
return "admin/listcity";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryCityByCond.action")
public String queryCityByCond(String cond, String name, String number) {
City city = new City();
if (cond != null) {
if ("cityname".equals(cond)) {
city.setCityname(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
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();
orders.setUsersid(userid);
List<Orders> ordersList = new ArrayList<Orders>();
List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
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));
//定义为控制器
@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";
}
this.usersService.insertUsers(users);
} else {
this.getSession().setAttribute("message", "用户名已存在");
return "redirect:/index/preReg.action";
}
return "redirect:/index/preLogin.action";
}
// 退出登录
@RequestMapping("exit.action")
public String exit() {
this.front();
this.getSession().removeAttribute("userid");
this.getSession().removeAttribute("username");
this.getSession().removeAttribute("users");
return "index";
}
// 准备修改密码
@RequestMapping("prePwd.action")
public String prePwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/editpwd";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Users users = this.usersService.getUsersById(userid);
if (password.equals(users.getPassword())) {
users.setPassword(repassword);
this.usersService.updateUsers(users);
} else {
this.getSession().setAttribute("message", "旧密码错误");
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Jiancai x = tempList.get(i);
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/recommend.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {