基于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
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/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";
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping("/index")
public class IndexController extends BaseController {
@Autowired
@Resource
private UsersService usersService;
@Autowired
@Resource
private ArticleService articleService;
@Autowired
@Resource
private CateService cateService;
@Autowired
@Resource
private GoodsService goodsService;
@Autowired
@Resource
private CartService cartService;
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private ItemsService itemsService;
@Autowired
@Resource
private TopicService topicService;
@Autowired
@Resource
private EmployService employService;
@Autowired
@Resource
}
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";
}
// 查看订购
@RequestMapping("/showOrders")
public String showOrders(String number) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
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 % 10 == 0) {
maxPage = maxPage / 10;
} else {
maxPage = maxPage / 10 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 10;
int over = (Integer.parseInt(number) + 1) * 10;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
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";
}
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);
} else {
this.getRequest().setAttribute("message", "旧密码错误");
}
return "admin/editpwd";
}
// 管理员退出登录
@RequestMapping("/exit")
public String exit() {
this.getSession().removeAttribute("adminid");
this.getSession().removeAttribute("adminname");
this.getSession().removeAttribute("realname");
this.getSession().removeAttribute("role");
return "admin/index";
}
// 准备添加数据
@RequestMapping("/createAdmin")
public String createAdmin() {
return "admin/addadmin";
}
// 添加数据
@RequestMapping("/addAdmin")
public String addAdmin(Admin admin) {
admin.setAddtime(VeDate.getStringDateShort());
this.adminService.insertAdmin(admin);
return "redirect:/admin/createAdmin";
}
// 通过主键删除数据
@RequestMapping("/deleteAdmin")
public String deleteAdmin(String id) {
this.adminService.deleteAdmin(id);
return "redirect:/admin/getAllAdmin";
}
// 批量删除数据
@RequestMapping("/deleteAdminByIds")
public String deleteAdminByIds() {
String[] ids = this.getRequest().getParameterValues("adminid");
for (String adminid : ids) {
this.adminService.deleteAdmin(adminid);
}
return "redirect:/admin/getAllAdmin";
}
// 更新数据
@RequestMapping("/updateAdmin")
public String updateAdmin(Admin admin) {
this.adminService.updateAdmin(admin);
return "redirect:/admin/getAllAdmin";
}
@RequestMapping("/queryGoodsByCond")
public String queryGoodsByCond(String cond, String name, String number) {
Goods goods = new Goods();
if (cond != null) {
if ("goodsname".equals(cond)) {
goods.setGoodsname(name);
}
if ("image".equals(cond)) {
goods.setImage(name);
}
if ("cateid".equals(cond)) {
goods.setCateid(name);
}
if ("price".equals(cond)) {
goods.setPrice(name);
}
if ("addtime".equals(cond)) {
goods.setAddtime(name);
}
if ("hits".equals(cond)) {
goods.setHits(name);
}
if ("sellnum".equals(cond)) {
goods.setSellnum(name);
}
if ("contents".equals(cond)) {
goods.setContents(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.goodsService.getGoodsByLike(goods), "goods", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querygoods";
}
// 按主键查询数据
@RequestMapping("/getGoodsById")
public String getGoodsById(String id) {
Goods goods = this.goodsService.getGoodsById(id);
this.getRequest().setAttribute("goods", goods);
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/editgoods";
}
// @GetMapping("/findPage")
return "users/checkout";
}
// 结算
@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";
}
}
}
}
package com.controller;
/**
* 基类
*/
@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() {
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;
}
}
}
package com.controller;
day.put(nxtDay);
}
JSONObject json = new JSONObject();
json.put("count", count.toString());
json.put("days", day.toString().replaceAll("\"", ""));
return json.toString();
}
@RequestMapping("/chartpie")
@ResponseBody
public String chartpie() throws JSONException {
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) {
}
String html = buffer.toString();
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>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"" + name + "/" + action + "?number=" + (Integer.parseInt(number) + 1) + "" + path + "\">下一页</a>");
}
// 用户注册
@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", "用户名已存在");
return "redirect:/index/preReg";
}
return "users/login";
}
// 退出登录
@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();
}
// 按分类查询
@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;
}
for (int i = start; i < over; i++) {
Goods x = tempList.get(i);
goodsList.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 {
// 4、订单的信息
alipayRequest.setBizContent(
"{\"out_trade_no\":\""+id+"\","
+ "\"total_amount\":\""+order.getTotal()+"\","
+ " \"subject\":\"爱家政\","
+ "\"body\":\"做饭\","
// + "\"timeout_express\":\"" + timeout_express + "\","
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
String form = "";
try {
// 获取一个登陆页面
form = alipayClient.pageExecute(alipayRequest).getBody(); //调用SDK生成表单
System.out.println(form);
} catch (AlipayApiException e) {
e.printStackTrace();
}
// 把登录页面响应给用户
httpResponse.setContentType("text/html;charset=" + CHARSET);
httpResponse.getWriter().write(form); //直接将完整的表单html输出到页面
httpResponse.getWriter().flush();
httpResponse.getWriter().close();
} else {
// // throw new ShopException(1002, "订单为不能为空");
}
}
// 必须确保这个解耦由支付宝来调用,所以需要做延签
@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<>();
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;
}
}
package com.controller;
@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) {
package com.controller;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/orders", produces = "text/plain;charset=utf-8")
public class OrdersController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private UsersService usersService;
// 准备添加数据
@RequestMapping("/createOrders")
public String createOrders() {
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
return "admin/addorders";
}
// 添加数据
@RequestMapping("/addOrders")
public String addOrders(Orders orders) {
this.ordersService.insertOrders(orders);
return "redirect:/orders/createOrders";
}
// 通过主键删除数据
@RequestMapping("/deleteOrders")
public String deleteOrders(String id) {
this.ordersService.deleteOrders(id);
return "redirect:/orders/getAllOrders";
}
// 批量删除数据
@RequestMapping("/deleteOrdersByIds")
public String deleteOrdersByIds() {
@RequestMapping("/pay")
public String pay(String id) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
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));
topic.setOrdersid(orders.getOrdersid());
String[] ids = this.getRequest().getParameterValues("articleid");
for (String articleid : ids) {
this.articleService.deleteArticle(articleid);
}
return "redirect:/article/getAllArticle";
}
// 更新数据
@RequestMapping("/updateArticle")
public String updateArticle(Article article) {
this.articleService.updateArticle(article);
return "redirect:/article/getAllArticle";
}
// 显示全部数据
@RequestMapping("/getAllArticle")
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")
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";
}
System.out.println("这是一个非法的请求。。。");
}
}
}
package com.util;
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";
}
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;
public String chartline() throws JSONException {
String start = this.getRequest().getParameter("start");
String end = this.getRequest().getParameter("end");
long days = VeDate.getDays(end, start) + 1;
JSONArray count = new JSONArray();
JSONArray day = new JSONArray(); // 存放名称
for (int i = 0; i < days; i++) {
String nxtDay = VeDate.getNextDay(start, "" + i);
double total = 0;
Orders orders = new Orders();
orders.setAddtime(nxtDay);
List<Orders> list = this.ordersService.getOrdersByCond(orders);
for (Orders b : list) {
total += Double.parseDouble(b.getTotal());
}
count.put(total);
day.put(nxtDay);
}
JSONObject json = new JSONObject();
json.put("count", count.toString());
json.put("days", day.toString().replaceAll("\"", ""));
return json.toString();
}
@RequestMapping("/chartpie")
@ResponseBody
public String chartpie() throws JSONException {
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());
// 准备注册
@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", "用户名已存在");
return "redirect:/index/preReg";
}
return "users/login";
}
// 退出登录
@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");
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/topic", produces = "text/plain;charset=utf-8")
public class TopicController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private TopicService topicService;
@Autowired
@Resource
private UsersService usersService;
@Autowired
@Resource
private OrdersService ordersService;
@Autowired
@Resource
private GoodsService goodsService;
// 准备添加数据
@RequestMapping("/createTopic")
public String createTopic() {
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/addtopic";
}
// 添加数据
@RequestMapping("/addTopic")
public String addTopic(Topic topic) {
topic.setUsersid("");
topic.setOrdersid("");
// 设置路径
@RequestMapping(value = "/users", produces = "text/plain;charset=utf-8")
public class UsersController extends BaseController {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private UsersService usersService;
// 准备添加数据
@RequestMapping("/createUsers")
public String createUsers() {
return "admin/addusers";
}
// 添加数据
@RequestMapping("/addUsers")
public String addUsers(Users users) {
this.usersService.insertUsers(users);
return "redirect:/users/createUsers";
}
// 通过主键删除数据
@RequestMapping("/deleteUsers")
public String deleteUsers(String id) {
this.usersService.deleteUsers(id);
return "redirect:/users/getAllUsers";
}
// 批量删除数据
@RequestMapping("/deleteUsersByIds")
public String deleteUsersByIds() {
String[] ids = this.getRequest().getParameterValues("usersid");
for (String usersid : ids) {
this.usersService.deleteUsers(usersid);
}
return "redirect:/users/getAllUsers";
}
// 更新数据
@RequestMapping("/updateUsers")
public String updateUsers(Users users) {
this.usersService.updateUsers(users);
return "redirect:/users/getAllUsers";
}
// 显示全部数据
@RequestMapping("/myTopic")
public String myTopic() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin";
}
String userid = (String) this.getSession().getAttribute("userid");
Topic topic = new Topic();
topic.setUsersid(userid);
List<Topic> topicList = this.topicService.getTopicByCond(topic);
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;
public String updateArticle(Article article) {
this.articleService.updateArticle(article);
return "redirect:/article/getAllArticle";
}
// 显示全部数据
@RequestMapping("/getAllArticle")
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")
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")