基于javaweb+mysql的ssm+maven在线图书商城系统(java+ssm+jsp+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven在线图书商城系统(java+ssm+jsp+jquery+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.数据库:MySql 5.7版本; 6.是否Maven项目:是;
技术栈
- 后端: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. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,前台地址:http://localhost:8080/snack/shop/index 后台地址:http://localhost:8080/snack/admin/login/adminLogin
@Controller
@RequestMapping("/shop/")
public class ShopControll {
@Autowired
public shopService shopService=null;
@Autowired
public typeService typeService;
//主页
@RequestMapping("index")
public String gotoIndex(HttpServletRequest request){
List<Snackinfo> HotSnackList = shopService.getHotSnack();
List<Snackinfo> newSnackList = shopService.getNewSnack();
List<Type> typeList = typeService.getall();
request.setAttribute("HotSnackList",HotSnackList);
request.setAttribute("newSnackList",newSnackList);
request.getSession().setAttribute("type", typeList);
System.out.println("00");
return "user/index";
}
//登录
@RequestMapping("userLoginGet")
public String gotoUserLogin(){
return "user/userLogin";
}
@RequestMapping("userLoginPost")
public String gotoUserLogin(Userinfo userinfo,HttpServletRequest request){
Userinfo exituser = shopService.userLogin(userinfo);
if(exituser ==null){
request.setAttribute("msg","用户名或密码错误");
return "user/userLogin";
@RequestMapping("userOrderPayMoneyConfirm")
@ResponseBody
public String userOrderPayMoneyConfirm(HttpServletRequest request,Float payNumber,Float uMoney,String uPasword,String oId){
Userinfo userinfo = (Userinfo)request.getSession().getAttribute("exituser");
if(userinfo.getuPassword().equals(uPasword)){
sorderService.updateOrderByoId(oId);
userService.updateUserinfoBypay(userinfo.getuId(), uMoney-payNumber);
}else{
return ResponseUtil.errorToClient();
}
return ResponseUtil.successToClient();
}
//删除订单
@RequestMapping("deleteMyOrder")
@ResponseBody
public String deleteAdminOrder(String oId){
return ResponseUtil.successToClient(adminOrderService.deleteAdminOrder(oId));
}
//跳转管理员信息
@RequestMapping("mainToAdminuser")
public String mainToAdminuser(){
return "admin/persionInfo/adminInfo";
}
//加载管理员信息
@RequestMapping("mainSelectAdminuser")
@ResponseBody
public String mainSelectAdminuser(HttpServletRequest request){
int adId =(int)request.getSession().getAttribute("adminId");
return ResponseUtil.successToClient(userService.selectAdminInfo(adId));
}
//更新管理员信息
@RequestMapping("mainUpdateAdminuser")
@ResponseBody
public String mainUpdateAdminuser(DoAdminInfo admin){
return ResponseUtil.successToClient(userService.updateAdminInfo(admin));
}
}
package com.snack.web;
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filename));
return ResponseUtil.successToClient();
} else {
return ResponseUtil.errorToClient();
}
}
@RequestMapping("mainToAdminSnackinfo")
public String mainToAdminImg(HttpServletRequest request) {
return "admin/snackinfo/adminSnackinfo";
}
//商品
@RequestMapping("adminSnackinfoLimit")
@ResponseBody
public DataTables adminOrderLimit(int start, int length,
String sName, String sType, String startDate, String endDate) {
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("pageStart", start);
map.put("pageSize", length);
map.put("sType", sType);
map.put("sName", sName);
map.put("startDate", startDate);
map.put("endDate", endDate);
PageHelp<Snackinfo> pageHelp = adminSnackInfoService.selectAdminSnackinfoLimit(map);
DataTables datatable = new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//删除用户
@RequestMapping("delAdminUserinfo")
@ResponseBody
public String delUserinfoById(int sId) {
return ResponseUtil.successToClient(adminSnackInfoService.delAdminSnackinfo(sId));
}
@Controller
@RequestMapping("/shop/")
public class ShopControll {
@Autowired
public shopService shopService=null;
@Autowired
public typeService typeService;
//主页
@RequestMapping("index")
public String gotoIndex(HttpServletRequest request){
List<Snackinfo> HotSnackList = shopService.getHotSnack();
List<Snackinfo> newSnackList = shopService.getNewSnack();
List<Type> typeList = typeService.getall();
request.setAttribute("HotSnackList",HotSnackList);
request.setAttribute("newSnackList",newSnackList);
request.getSession().setAttribute("type", typeList);
System.out.println("00");
return "user/index";
}
//登录
@RequestMapping("userLoginGet")
@RequestParam("file") MultipartFile file, String fileName, Snackinfo snackinfo) throws Exception {
Date day = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String sBatch = df.format(day).toString() + String.valueOf((int) (Math.random() * 9000 + 1000));
snackinfo.setsCreatedate(DateUtil.getCurrentDateStr());
snackinfo.setState(1);
snackinfo.setsPictureurl(fileName);
snackinfo.setsBatch(sBatch);
adminSnackInfoService.addAdminSnackinfo(snackinfo);
//如果文件不为空,写入上传路径
if (!file.isEmpty()) {
//上传文件路径
String path = request.getSession().getServletContext().getRealPath("/image/");
//上传文件名
String filename = fileName;
File filepath = new File(path, filename);
//判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filename));
return ResponseUtil.successToClient();
} else {
return ResponseUtil.errorToClient();
}
}
@RequestMapping("mainToAdminSnackinfo")
public String mainToAdminImg(HttpServletRequest request) {
return "admin/snackinfo/adminSnackinfo";
}
//商品
@RequestMapping("adminSnackinfoLimit")
@ResponseBody
public DataTables adminOrderLimit(int start, int length,
String sName, String sType, String startDate, String endDate) {
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("pageStart", start);
map.put("pageSize", length);
map.put("sType", sType);
map.put("sName", sName);
map.put("startDate", startDate);
map.put("endDate", endDate);
PageHelp<Snackinfo> pageHelp = adminSnackInfoService.selectAdminSnackinfoLimit(map);
return ResponseUtil.successToClient(adminOrderService.updateAdminOrder(receiptinfo));
}
//updateOrderDetial加载订单
@RequestMapping("updateSelectAdminOrderDetial")
@ResponseBody
public String updateSelectAdminOrderDetial(int dId){
return ResponseUtil.successToClient(adminOrderService.updateSelectAdminOrderDetial(dId));
}
//updateOrderDetial订单
@RequestMapping("updateOrderdetail")
@ResponseBody
public String updateOrderdetail(Orderdetail orderdetail){
return ResponseUtil.successToClient(adminOrderService.updateOrderdetail(orderdetail));
}
//删除OrderDetial
@RequestMapping("deleteOrderdetail")
@ResponseBody
public String deleteOrderdetail(int dId,String oId){
List<Orderdetail> orderdetailList = adminOrderService.selectOrderdetailByoId(oId);
if(orderdetailList.size()>=2){
adminOrderService.deleteOrderdetailBydId(dId);
return ResponseUtil.successToClient(1);
}else{
adminOrderService.deleteAdminOrder(oId);
return ResponseUtil.successToClient(2);
}
}
//导出订单详情
@RequestMapping("outExcelOrder")
@ResponseBody
public void outExcelOrder(HttpServletResponse response,String oId){
SXSSFWorkbook workbook = new SXSSFWorkbook();
reportSheet(workbook,oId);
outputExcel(response, workbook, "订单详情");
}
private void reportSheet(SXSSFWorkbook workbook,String oId) {
List<DoExcelOrder> outExcelOrderDetail = adminOrderService.outExcelOrderDetail(oId);
for (int i = 0; i < outExcelOrderDetail.size(); i++) {
if(i!=0){
outExcelOrderDetail.get(i).setOId("");
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<Integral> pageHelp= userService.selectIntegralLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//跳转个人账户页面
@RequestMapping("userAccount")
public String userAccount(){
return "user/account";
}
//加载个人积分
@RequestMapping("userAccountLimit")
@ResponseBody
public DataTables userAccountLimit(HttpServletRequest request,int start,int length){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("uId",request.getSession().getAttribute("frontuserId"));
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<Account> pageHelp= userService.selectAccountLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//获得金额
@RequestMapping("getMoneyAcount")
@ResponseBody
public Object getMoneyAcount(HttpServletRequest request){
return request.getSession().getAttribute("money");
}
//查看当前订单
@RequestMapping("userOrderLimit")
@ResponseBody
public DataTables userOrderLimit(HttpServletRequest request,int start,int length){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("uId",request.getSession().getAttribute("frontuserId"));
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<DoMyOrder> pageHelp= userService.selectOrderLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
map.put("pageSize",length);
PageHelp<Account> pageHelp= userService.selectAccountLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//获得金额
@RequestMapping("getMoneyAcount")
@ResponseBody
public Object getMoneyAcount(HttpServletRequest request){
return request.getSession().getAttribute("money");
}
//查看当前订单
@RequestMapping("userOrderLimit")
@ResponseBody
public DataTables userOrderLimit(HttpServletRequest request,int start,int length){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("uId",request.getSession().getAttribute("frontuserId"));
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<DoMyOrder> pageHelp= userService.selectOrderLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//跳转订单页面
@RequestMapping("userGoOrder")
public String userGoOrder(HttpSession session){
return "user/myOrder";
}
//跳转历史订单
@RequestMapping("userGoSuccessOrder")
public String userGoSuccessOrder(){
return "user/myOrderSuccess";
@Controller
@RequestMapping("/admin/order/")
public class AdminOrderControll {
@Autowired
private adminOrderService adminOrderService;
@Autowired
private userService userService;
@RequestMapping("mainToAdminOrder")
public String mainToAdminOrder(){
return "admin/order/adminOrder";
}
//订单
@RequestMapping("adminOrderLimit")
@ResponseBody
public DataTables adminOrderLimit(int start,int length,
String oId,String oTimeStart,String oTimeEnd,String adUserName){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("pageStart",start);
map.put("pageSize",length);
map.put("oId",oId);
map.put("oTimeStart",oTimeStart);
map.put("oTimeEnd",oTimeEnd);
map.put("adUserName",adUserName);
PageHelp<DoAdminOrder> pageHelp= adminOrderService.selectAdminOrderLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
public String delUserinfoById(int uId){
return ResponseUtil.successToClient(adminUserService.delUserinfoById(uId));
}
//更新加载用户
@RequestMapping("updateGoUserinfoById")
@ResponseBody
public String updateGoUserinfoById(int uId){
return ResponseUtil.successToClient(adminUserService.updateGoUserinfoById(uId));
}
//更新用户
@RequestMapping("updateUserinfoById")
@ResponseBody
public String updateUserinfoById(Userinfo userinfo){
return ResponseUtil.successToClient(adminUserService.updateUserinfoById(userinfo));
}
@RequestMapping("mainToAdmin")
public String mainToAdmin(){
return "admin/user/adminAdmin";
}
//加载用户
@RequestMapping("adminAdminLimit")
@ResponseBody
public DataTables adminAdminLimit(HttpServletRequest request,int start,int length,DoAdmin doAdmin){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<Admin> pageHelp= adminUserService.selectAdminLimit(map,doAdmin);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//新建
@RequestMapping("addNewAdmin")
@ResponseBody
return "admin/user/adminUserinfo";
}
//加载用户
@RequestMapping("adminUserinfoLimit")
@ResponseBody
public DataTables adminUserinfoLimit(HttpServletRequest request,int start,int length,Userinfo userinfo){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<Userinfo> pageHelp= adminUserService.selectAdminUserinfoLimit(map,userinfo);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//删除用户
@RequestMapping("delUserinfoById")
@ResponseBody
public String delUserinfoById(int uId){
return ResponseUtil.successToClient(adminUserService.delUserinfoById(uId));
}
//更新加载用户
@RequestMapping("updateGoUserinfoById")
@ResponseBody
public String updateGoUserinfoById(int uId){
return ResponseUtil.successToClient(adminUserService.updateGoUserinfoById(uId));
}
//更新用户
@RequestMapping("updateUserinfoById")
@ResponseBody
public String updateUserinfoById(Userinfo userinfo){
return ResponseUtil.successToClient(adminUserService.updateUserinfoById(userinfo));
}
@RequestMapping("mainToAdmin")
public String mainToAdmin(){
return "admin/user/adminAdmin";
}
//加载用户
if(exituser ==null){
request.setAttribute("msg","用户名或密码错误");
return "user/userLogin";
}
request.getSession().setAttribute("exituser", exituser);
request.getSession().setAttribute("frontuser", exituser.getuUsername());
request.getSession().setAttribute("frontuserId", exituser.getuId());
request.getSession().setAttribute("money", exituser.getuMoney());
return "redirect:index";
}
//退出登录
@RequestMapping("userlogout")
public String showlogin(HttpServletRequest request){
HttpSession session = request.getSession();
session.removeAttribute("frontuser");
session.removeAttribute("frontuserId");
return "redirect:userLoginGet";
}
//商品详情
@RequestMapping("proDatail")
public String gotoProDatail(HttpServletRequest request,Snackinfo snack){
Snackinfo sck = shopService.selectById(snack);
request.setAttribute("sck", sck);
return "product/proDetail";
}
//查询订单
@RequestMapping("selectOrderSnack")
@ResponseBody
public DataTables selectOrderSnack(String oId,int start,int length){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("oId", oId);
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<DoSnack> pageHelp = shopService.selectOrderSnack(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
@ResponseBody
public void outExcelOrder(HttpServletResponse response,String oId){
SXSSFWorkbook workbook = new SXSSFWorkbook();
reportSheet(workbook,oId);
outputExcel(response, workbook, "订单详情");
}
private void reportSheet(SXSSFWorkbook workbook,String oId) {
List<DoExcelOrder> outExcelOrderDetail = adminOrderService.outExcelOrderDetail(oId);
for (int i = 0; i < outExcelOrderDetail.size(); i++) {
if(i!=0){
outExcelOrderDetail.get(i).setOId("");
outExcelOrderDetail.get(i).setOName("");
outExcelOrderDetail.get(i).setOPhone("");
outExcelOrderDetail.get(i).setOAddress("");
}
outExcelOrderDetail.get(i).setMoney(outExcelOrderDetail.get(i).getMoney()+"元");
}
ExcelUtil2 excelUtil=new ExcelUtil2();
List<JSONObject> columns = new ArrayList<>();
columns.add(excelUtil.defaultGetColumn("订单号", "oId", 15 * 256, false, false));
columns.add(excelUtil.defaultGetColumn("收货人", "oName", 15 * 256, false, false));
columns.add(excelUtil.defaultGetColumn("电话", "oPhone", 15 * 256, false, false));
columns.add(excelUtil.defaultGetColumn("地址", "oAddress", 26 * 256, false, false));
columns.add(excelUtil.defaultGetColumn("商品名", "sName", 15 * 256, false, false));
columns.add(excelUtil.defaultGetColumn("数量", "num", 12 * 256, false, false));
columns.add(excelUtil.defaultGetColumn("单价", "money", 12 * 256, false, false));
excelUtil.createSheet(workbook, outExcelOrderDetail, columns, "订单详情");
}
private void outputExcel(HttpServletResponse response, SXSSFWorkbook workbook, String excelName) {
response.setContentType("application/vnd.ms-excel");
try {
// 进行转码,使其支持中文文件名
response.setHeader("content-disposition", "attachment;filename=" + new String(excelName.getBytes("GB2312"), "ISO-8859-1") + ".xlsx");
workbook.write(response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request;
HttpServletResponse resp =(HttpServletResponse) response;
HttpSession session = req.getSession();
// 获得用户请求的URI
String path = req.getRequestURI();
// 从session取得已经登录验证的凭证 我这里的demo用的是password来作为登录凭证
String adminName = (String) session.getAttribute("adminName");
// login.jsp页面无需过滤(根据自己项目的要求来)
if(path.indexOf("adminGoMain") == -1) {//注意:登录页面千万不能过滤 不然过滤器就。。。。。自行调试不要偷懒!这样记忆深刻
chain.doFilter(req, resp);
return;
} else if(path.indexOf("adminGoMain") > -1){//如果不是login.jsp进行过滤
if (adminName == null || "".equals(adminName)) {
resp.sendRedirect("adminLogin");
} else {
// 已经登陆,继续此次请求
chain.doFilter(req, resp);
}
}
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
package com.snack.web;
}
//获得金额
@RequestMapping("getMoneyAcount")
@ResponseBody
public Object getMoneyAcount(HttpServletRequest request){
return request.getSession().getAttribute("money");
}
//查看当前订单
@RequestMapping("userOrderLimit")
@ResponseBody
public DataTables userOrderLimit(HttpServletRequest request,int start,int length){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("uId",request.getSession().getAttribute("frontuserId"));
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<DoMyOrder> pageHelp= userService.selectOrderLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//跳转订单页面
@RequestMapping("userGoOrder")
public String userGoOrder(HttpSession session){
return "user/myOrder";
}
//跳转历史订单
@RequestMapping("userGoSuccessOrder")
public String userGoSuccessOrder(){
return "user/myOrderSuccess";
}
//查看当前订单
@RequestMapping("userSucOrderLimit")
@ResponseBody
public DataTables userSucOrderLimit(HttpServletRequest request,int start,int length){
Map<Object,Object> map=new HashMap<Object, Object>();
for(Orderdetail temp : receiptinfo.getOrderdetailSet()){
tal+=temp.getoMoney()*temp.getoNum();
}
return String.valueOf(tal);
}
@RequestMapping(value="/delete",method=RequestMethod.GET)
public String deleteSorder(Snackinfo snackinfo,HttpSession session) {
Receiptinfo receiptinfo = (Receiptinfo)session.getAttribute("receiptinfo");
Set<Orderdetail> set = receiptinfo.getOrderdetailSet();
Iterator<Orderdetail> iterator = set.iterator();
while(iterator.hasNext()){
Orderdetail orderdetail = iterator.next();
if(orderdetail.getSnackinfo().getsId()==snackinfo.getsId()){
iterator.remove();
receiptinfo.setoPhone(String.valueOf((Double.parseDouble(receiptinfo.getoPhone())-orderdetail.getoMoney()*orderdetail.getoNum())));
}
}
if( set.size() <= 0){
session.removeAttribute("receiptinfo");
}
return "redirect:gotocar";
}
@RequestMapping(value="/clear",method=RequestMethod.GET)
public String clearSorder(Snackinfo snackinfo,HttpSession session) {
Receiptinfo receiptinfo = (Receiptinfo)session.getAttribute("receiptinfo");
if(receiptinfo!=null){
Set<Orderdetail> set = receiptinfo.getOrderdetailSet();
set.clear();
}
receiptinfo.setoPhone(String.valueOf(0d));
session.removeAttribute("receiptinfo");
return "redirect:gotocar";
@Controller
@RequestMapping("/sorder")
public class SorderController {
@Autowired
private sorderService sorderService=null;
@Autowired
private userService userService;
@RequestMapping(value="/add",method=RequestMethod.POST)
public String addSorder(Snackinfo snackinfo,HttpSession session) {
System.out.println("-------addCar()------"+snackinfo.getsNumber());
// 1:通过 product.id获取当前的商品数据
Snackinfo findSnackinfo = sorderService.snackfindById(snackinfo.getsId());
findSnackinfo.setsNumber(snackinfo.getsNumber());
//2:判断当前session是否有购物车,如果没有则创建
if (session.getAttribute("receiptinfo")==null) {
//创建购物车,存到session中
session.setAttribute("receiptinfo", new Receiptinfo(new HashSet<Orderdetail>()));
}
Receiptinfo receiptinfo = (Receiptinfo)session.getAttribute("receiptinfo");
//3:把商品信息转化为sorder,并且添加到购物车中(判断购物车是否重复)
receiptinfo = sorderService.addSorder(receiptinfo, findSnackinfo);
receiptinfo.setoPhone(cluTotal(receiptinfo));
return "redirect:gotocar";
}
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("pageStart", start);
map.put("pageSize", length);
map.put("sType", sType);
map.put("sName", sName);
map.put("startDate", startDate);
map.put("endDate", endDate);
PageHelp<Snackinfo> pageHelp = adminSnackInfoService.selectAdminSnackinfoLimit(map);
DataTables datatable = new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//删除用户
@RequestMapping("delAdminUserinfo")
@ResponseBody
public String delUserinfoById(int sId) {
return ResponseUtil.successToClient(adminSnackInfoService.delAdminSnackinfo(sId));
}
//加载用户
@RequestMapping("selectAdminUserinfoBysId")
@ResponseBody
public String selectAdminUserinfoBysId(int sId) {
return ResponseUtil.successToClient(adminSnackInfoService.selectAdminUserinfoBysId(sId));
}
@RequestMapping(value = "updateAdminSnack")
@ResponseBody
public String updateAdminSnack(HttpServletRequest request, MultipartFile file, String fileName, Snackinfo snackinfo) throws Exception {
//如果文件不为空,写入上传路径
if (file != null) {
snackinfo.setsPictureurl(fileName);
adminSnackInfoService.updateAdminSnackinfo(snackinfo);
//上传文件路径
String path = request.getSession().getServletContext().getRealPath("/image/");
//上传文件名
String filename = fileName;
File filepath = new File(path, filename);
//判断路径是否存在,如果不存在就创建一个
public String updateGoAdminById(HttpServletRequest request,Admin admin){
return ResponseUtil.successToClient(adminUserService.selectAdminByOne(admin));
}
//更新用户
@RequestMapping("updateAdminById")
@ResponseBody
public String updateAdminById(Admin admin){
return ResponseUtil.successToClient(adminUserService.updateAdmin(admin));
}
}
package com.snack.web;
@Controller
@RequestMapping("/admin/login/")
public class AdminLogin {
@Autowired
private adminLoginService adminLoginService;
@Autowired
private AccountMapper accountMapper;
@Autowired
private typeService typeService;
//登录login
@ResponseBody
public DataTables adminOrderLimit(int start,int length,
String oId,String oTimeStart,String oTimeEnd,String adUserName){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("pageStart",start);
map.put("pageSize",length);
map.put("oId",oId);
map.put("oTimeStart",oTimeStart);
map.put("oTimeEnd",oTimeEnd);
map.put("adUserName",adUserName);
PageHelp<DoAdminOrder> pageHelp= adminOrderService.selectAdminOrderLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//删除订单
@RequestMapping("deleteAdminOrder")
@ResponseBody
public String deleteAdminOrder(String oId){
return ResponseUtil.successToClient(adminOrderService.deleteAdminOrder(oId));
}
//update加载订单
@RequestMapping("updateSelectAdminOrder")
@ResponseBody
public String updateSelectAdminOrder(int rId){
return ResponseUtil.successToClient(adminOrderService.updateSelectAdminOrder(rId));
}
//update订单
@RequestMapping("updateAdminOrder")
@ResponseBody
public String updateAdminOrder(Receiptinfo receiptinfo){
return ResponseUtil.successToClient(adminOrderService.updateAdminOrder(receiptinfo));
}
//updateOrderDetial加载订单
@RequestMapping("updateSelectAdminOrderDetial")
@ResponseBody
public String updateSelectAdminOrderDetial(int dId){
return ResponseUtil.successToClient(adminOrderService.updateSelectAdminOrderDetial(dId));
}
//updateOrderDetial订单
@RequestMapping("updateOrderdetail")
@ResponseBody
public String updateOrderdetail(Orderdetail orderdetail){
return ResponseUtil.successToClient(adminOrderService.updateOrderdetail(orderdetail));
}
@Controller
@RequestMapping("/admin/snackinfo/")
public class AdminSnakcinfoController {
@Autowired
private adminSnackInfoService adminSnackInfoService;
@Autowired
private typeService typeService;
@RequestMapping(value = "addAdminSnack")
@ResponseBody
public String upload(HttpServletRequest request,
@RequestParam("file") MultipartFile file, String fileName, Snackinfo snackinfo) throws Exception {
Date day = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String sBatch = df.format(day).toString() + String.valueOf((int) (Math.random() * 9000 + 1000));
snackinfo.setsCreatedate(DateUtil.getCurrentDateStr());
snackinfo.setState(1);
snackinfo.setsPictureurl(fileName);
snackinfo.setsBatch(sBatch);
adminSnackInfoService.addAdminSnackinfo(snackinfo);
//如果文件不为空,写入上传路径
if (!file.isEmpty()) {
//上传文件路径
String path = request.getSession().getServletContext().getRealPath("/image/");
//上传文件名
String filename = fileName;
}
}
package com.snack.web;
@Controller
@RequestMapping("/admin/login/")
public class AdminLogin {
@Autowired
private adminLoginService adminLoginService;
@Autowired
private AccountMapper accountMapper;
@Autowired
private typeService typeService;
//登录login
@RequestMapping("adminLogin")
public String adminLogin(){
System.out.println("存储过程相加:"+accountMapper.selectNum(4, 6));
return "admin/adminLogin";
}
//登录
@RequestMapping("adminGoLogin")
public String adminGoLogin(HttpServletRequest request,Admin admin){
List<Admin> adminSelect = adminLoginService.adminLogin(admin);
if(adminSelect.size()==1){
request.getSession().setAttribute("adminName", adminSelect.get(0).getAdUsername());
request.getSession().setAttribute("adminId", adminSelect.get(0).getAdId());
}
}
package com.snack.web;
@Controller
@RequestMapping("/admin/img/")
public class AdminImg {
@RequestMapping("mainToAdminImg")
public String mainToAdminImg() {
return "admin/Img/adminImg";
}
@RequestMapping(value = "/upload")
@ResponseBody
public String upload(HttpServletRequest request,
@RequestParam("file") MultipartFile file, String fileName) throws Exception {
//如果文件不为空,写入上传路径
if (!file.isEmpty()) {
//上传文件路径
String path = request.getSession().getServletContext().getRealPath("/image/trimImg/");
//上传文件名
String filename = fileName;
File filepath = new File(path, filename);
//判断路径是否存在,如果不存在就创建一个
//filepath.delete();
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filename));
return ResponseUtil.successToClient();
} else {
return ResponseUtil.errorToClient();
}
}
snackinfo.setsPictureurl(fileName);
adminSnackInfoService.updateAdminSnackinfo(snackinfo);
//上传文件路径
String path = request.getSession().getServletContext().getRealPath("/image/");
//上传文件名
String filename = fileName;
File filepath = new File(path, filename);
//判断路径是否存在,如果不存在就创建一个
//filepath.delete();
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filename));
return ResponseUtil.successToClient();
} else {
adminSnackInfoService.updateAdminSnackinfo(snackinfo);
return ResponseUtil.successToClient();
}
}
}
package com.snack.web;
@Controller
PageHelp<Account> pageHelp= userService.selectAccountLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//获得金额
@RequestMapping("getMoneyAcount")
@ResponseBody
public Object getMoneyAcount(HttpServletRequest request){
return request.getSession().getAttribute("money");
}
//查看当前订单
@RequestMapping("userOrderLimit")
@ResponseBody
public DataTables userOrderLimit(HttpServletRequest request,int start,int length){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("uId",request.getSession().getAttribute("frontuserId"));
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<DoMyOrder> pageHelp= userService.selectOrderLimit(map);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//跳转订单页面
@RequestMapping("userGoOrder")
public String userGoOrder(HttpSession session){
return "user/myOrder";
}
//跳转历史订单
@RequestMapping("userGoSuccessOrder")
public String userGoSuccessOrder(){
return "user/myOrderSuccess";
}
public String mainToAdmin(){
return "admin/user/adminAdmin";
}
//加载用户
@RequestMapping("adminAdminLimit")
@ResponseBody
public DataTables adminAdminLimit(HttpServletRequest request,int start,int length,DoAdmin doAdmin){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<Admin> pageHelp= adminUserService.selectAdminLimit(map,doAdmin);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//新建
@RequestMapping("addNewAdmin")
@ResponseBody
public String addNewAdmin(Admin admin){
return ResponseUtil.successToClient(adminUserService.addAdmin(admin));
}
//删除用户
@RequestMapping("delAdminById")
@ResponseBody
public String delAdminById(Admin admin){
return ResponseUtil.successToClient(adminUserService.delAdmin(admin));
}
//更新加载用户
@RequestMapping("updateGoAdminById")
@ResponseBody
public String updateGoAdminById(HttpServletRequest request,Admin admin){
return ResponseUtil.successToClient(adminUserService.selectAdminByOne(admin));
}
//更新用户
@RequestMapping("updateAdminById")
@ResponseBody
@ResponseBody
public String updateGoUserinfoById(int uId){
return ResponseUtil.successToClient(adminUserService.updateGoUserinfoById(uId));
}
//更新用户
@RequestMapping("updateUserinfoById")
@ResponseBody
public String updateUserinfoById(Userinfo userinfo){
return ResponseUtil.successToClient(adminUserService.updateUserinfoById(userinfo));
}
@RequestMapping("mainToAdmin")
public String mainToAdmin(){
return "admin/user/adminAdmin";
}
//加载用户
@RequestMapping("adminAdminLimit")
@ResponseBody
public DataTables adminAdminLimit(HttpServletRequest request,int start,int length,DoAdmin doAdmin){
Map<Object,Object> map=new HashMap<Object, Object>();
map.put("pageStart",start);
map.put("pageSize",length);
PageHelp<Admin> pageHelp= adminUserService.selectAdminLimit(map,doAdmin);
DataTables datatable=new DataTables();
datatable.setData(pageHelp.getList());
datatable.setRecordsFiltered(pageHelp.getRecord());
datatable.setRecordsTotal(pageHelp.getRecord());
return datatable;
}
//新建
@RequestMapping("addNewAdmin")
@ResponseBody
public String addNewAdmin(Admin admin){
return ResponseUtil.successToClient(adminUserService.addAdmin(admin));
}
//删除用户
@RequestMapping("delAdminById")
HttpSession session = request.getSession();
List<Permission> list = (List<Permission>)session.getAttribute("allPer");
List<Permission> list2 = (List<Permission>)session.getAttribute("userPer");
for (int i = 0; i < list.size(); i++) {
if(uri.equals((list.get(i).getUrl()))){
for (int j = 0; j < list2.size(); j++) {
k++;
if(uri.contains(list2.get(j).getUrl())){
return true;
}
}
}
p++;
}
if(p>0 && k==list2.size()){
response.getWriter().write("Sorry");
return false;
}
if(list.size()==p){
return true;
}
return false;
}
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex)
throws Exception {
// TODO Auto-generated method stub
}