一、项目简述
功能:本系统分用户前台和管理员后台。 前台展示+后台管理,前台界面可实现用户登录,用户注 册,商品展示,商品明细展示,用户信息修改,密码修 改,购物车添加,商品购买,商品结算,订单查询,购物 车查询,后台管理可实现商品管理,订单管理,用户管理
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
@RequestParam(required = false) String orderBy/* 排序字段 */,
@RequestParam(required = false,defaultValue = "true") Boolean isDesc/* 是否倒序 */,
@PathVariable Integer index/* 页数 */,
@PathVariable Integer count/* 行数 */){
//移除不必要条件
if (productOrder_status_array != null && (productOrder_status_array.length <= 0 || productOrder_status_array.length >=5)) {
productOrder_status_array = null;
}
if (productOrder_code != null){
productOrder_code = "".equals(productOrder_code) ? null : productOrder_code;
}
if(productOrder_post != null){
productOrder_post = "".equals(productOrder_post) ? null : productOrder_post;
}
if (orderBy != null && "".equals(orderBy)) {
orderBy = null;
}
//封装查询条件
ProductOrder productOrder = new ProductOrder()
file.transferTo(new File(filePath));
logger.info("文件上传成功!");
jsonObject.put("success", true);
jsonObject.put("fileName", fileName);
} catch (IOException e) {
logger.warn("文件上传失败!");
e.printStackTrace();
jsonObject.put("success", false);
}
return jsonObject.toJSONString();
}
//更新管理员信息
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@ResponseBody
@RequestMapping(value = "admin/account/{admin_id}", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8")
public String updateAdmin(HttpSession session, @RequestParam String admin_nickname/*管理员昵称*/,
@RequestParam(required = false) String admin_password/*管理员当前密码*/,
@RequestParam(required = false) String admin_newPassword/*管理员新密码*/,
@RequestMapping(value = "admin/account/logout", method = RequestMethod.GET)
public String logout(HttpSession session) {
Object o = session.getAttribute("adminId");
if (o == null) {
logger.info("无相关信息,返回管理员登陆页");
} else {
session.removeAttribute("adminId");
session.invalidate();
logger.info("登录信息已清除,返回管理员登陆页");
}
return "redirect:/admin/login";
}
//管理员头像上传
@ResponseBody
@RequestMapping(value = "admin/uploadAdminHeadImage", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public String uploadAdminHeadImage(@RequestParam MultipartFile file, HttpSession session) {
String originalFileName = file.getOriginalFilename();
logger.info("获取图片原始文件名:{}", originalFileName);
assert originalFileName != null;
String extension = originalFileName.substring(originalFileName.lastIndexOf('.'));
//生成随机名
String fileName = UUID.randomUUID() + extension;
//获取上传路径
String filePath = session.getServletContext().getRealPath("/") + "res/images/item/adminProfilePicture/" + fileName;
logger.info("文件上传路径:{}", filePath);
JSONObject jsonObject = new JSONObject();
logger.info("获取订单总数量");
Integer productOrderCount = productOrderService.getTotal(null, null);
map.put("productOrderCount", productOrderCount);
logger.info("获取分页信息");
pageUtil.setTotal(productOrderCount);
map.put("pageUtil", pageUtil);
logger.info("转到后台管理-订单页-ajax方式");
return "admin/orderManagePage";
}
//转到后台管理-订单详情页-ajax
@RequestMapping(value = "admin/order/{oid}", method = RequestMethod.GET)
public String goToDetailsPage(HttpSession session, Map<String, Object> map, @PathVariable Integer oid/* 订单ID */) {
logger.info("获取order_id为{}的订单信息",oid);
ProductOrder order = productOrderService.get(oid);
logger.info("获取订单详情-地址信息");
Address address = addressService.get(order.getProductOrder_address().getAddress_areaId());
Stack<String> addressStack = new Stack<>();
//详细地址
addressStack.push(order.getProductOrder_detail_address());
//最后一级地址
addressStack.push(address.getAddress_name() + " ");
//如果不是第一级地址,循环拼接地址信息
while (!address.getAddress_areaId().equals(address.getAddress_regionId().getAddress_areaId())) {
address = addressService.get(address.getAddress_regionId().getAddress_areaId());
addressStack.push(address.getAddress_name() + " ");
}
try {
logger.info("文件上传中...");
file.transferTo(new File(filePath));
logger.info("文件上传完成");
object.put("success", true);
object.put("fileName", fileName);
} catch (IOException e) {
logger.warn("文件上传失败!");
e.printStackTrace();
object.put("success", false);
}
return object.toJSONString();
}
}
后台管理-订单页:
/**
* 后台管理-订单页
*/
@Controller
public class
OrderController extends BaseController{
@Resource(name="productOrderService")
private ProductOrderService productOrderService;
@Resource(name = "addressService")
ProductOrder productOrder = new ProductOrder()
.setProductOrder_code(productOrder_code)
.setProductOrder_post(productOrder_post);
OrderUtil orderUtil = null;
if (orderBy != null) {
logger.info("根据{}排序,是否倒序:{}",orderBy,isDesc);
orderUtil = new OrderUtil(orderBy, isDesc);
} else {
orderUtil = new OrderUtil("productOrder_id",
true);
}
JSONObject object = new JSONObject();
logger.info("按条件获取第{}页的{}条订单", index + 1, count);
PageUtil pageUtil = new PageUtil(index, count);
List<ProductOrder> productOrderList = productOrderService.getList(productOrder, productOrder_status_array, orderUtil, pageUtil);
object.put("productOrderList", JSONArray.parseArray(JSON.toJSONString(productOrderList)));
logger.info("按条件获取订单总数量");
Integer productOrderCount = productOrderService.getTotal(productOrder, productOrder_status_array);
object.put("productOrderCount", productOrderCount);
logger.info("获取分页信息");
pageUtil.setTotal(productOrderCount);
/**
* 后台管理-产品类型页
*/
@Controller
public class CategoryController extends BaseController {
@Resource(name = "categoryService")
private CategoryService categoryService;
@Resource(name = "lastIDService")
private LastIDService lastIDService;
@Resource(name = "propertyService")
private PropertyService propertyService;
//转到后台管理-产品类型页-ajax
@RequestMapping(value = "admin/category", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map) {
logger.info("获取前10条产品类型列表");
PageUtil pageUtil = new PageUtil(0, 10);
List<Category> categoryList = categoryService.getList(null, pageUtil);
map.put("categoryList", categoryList);
logger.info("获取产品类型总数量");
Integer categoryCount = categoryService.getTotal(null);
map.put("categoryCount", categoryCount);
logger.info("获取分页信息");
pageUtil.setTotal(categoryCount);
String extension = originalFileName.substring(originalFileName.lastIndexOf('.'));
//生成随机名
String fileName = UUID.randomUUID() + extension;
//获取上传路径
String filePath = session.getServletContext().getRealPath("/") + "res/images/item/adminProfilePicture/" + fileName;
logger.info("文件上传路径:{}", filePath);
JSONObject jsonObject = new JSONObject();
try {
logger.info("文件上传中...");
file.transferTo(new File(filePath));
logger.info("文件上传成功!");
jsonObject.put("success", true);
jsonObject.put("fileName", fileName);
} catch (IOException e) {
logger.warn("文件上传失败!");
e.printStackTrace();
jsonObject.put("success", false);
}
return jsonObject.toJSONString();
}
//更新管理员信息
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
}
if(productOrder_post != null){
productOrder_post = "".equals(productOrder_post) ? null : productOrder_post;
}
if (orderBy != null && "".equals(orderBy)) {
orderBy = null;
}
//封装查询条件
ProductOrder productOrder = new ProductOrder()
.setProductOrder_code(productOrder_code)
.setProductOrder_post(productOrder_post);
OrderUtil orderUtil = null;
if (orderBy != null) {
logger.info("根据{}排序,是否倒序:{}",orderBy,isDesc);
orderUtil = new OrderUtil(orderBy, isDesc);
} else {
orderUtil = new OrderUtil("productOrder_id",
true);
}
JSONObject object = new JSONObject();
logger.info("按条件获取第{}页的{}条订单", index + 1, count);
PageUtil pageUtil = new PageUtil(index, count);
List<ProductOrder> productOrderList = productOrderService.getList(productOrder, productOrder_status_array, orderUtil, pageUtil);
object.put("productOrderList", JSONArray.parseArray(JSON.toJSONString(productOrderList)));