基于javaweb+mysql的springboot家政服务网站系统设计和实现(java+springboot+ssm+mysql+jsp+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot家政服务网站系统设计和实现(java+springboot+ssm+mysql+jsp+maven)
一、项目简述
本系统主要实现的功能有: 项目功能较多,包括用户的注册登录,家政0员务的查看, 分类,预订,以及支付,订单信息的查看,后台管理员的 人员管理,服务类别管理,订单分配,数据统计,家政维 护等等功能。
二、项目运行
1运行环境:
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven
}
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")
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;
}
}
// 按条件查询数据 (模糊查询)
@RequestMapping("/queryTopicByCond")
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);
}
if ("status".equals(cond)) {
topic.setStatus(name);
}
if ("reps".equals(cond)) {
topic.setReps(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")
return "users/userinfo";
}
@RequestMapping("/personal")
public String personal(Users users) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
this.usersService.updateUsers(users);
return "redirect:/index/userinfo";
}
// 添加产品到购物车
@RequestMapping("/addcart")
public String addcart() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
String userid = (String) this.getSession().getAttribute("userid");
Users users=usersService.getUsersById(userid);
Goods goods=goodsService.find(getRequest().getParameter("goodsid"));
Cart cart = new Cart();
cart.setAddtime(VeDate.getStringDateShort());
cart.setGoodsid(getRequest().getParameter("goodsid"));
cart.setPrice(getRequest().getParameter("price"));
cart.setUsersid(userid);
cart.setImage(goods.getImage());
cart.setUsername(goods.getGoodsname());
cart.setUsername(users.getUsername());
this.cartService.insertCart(cart);
return "redirect:/index/cart";
}
// 查看购物车
@RequestMapping("/cart")
public String cart() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
String userid = (String) this.getSession().getAttribute("userid");
name = null;
cond = null;
return "admin/queryemploy";
}
// 按主键查询数据
@RequestMapping("/getEmployById")
public String getEmployById(String id) {
Employ employ = this.employService.getEmployById(id);
this.getRequest().setAttribute("employ", employ);
return "admin/editemploy";
}
public EmployService getEmployService() {
return employService;
}
public void setEmployService(EmployService employService) {
this.employService = employService;
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/article", produces = "text/plain;charset=utf-8")
public class ArticleController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private ArticleService articleService;
this.getRequest().setAttribute("topicList", topicList);
return "users/myTopic";
}
// 订单明细
@RequestMapping("/orderdetail")
public String orderdetail(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
Items details = new Items();
details.setOrdercode(id);
List<Items> detailsList = this.itemsService.getItemsByCond(details);
this.getRequest().setAttribute("detailsList", detailsList);
return "users/orderdetail";
}
// 按分类查询
@RequestMapping("/cate")
public String cate(String id, String number) {
this.front();
Goods goods = new Goods();
goods.setCateid(id);
List<Goods> goodsList = new ArrayList<Goods>();
List<Goods> tempList = this.goodsService.getGoodsByCond(goods);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 4 == 0) {
maxPage = maxPage / 4;
} else {
maxPage = maxPage / 4 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 4;
int over = (Integer.parseInt(number) + 1) * 4;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
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>");
}
String html = buffer.toString();
request.setAttribute("html", html);
request.setAttribute(name + "List", objList);
}
public static void getIndexPage(List<?> list, String name, String actionName, int pageSize, String number, HttpServletRequest request) {
StringBuffer buffer = new StringBuffer();
String path = "";
String action = actionName + "";
List<Object> objList = new ArrayList<Object>();
int pageNumber = list.size();
int maxPage = pageNumber;
if (maxPage % pageSize == 0) {
maxPage = maxPage / pageSize;
} else {
maxPage = maxPage / pageSize + 1;
}
if (number == null) {
number = "0";
String action = "getAll" + name2 + "";
if (method != null) {
action = "query" + name2 + "ByCond";
}
List<Object> objList = new ArrayList<Object>();
if (nameList != null && valueList != null) {
for (int i = 0; i < nameList.size(); i++) {
path += "&" + nameList.get(i) + "=" + valueList.get(i);
}
}
int pageNumber = list.size();
int maxPage = pageNumber;
if (maxPage % pageSize == 0) {
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>");
}
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.interceptor;
//
//
//
//@Component
//public class LoginInterceptor implements HandlerInterceptor {
// @Autowired
// private UsersService usersService;
// @Override
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// HttpSession session = request.getSession();
// String userid= (String) session.getAttribute("userid");
// Users user=usersService.getUsersById(userid);
// System.out.println(user);
// if (user==null){
// return false;
return "redirect:/index/preLogin";
}
String oid=getRequest().getParameter("id");
Orders orders = this.ordersService.getOrdersById(oid);
orders.setStatus("已付款");
this.ordersService.updateOrders(orders);
return "redirect:/index/showOrders";
}
// 确认收货
@RequestMapping("/preTopic")
public String preTopic(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
Items items = new Items();
items.setOrdercode(orders.getOrdercode());
List<Items> itemsList = this.itemsService.getItemsByCond(items);
this.getRequest().setAttribute("detailsList", itemsList);
this.getRequest().setAttribute("orders", orders);
return "users/addTopic";
}
// 取消订单
@RequestMapping("/addTopic")
public String addTopic() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
Orders orders = this.ordersService.getOrdersById(this.getRequest().getParameter("id"));
orders.setStatus("已评价");
this.ordersService.updateOrders(orders);
Items items = new Items();
items.setOrdercode(orders.getOrdercode());
List<Items> itemsList = this.itemsService.getItemsByCond(items);
String userid = (String) this.getSession().getAttribute("userid");
for (int i = 0; i < itemsList.size(); i++) {
Items x = itemsList.get(i);
Topic topic = new Topic();
topic.setTopicid(UUID.randomUUID().toString());
topic.setGoodsid(x.getGoodsid());
topic.setContents(this.getRequest().getParameter("contents_" + i));
topic.setNum(this.getRequest().getParameter("num_" + i));
JSONArray count = new JSONArray();
JSONArray name = new JSONArray(); // 存放名称
List<Goods> goodsList = this.goodsService.getAllGoods();
for (Goods goods : goodsList) {
name.put(goods.getGoodsname());
count.put(Integer.parseInt(goods.getSellnum()));
}
JSONObject json = new JSONObject();
json.put("count", count.toString());
json.put("names", name.toString().replaceAll("\"", ""));
return json.toString();
}
@RequestMapping("/chartBar")
@ResponseBody
public String chartBar() throws JSONException {
JSONArray name = new JSONArray();
JSONArray count = new JSONArray();
List<Cate> cateList = this.cateService.getAllCate();
for (Cate cate : cateList) {
name.put(cate.getCatename());
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
int sum4 = 0;
int sum5 = 0;
Topic t = new Topic();
t.setCateid(cate.getCateid());
List<Topic> list = this.topicService.getTopicBar(t);
for (Topic x : list) {
if (Integer.parseInt(x.getNum()) == 1) {
sum1++;
}
if (Integer.parseInt(x.getNum()) == 2) {
sum2++;
}
if (Integer.parseInt(x.getNum()) == 3) {
sum3++;
}
if (Integer.parseInt(x.getNum()) == 4) {
sum4++;
}
if (Integer.parseInt(x.getNum()) == 5) {
sum5++;
}
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";
} 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";
} else {
this.getSession().setAttribute("message", "密码错误");
return "redirect:/index/preLogin";
}
}
}
// 准备注册
@RequestMapping("/preReg")
public String preReg() {
this.front();
return "users/register";
}
// 用户注册
@RequestMapping("/register")
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", "用户名已存在");
}
// 退出登录
@RequestMapping("/exit")
public String exit() {
this.front();
this.getSession().removeAttribute("userid");
this.getSession().removeAttribute("username");
this.getSession().removeAttribute("users");
return "index";
}
// 准备修改密码
@RequestMapping("/prePwd")
public String prePwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
return "users/editpwd";
}
// 修改密码
@RequestMapping("/editpwd")
public String editpwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
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";
}
return "redirect:/index/prePwd";
}
//用户个人中心
}
}
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")
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;
}
}
if ("status".equals(cond)) {
topic.setStatus(name);
}
if ("reps".equals(cond)) {
topic.setReps(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")
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<Orders> ordersList = this.ordersService.getAllOrders();
this.getRequest().setAttribute("ordersList", ordersList);
List<Goods> goodsList = this.goodsService.getAllGoods();
this.getRequest().setAttribute("goodsList", goodsList);
return "admin/edittopic";
}
public TopicService getTopicService() {
return topicService;
}
public void setTopicService(TopicService topicService) {
this.topicService = topicService;
}
}
private String appId = "108850";
private String appSecret = "NzhmN2JhNGQtNmRmOC00MWIwLTk1OGEtOTEyYzFiYjFlY2Vk";
@ResponseBody
@RequestMapping("/sendCode")
public boolean getCode(String memPhone, HttpSession httpSession){
try {
JSONObject json = null;
//随机生成验证码
String code = String.valueOf(new Random().nextInt(999999));
String pcode=null;
//将验证码通过榛子云接口发送至手机
ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
Map<String, Object> params = new HashMap<String, Object>();
//前台输入的手机号
params.put("number", memPhone);
//这个模板id对应的是榛子云个人中心的模板id
params.put("templateId", 5032);
String[] templateParams = new String[2];
templateParams[0] = code;
templateParams[1] = "5分钟";
params.put("templateParams", templateParams);
String result = client.send(params);
System.out.println(result);
json = JSONObject.parseObject(result);
if (json.getIntValue("code")!=0){//发送短信失败
return false;
}
//将验证码存到session中,同时存入创建时间
//以json存放,这里使用的是阿里的fastjson
pcode=code;
System.out.println(pcode);
httpSession.setAttribute("pcode",pcode);
json = new JSONObject();
json.put("memPhone",memPhone);
json.put("code",code);
json.put("createTime",System.currentTimeMillis());
// 将认证码存入session
httpSession.setAttribute("code",json);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
if ("memo".equals(cond)) {
employ.setMemo(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.employService.getEmployByLike(employ), "employ", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryemploy";
}
// 按主键查询数据
@RequestMapping("/getEmployById")
public String getEmployById(String id) {
Employ employ = this.employService.getEmployById(id);
this.getRequest().setAttribute("employ", employ);
return "admin/editemploy";
}
public EmployService getEmployService() {
return employService;
}
public void setEmployService(EmployService employService) {
this.employService = employService;
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/article", produces = "text/plain;charset=utf-8")
public class ArticleController extends BaseController {
}
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);
}
if ("status".equals(cond)) {
topic.setStatus(name);
}
if ("reps".equals(cond)) {
topic.setReps(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")
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<Orders> ordersList = this.ordersService.getAllOrders();
this.getRequest().setAttribute("ordersList", ordersList);
// 批量删除数据
@RequestMapping("/deleteTopicByIds")
public String deleteTopicByIds() {
String[] ids = this.getRequest().getParameterValues("topicid");
for (String topicid : ids) {
this.topicService.deleteTopic(topicid);
}
return "redirect:/topic/getAllTopic";
}
// 更新数据
@RequestMapping("/updateTopic")
public String updateTopic(Topic topic) {
this.topicService.updateTopic(topic);
return "redirect:/topic/getAllTopic";
}
// 显示全部数据
@RequestMapping("/getAllTopic")
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")
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 ("status".equals(cond)) {
allot.setStatus(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.allotService.getAllotByLike(allot), "allot", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryallot";
}
// 按主键查询数据
@RequestMapping("/getAllotById")
public String getAllotById(String id) {
Allot allot = this.allotService.getAllotById(id);
this.getRequest().setAttribute("allot", allot);
List<Orders> ordersList = this.ordersService.getAllOrders();
this.getRequest().setAttribute("ordersList", ordersList);
List<Employ> employList = this.employService.getAllEmploy();
this.getRequest().setAttribute("employList", employList);
return "admin/editallot";
}
public AllotService getAllotService() {
return allotService;
}
public void setAllotService(AllotService allotService) {
this.allotService = allotService;
}
}