基于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
return "admin/additems";
}
// 添加数据
@RequestMapping("/addItems")
public String addItems(Items items) {
this.itemsService.insertItems(items);
return "redirect:/items/createItems";
}
// 通过主键删除数据
@RequestMapping("/deleteItems")
public String deleteItems(String id) {
this.itemsService.deleteItems(id);
return "redirect:/items/getAllItems";
}
// 批量删除数据
@RequestMapping("/deleteItemsByIds")
public String deleteItemsByIds() {
String[] ids = this.getRequest().getParameterValues("itemsid");
for (String itemsid : ids) {
this.itemsService.deleteItems(itemsid);
}
return "redirect:/items/getAllItems";
}
// 更新数据
@RequestMapping("/updateItems")
public String updateItems(Items items) {
this.itemsService.updateItems(items);
return "redirect:/items/getAllItems";
}
// 显示全部数据
@RequestMapping("/getAllItems")
public String getAllItems(String number) {
List<Items> itemsList = this.itemsService.getAllItems();
PageHelper.getPage(itemsList, "items", null, null, 10, number, this.getRequest(), null);
return "admin/listitems";
// 必须确保这个解耦由支付宝来调用,所以需要做延签
@PostMapping("/updateOrderStatus")
public void updateOrderStatus(HttpServletRequest request) throws AlipayApiException {
System.out.println("AliPayController.updateOrderStatus");
// 1.获取支付宝发送的参数了
Map<String, String[]> parameterMap = request.getParameterMap();
// 2、把支付宝传递古来的参数放到一个Map<Sring,String>中
Map<String, String> paramMap = new HashMap<>();
Set<Map.Entry<String, String[]>> entries = parameterMap.entrySet();
for (Map.Entry<String, String[]> entry : entries) {
paramMap.put(entry.getKey(), entry.getValue()[0]);
}
// 3延签,验证这个请你去是支付宝发送的
boolean signVerified = AlipaySignature.rsaCheckV1(paramMap, ALIPAY_PUBLIC_KEY, CHARSET, SINGTYP); //调用SDK验证签名
if (signVerified) {
// 1.获取交易状态
String trade_status = request.getParameter("trade_status");
System.out.println(trade_status);
// 2.判断状态值
if ("TRADE_SUCCESS".equals(trade_status)) {
// 支付成功,修改订单的状态
System.out.println("延签通过,修改订单的状态。。。");
String id = paramMap.get("111111111"); // 获取订单id
Orders orders=ordersService.getOrdersById(id);
ordersService.updateOrders(orders);
}
} else {
System.out.println("这是一个非法的请求。。。");
}
}
}
public class PageHelper {
public static void getPage(List<?> list, String name, List<String> nameList, List<String> valueList, int pageSize, String number,
HttpServletRequest request, String method) {
StringBuffer buffer = new StringBuffer();
String name2 = name.substring(0, 1).toUpperCase() + name.substring(1);
String path = "";
String action = "getAll" + name2 + "";
if (method != null) {
action = "query" + name2 + "ByCond";
}
cate.setMemo(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.cateService.getCateByLike(cate), "cate", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querycate";
}
// 按主键查询数据
@RequestMapping("/getCateById")
public String getCateById(String id) {
Cate cate = this.cateService.getCateById(id);
this.getRequest().setAttribute("cate", cate);
return "admin/editcate";
}
public CateService getCateService() {
return cateService;
}
public void setCateService(CateService cateService) {
this.cateService = cateService;
}
}
@Controller
public class SendCodeController {
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/goods", produces = "text/plain;charset=utf-8")
public class GoodsController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private GoodsService goodsService;
@Autowired
@Resource
private CateService cateService;
// 准备添加数据
@RequestMapping("/createGoods")
public String createGoods() {
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/addgoods";
}
// 添加数据
@RequestMapping("/addGoods")
public String addGoods(Goods goods) {
goods.setAddtime(VeDate.getStringDateShort());
goods.setHits("0");
goods.setSellnum("0");
this.goodsService.insertGoods(goods);
return "redirect:/goods/createGoods";
}
// 通过主键删除数据
@RequestMapping("/deleteGoods")
public String deleteGoods(String id) {
this.goodsService.deleteGoods(id);
return "redirect:/goods/getAllGoods";
}
// 批量删除数据
@RequestMapping("/deleteGoodsByIds")
public String deleteGoodsByIds() {
String[] ids = this.getRequest().getParameterValues("goodsid");
for (String goodsid : ids) {
this.goodsService.deleteGoods(goodsid);
public String deleteCate(String id) {
this.cateService.deleteCate(id);
return "redirect:/cate/getAllCate";
}
// 批量删除数据
@RequestMapping("/deleteCateByIds")
public String deleteCateByIds() {
String[] ids = this.getRequest().getParameterValues("cateid");
for (String cateid : ids) {
this.cateService.deleteCate(cateid);
}
return "redirect:/cate/getAllCate";
}
// 更新数据
@RequestMapping("/updateCate")
public String updateCate(Cate cate) {
this.cateService.updateCate(cate);
return "redirect:/cate/getAllCate";
}
// 显示全部数据
@RequestMapping("/getAllCate")
public String getAllCate(String number) {
List<Cate> cateList = this.cateService.getAllCate();
PageHelper.getPage(cateList, "cate", null, null, 10, number, this.getRequest(), null);
return "admin/listcate";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("/queryCateByCond")
public String queryCateByCond(String cond, String name, String number) {
Cate cate = new Cate();
if (cond != null) {
if ("catename".equals(cond)) {
cate.setCatename(name);
}
if ("memo".equals(cond)) {
cate.setMemo(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.cateService.getCateByLike(cate), "cate", nameList, valueList, 10, number, this.getRequest(), "query");
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 {
orders.setWorktime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.ordersService.getOrdersByLike(orders), "orders", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryorders";
}
// 按主键查询数据
@RequestMapping("/getOrdersById")
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;
}
}
request.setAttribute("html", html);
request.setAttribute(name + "List", objList);
}
public static void getUserPage(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";
}
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>");
}
public CateService getCateService() {
return cateService;
}
public void setCateService(CateService cateService) {
this.cateService = cateService;
}
}
@Controller
public class SendCodeController {
//短信平台相关参数
//这个不用改
private String apiUrl = "https://sms_developer.zhenzikj.com";
//榛子云系统上获取
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;
return "redirect:/topic/createTopic";
}
// 通过主键删除数据
@RequestMapping("/deleteTopic")
public String deleteTopic(String id) {
this.topicService.deleteTopic(id);
return "redirect:/topic/getAllTopic";
}
// 批量删除数据
@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)) {
@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 ("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);
/**
* 基类
*/
@Controller
public class BaseController {
/* 日志 */
protected final Log log = LogFactory.getLog(getClass());
/* 获取基本环境 */
public Map<String, String[]> getParameters() {// 封装为Map的requestParameters
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest().getParameterMap();
}
public HttpServletRequest getRequest() {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest();
}
public HttpSession getSession() {
HttpSession session = null;
try {
session = this.getRequest().getSession();
} catch (Exception e) {
}
return session;
}
/* 向客户端输出操作成功或失败信息 */
public void writeJsonResponse(String success) throws IOException, JSONException {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = attrs.getResponse();
response.setContentType("text/json;charset=UTF-8");
PrintWriter out = response.getWriter();
// 将要被返回到客户端的对象
JSONObject json = new JSONObject();
json.accumulate("result", success);
System.out.println(json.toString());
out.println(json.toString());
@RequestMapping("/checkout")
public String checkout() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
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";
} else {
// 获取一个1000-9999的随机数 防止同时提交
String ordercode = "PD" + VeDate.getStringDatex();
double total = 0;
for (Cart cart : cartList) {
Items details = new Items();
details.setItemsid(VeDate.getStringDatex() + (Math.random() * 9 + 1) * 1000);
details.setGoodsid(cart.getGoodsid());
details.setOrdercode(ordercode);
details.setPrice(cart.getPrice());
Goods goods = this.goodsService.getGoodsById(cart.getGoodsid());
details.setGoodsname(goods.getGoodsname());
this.itemsService.insertItems(details);
goods.setSellnum("" + (Integer.parseInt(goods.getSellnum()) + 1));
this.goodsService.updateGoods(goods);
total += Double.parseDouble(cart.getPrice());
this.cartService.deleteCart(cart.getCartid());
}
String workdate = this.getRequest().getParameter("workdate");
String enddate = this.getRequest().getParameter("enddate");
String worktime = this.getRequest().getParameter("worktime");
long days = VeDate.getDays(enddate, workdate) + 1;
Orders orders = new Orders();
orders.setAddress(getRequest().getParameter("address"));
orders.setAddtime(VeDate.getStringDateShort());
orders.setContact(getRequest().getParameter("contact"));
orders.setOrdercode(ordercode);
orders.setStatus("已付款");
orders.setTotal("" + VeDate.getDouble(total));
orders.setUsersid(userid);
orders.setEnddate(enddate);
orders.setWorkdate(workdate);
orders.setWorktime(worktime);
this.ordersService.insertOrders(orders);
}
return "redirect:/index/showOrders";
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;
// 准备添加数据
@RequestMapping("/createArticle")
public String createArticle() {
return "admin/addarticle";
}
// 添加数据
@RequestMapping("/addArticle")
public String addArticle(Article article) {
article.setAddtime(VeDate.getStringDateShort());
article.setHits("0");
this.articleService.insertArticle(article);
return "redirect:/article/createArticle";
}
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private EmployService employService;
// 准备添加数据
@RequestMapping("/createEmploy")
public String createEmploy() {
return "admin/addemploy";
}
// 添加数据
@RequestMapping("/addEmploy")
public String addEmploy(Employ employ) {
this.employService.insertEmploy(employ);
return "redirect:/employ/createEmploy";
}
// 通过主键删除数据
@RequestMapping("/deleteEmploy")
public String deleteEmploy(String id) {
this.employService.deleteEmploy(id);
return "redirect:/employ/getAllEmploy";
}
// 批量删除数据
@RequestMapping("/deleteEmployByIds")
public String deleteEmployByIds() {
String[] ids = this.getRequest().getParameterValues("employid");
for (String employid : ids) {
this.employService.deleteEmploy(employid);
}
return "redirect:/employ/getAllEmploy";
}
// 更新数据
@RequestMapping("/updateEmploy")
public String updateEmploy(Employ employ) {
this.employService.updateEmploy(employ);
return "redirect:/employ/getAllEmploy";
}
} else {
buffer.append("<a href=\"index/article?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/article?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/article?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/article?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("articleList", articleList);
return "users/article";
}
// 阅读公告
@RequestMapping("/read")
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")
public String prelogin() {
this.front();
return "users/login";
}
// 用户登录
@RequestMapping("/login")
public String login() {
// 更新数据
@RequestMapping("/updateAdmin")
public String updateAdmin(Admin admin) {
this.adminService.updateAdmin(admin);
return "redirect:/admin/getAllAdmin";
}
// 显示全部数据
@RequestMapping("/getAllAdmin")
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")
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 ("role".equals(cond)) {
admin.setRole(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;
// 显示全部数据
@RequestMapping("/getAllEmploy")
public String getAllEmploy(String number) {
List<Employ> employList = this.employService.getAllEmploy();
PageHelper.getPage(employList, "employ", null, null, 10, number, this.getRequest(), null);
return "admin/listemploy";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("/queryEmployByCond")
public String queryEmployByCond(String cond, String name, String number) {
Employ employ = new Employ();
if (cond != null) {
if ("realname".equals(cond)) {
employ.setRealname(name);
}
if ("sex".equals(cond)) {
employ.setSex(name);
}
if ("birthday".equals(cond)) {
employ.setBirthday(name);
}
if ("idcard".equals(cond)) {
employ.setIdcard(name);
}
if ("jiguan".equals(cond)) {
employ.setJiguan(name);
}
if ("minzu".equals(cond)) {
employ.setMinzu(name);
}
if ("workdate".equals(cond)) {
employ.setWorkdate(name);
}
if ("contact".equals(cond)) {
employ.setContact(name);
}
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";