基于SSM框架和MySQL的仿天猫商城
1.项目简介
天猫商城是一个基于SSM框架的综合性B2C电商平台,需求设计主要参考天猫商城的购物流程:用户从注册开始,到完成登录,浏览商品,加入购物车,进行下单,确认收货,评价等一系列操作。 作为模拟天猫商城系统的核心组成部分之一,采用SSM框架的天猫数据管理后台包含商品管理,订单管理,类别管理,用户管理和交易额统计等模块,实现了对整个商城的一站式管理和维护。
后端页面兼容IE10及以上现代浏览器,Chrome,Edge,Firebox等浏览器表现效果最佳。
2.开发环境
-
1.项目使用IntelliJ IDEA开发
-
2.项目数据库为MySQL 5.7版本,在resources下的sql文件夹中下载sql,并导入到数据库中
-
3.使用IDEA打开项目后,在maven面板刷新项目,下载依赖包
-
4.在IDEA中启动springboot项目即可(run方式或debug方式都行)
-
5.账户名和密码详见附件中的sql文件或者在resources下的sql文件夹中的sql文件(sql运行之后在admin表里有账户名和密码)
注意事项 :后台管理界面的订单图表没有数据为正常现象,该图表显示的为近7天的交易额。
后台界面(部分) 访问地址:http://localhost:8082/tmall/admin/login (账户名和密码在admin表里)
3.数据库设计
3.1 表结构
3.1.1 用户表
3.1.2 评论表
3.1.3 产品属性管理表
3.1.4 类别属性表
3.1.5 产品订单详细表
3.1.6 产品订单表
3.1.7 产品图片表
3.1.8 产品表
3.1.9 类别表
3.1.10 管理员表
3.1.11 地址表
3.2 ER图
4.项目开发
4.1 常用工具类
排序工具类
```java public final class OrderUtil { //排序字段 private String orderBy; //倒序排序 private boolean isDesc;
public OrderUtil(String orderBy){
this.orderBy = orderBy;
this.isDesc = false;
}
public OrderUtil(String orderBy,boolean isDesc) {
this.orderBy = orderBy;
this.isDesc = isDesc;
}
public String getOrderBy() {
return orderBy;
}
public boolean getIsDesc() {
return isDesc;
}
}
```
分页工具类
```java public final class PageUtil { private Integer index; private Integer count; private Integer total; private Integer pageStart;
public PageUtil(Integer index, Integer count) {
this.index = index;
this.count = count;
}
public Boolean isHasPrev(){
return index >= 1;
}
public Boolean isHasNext(){
return index + 1 < getTotalPage();
}
public Integer getTotalPage(){
return (int) Math.ceil((double) total / count);
}
public PageUtil(){
}
public Integer getPageStart() {
if (index != null) {
return index * count;
} else {
return pageStart;
}
}
public PageUtil setPageStart(Integer pageStart) {
this.pageStart = pageStart;
return this;
}
public Integer getIndex() {
return index;
}
public PageUtil setIndex(Integer index) {
this.index = index;
return this;
}
public Integer getCount() {
return count;
}
public PageUtil setCount(Integer count) {
this.count = count;
return this;
}
public Integer getTotal() {
return total;
}
public PageUtil setTotal(Integer total) {
this.total = total;
return this;
}
}
```
4.2 配置类
4.2.1 mybatis配置
```java @EnableTransactionManagement @Configuration @MapperScan({"com.xq.tmall.dao*"}) public class MybatisPlusConfig {
/**
* mybatis-plus SQL执行效率插件【生产环境可以关闭】
*/
@Bean
public PerformanceInterceptor performanceInterceptor() {
return new PerformanceInterceptor();
}
/**
* mybatis-plus分页插件<br>
* 文档:http://mp.baomidou.com<br>
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
paginationInterceptor.setLocalPage(true);// 开启 PageHelper 的支持
/*
* 【测试多租户】 SQL 解析处理拦截器<br>
* 这里固定写成住户 1 实际情况你可以从cookie读取,因此数据看不到 【 麻花藤 】 这条记录( 注意观察 SQL )<br>
*/
/*
List<ISqlParser> sqlParserList = new ArrayList<>();
TenantSqlParser tenantSqlParser = new TenantSqlParser();
tenantSqlParser.setTenantHandler(new TenantHandler() {
@Override
public Expression getTenantId() {
return new LongValue(1L);
}
@Override
public String getTenantIdColumn() {
return "tenant_id";
}
@Override
public boolean doTableFilter(String tableName) {
// 这里可以判断是否过滤表
*//*
if ("user".equals(tableName)) {
return true;
}*//*
return false;
}
});
sqlParserList.add(tenantSqlParser);
paginationInterceptor.setSqlParserList(sqlParserList);
paginationInterceptor.setSqlParserFilter(new ISqlParserFilter() {
@Override
public boolean doFilter(MetaObject metaObject) {
MappedStatement ms = PluginUtils.getMappedStatement(metaObject);
// 过滤自定义查询此时无租户信息约束【 麻花藤 】出现
if ("com.baomidou.springboot.mapper.UserMapper.selectListBySQL".equals(ms.getId())) {
return true;
}
return false;
}
});
*/
return paginationInterceptor;
}
} ```
4.2.2 Duild数据源配置
```java package com.xq.tmall.config.datasource;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment;
import com.alibaba.druid.pool.DruidDataSource;
/* * @description:Druid监控数据源 / @Configuration @PropertySource(value = "classpath:application-dev.yml") public class DruidConfiguration {
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource druidDataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
return druidDataSource;
}
/**
* 注册一个StatViewServlet
* @return
*/
@Bean
public ServletRegistrationBean druidStatViewServlet(){
//org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册.
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
//添加初始化参数:initParams
//白名单:
servletRegistrationBean.addInitParameter("allow","127.0.0.1");
//IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
servletRegistrationBean.addInitParameter("deny","");
//登录查看信息的账号密码.
servletRegistrationBean.addInitParameter("loginUsername","admin");
servletRegistrationBean.addInitParameter("loginPassword","123456");
//是否能够重置数据.
servletRegistrationBean.addInitParameter("resetEnable","false");
return servletRegistrationBean;
}
/**
* 注册一个:filterRegistrationBean
* @return
*/
@Bean
public FilterRegistrationBean druidStatFilter(){
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
//添加过滤规则.
filterRegistrationBean.addUrlPatterns("/*");
//添加不需要忽略的格式信息.
filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
}
} ```
4.3 管理员功能开发
```java package com.xq.tmall.controller.admin;
import com.alibaba.fastjson.JSONObject; import com.xq.tmall.controller.BaseController; import com.xq.tmall.entity.Admin; import com.xq.tmall.service.AdminService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpSession; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.UUID;
/* * 后台管理-账户页 / @Controller public class AccountController extends BaseController{ @Autowired private AdminService adminService;
//转到后台管理-账户页-ajax
@RequestMapping(value = "admin/account", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map){
logger.info("检查管理员权限");
Object adminId = checkAdmin(session);
if(adminId == null){
return "admin/include/loginMessage";
}
logger.info("获取目前登录的管理员信息,管理员ID:{}",adminId);
Admin admin = adminService.get(null,Integer.parseInt(adminId.toString()));
map.put("admin",admin);
logger.info("转到后台管理-账户页-ajax方式");
return "admin/accountManagePage";
}
//退出当前账号
@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);
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)
@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/*管理员新密码*/,
@RequestParam(required = false) String admin_profile_picture_src/*管理员头像路径*/,
@PathVariable("admin_id") String admin_id/*管理员编号*/) {
logger.info("检查管理员权限");
Object adminId = checkAdmin(session);
if (adminId == null) {
return "admin/include/loginMessage";
}
JSONObject jsonObject = new JSONObject();
Admin putAdmin = new Admin();
putAdmin.setAdmin_id(Integer.valueOf(admin_id));
putAdmin.setAdmin_nickname(admin_nickname);
if (admin_password != null && !"".equals(admin_password) && admin_newPassword != null && !"".equals(admin_newPassword)) {
logger.info("获取需要修改的管理员信息");
Admin admin = adminService.get(null, Integer.valueOf(adminId.toString()));
if (adminService.login(admin.getAdmin_name(), admin_password) != null) {
logger.info("原密码正确");
putAdmin.setAdmin_password(admin_newPassword);
} else {
logger.info("原密码错误,返回错误信息");
jsonObject.put("success", false);
jsonObject.put("message", "原密码输入有误!");
return jsonObject.toJSONString();
}
}
if (admin_profile_picture_src != null && !"".equals(admin_profile_picture_src)) {
logger.info("管理员头像路径为{}", admin_profile_picture_src);
putAdmin.setAdmin_profile_picture_src(admin_profile_picture_src.substring(admin_profile_picture_src.lastIndexOf("/") + 1));
}
logger.info("更新管理员信息,管理员ID值为:{}", admin_id);
Boolean yn = adminService.update(putAdmin);
if (yn) {
logger.info("更新成功!");
jsonObject.put("success", true);
session.removeAttribute("adminId");
session.invalidate();
logger.info("登录信息已清除");
} else {
jsonObject.put("success", false);
logger.warn("更新失败!事务回滚");
throw new RuntimeException();
}
return jsonObject.toJSONString();
}
} ```
订单处理
```java package com.xq.tmall.controller.admin;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.xq.tmall.controller.BaseController; import com.xq.tmall.entity.Address; import com.xq.tmall.entity.Product; import com.xq.tmall.entity.ProductOrder; import com.xq.tmall.entity.ProductOrderItem; import com.xq.tmall.service. ; import com.xq.tmall.util.OrderUtil; import com.xq.tmall.util.PageUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation. ;
import javax.annotation.Resource; import javax.servlet.http.HttpSession; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Stack;
/* * 后台管理-订单页 / @Controller public class OrderController extends BaseController{ @Autowired private ProductOrderService productOrderService; @Autowired private AddressService addressService; @Autowired private UserService userService; @Autowired private ProductOrderItemService productOrderItemService; @Autowired private ProductService productService; @Autowired private ProductImageService productImageService; @Autowired private LastIDService lastIDService;
//转到后台管理-订单页-ajax
@RequestMapping(value = "admin/order", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map){
logger.info("检查管理员权限");
Object adminId = checkAdmin(session);
if(adminId == null){
return "admin/include/loginMessage";
}
logger.info("获取前10条订单列表");
PageUtil pageUtil = new PageUtil(0, 10);
List<ProductOrder> productOrderList = productOrderService.getList(null, null, new OrderUtil("productOrder_id", true), pageUtil);
map.put("productOrderList",productOrderList);
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("检查管理员权限");
Object adminId = checkAdmin(session);
if(adminId == null){
return "admin/include/loginMessage";
}
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() + " ");
}
StringBuilder builder = new StringBuilder();
while (!addressStack.empty()) {
builder.append(addressStack.pop());
}
logger.warn("订单地址字符串:{}", builder);
order.setProductOrder_detail_address(builder.toString());
logger.info("获取订单详情-用户信息");
order.setProductOrder_user(userService.get(order.getProductOrder_user().getUser_id()));
logger.info("获取订单详情-订单项信息");
List<ProductOrderItem> productOrderItemList = productOrderItemService.getListByOrderId(oid, null);
if (productOrderItemList != null) {
logger.info("获取订单详情-订单项对应的产品信息");
for (ProductOrderItem productOrderItem : productOrderItemList) {
Integer productId = productOrderItem.getProductOrderItem_product().getProduct_id();
logger.warn("获取产品ID为{}的产品信息", productId);
Product product = productService.get(productId);
if (product != null) {
logger.warn("获取产品ID为{}的第一张预览图片信息", productId);
product.setSingleProductImageList(productImageService.getList(productId, (byte) 0, new PageUtil(0, 1)));
}
productOrderItem.setProductOrderItem_product(product);
}
}
order.setProductOrderItemList(productOrderItemList);
map.put("order", order);
logger.info("转到后台管理-订单详情页-ajax方式");
return "admin/include/orderDetails";
}
//更新订单信息-ajax
@ResponseBody
@RequestMapping(value = "admin/order/{order_id}", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8")
public String updateOrder(@PathVariable("order_id") String order_id) {
JSONObject jsonObject = new JSONObject();
logger.info("整合订单信息");
ProductOrder productOrder = new ProductOrder()
.setProductOrder_id(Integer.valueOf(order_id))
.setProductOrder_status((byte) 2)
.setProductOrder_delivery_date(new Date());
logger.info("更新订单信息,订单ID值为:{}", order_id);
boolean yn = productOrderService.update(productOrder);
if (yn) {
logger.info("更新成功!");
jsonObject.put("success", true);
} else {
logger.info("更新失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
jsonObject.put("order_id", order_id);
return jsonObject.toJSONString();
}
//按条件查询订单-ajax
@ResponseBody
@RequestMapping(value = "admin/order/{index}/{count}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public String getOrderBySearch(@RequestParam(required = false) String productOrder_code/* 订单号 */,
@RequestParam(required = false) String productOrder_post/* 订单邮政编码 */,
@RequestParam(required = false) Byte[] productOrder_status_array/* 订单状态数组 */,
@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()
.setProductOrder_code(productOrder_code)
.setProductOrder_post(productOrder_post);
OrderUtil orderUtil = null;
if (orderBy != null) {
logger.info("根据{}排序,是否倒序:{}",orderBy,isDesc);
orderUtil = new OrderUtil(orderBy, isDesc);
}
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);
object.put("totalPage", pageUtil.getTotalPage());
object.put("pageUtil", pageUtil);
return object.toJSONString();
}
}
```
用户处理
```java package com.xq.tmall.controller.admin;
import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.xq.tmall.controller.BaseController; import com.xq.tmall.entity.Address; import com.xq.tmall.entity.Product; import com.xq.tmall.entity.ProductOrderItem; import com.xq.tmall.entity.User; import com.xq.tmall.service. ; import com.xq.tmall.util.OrderUtil; import com.xq.tmall.util.PageUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation. ;
import javax.annotation.Resource; import javax.servlet.http.HttpSession; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.List; import java.util.Map; import java.util.Stack;
/* * 后台管理-用户页 / @Controller public class UserController extends BaseController { @Autowired private UserService userService; @Autowired private AddressService addressService; @Autowired private ReviewService reviewService; @Autowired private ProductOrderItemService productOrderItemService; @Autowired private ProductService productService; @Autowired private ProductImageService productImageService;
//转到后台管理-用户页-ajax
@RequestMapping(value = "admin/user", method = RequestMethod.GET)
public String goUserManagePage(HttpSession session, Map<String, Object> map) {
logger.info("检查管理员权限");
Object adminId = checkAdmin(session);
if (adminId == null) {
return "admin/include/loginMessage";
}
logger.info("获取前十条用户信息");
PageUtil pageUtil = new PageUtil(0, 10);
List<User> userList = userService.getList(null, null, pageUtil);
map.put("userList", userList);
logger.info("获取用户总数量");
Integer userCount = userService.getTotal(null);
map.put("userCount", userCount);
logger.info("获取分页信息");
pageUtil.setTotal(userCount);
map.put("pageUtil", pageUtil);
logger.info("转到后台管理-用户页-ajax方式");
return "admin/userManagePage";
}
//转到后台管理-用户详情页-ajax
@RequestMapping(value = "admin/user/{uid}", method = RequestMethod.GET)
public String getUserById(HttpSession session, Map<String, Object> map, @PathVariable Integer uid/* 用户ID */) {
logger.info("检查管理员权限");
Object adminId = checkAdmin(session);
if (adminId == null) {
return "admin/include/loginMessage";
}
logger.info("获取user_id为{}的用户信息", uid);
User user = userService.get(uid);
logger.info("获取用户详情-所在地地址信息");
Address address = addressService.get(user.getUser_address().getAddress_areaId());
Stack<String> addressStack = new Stack<>();
//最后一级地址
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() + " ");
}
StringBuilder builder = new StringBuilder();
while (!addressStack.empty()) {
builder.append(addressStack.pop());
}
logger.info("所在地地址字符串:{}", builder);
user.setUser_address(new Address().setAddress_name(builder.toString()));
logger.info("获取用户详情-家乡地址信息");
address = addressService.get(user.getUser_homeplace().getAddress_areaId());
//最后一级地址
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() + " ");
}
builder = new StringBuilder();
while (!addressStack.empty()) {
builder.append(addressStack.pop());
}
logger.info("家乡地址字符串:{}", builder);
user.setUser_homeplace(new Address().setAddress_name(builder.toString()));
logger.info("获取用户详情-购物车订单项信息");
List<ProductOrderItem> productOrderItemList = productOrderItemService.getListByUserId(user.getUser_id(), null);
if (productOrderItemList != null) {
logger.info("获取用户详情-购物车订单项对应的产品信息");
for (ProductOrderItem productOrderItem : productOrderItemList) {
Integer productId = productOrderItem.getProductOrderItem_product().getProduct_id();
logger.warn("获取产品ID为{}的产品信息", productId);
Product product = productService.get(productId);
if (product != null) {
logger.warn("获取产品ID为{}的第一张预览图片信息", productId);
product.setSingleProductImageList(productImageService.getList(productId, (byte) 0, new PageUtil(0, 1)));
}
productOrderItem.setProductOrderItem_product(product);
}
}
user.setProductOrderItemList(productOrderItemList);
if (!StringUtils.isEmpty(user.getUser_realname())) {
logger.info("用户隐私加密");
user.setUser_realname(user.getUser_realname().substring(0, 1) + "*");
} else {
user.setUser_realname("未命名");
}
map.put("user", user);
logger.info("转到后台管理-用户详情页-ajax方式");
return "admin/include/userDetails";
}
//按条件查询用户-ajax
@ResponseBody
@RequestMapping(value = "admin/user/{index}/{count}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public String getUserBySearch(@RequestParam(required = false) String user_name/* 用户名称 */,
@RequestParam(required = false) Byte[] user_gender_array/* 用户性别数组 */,
@RequestParam(required = false) String orderBy/* 排序字段 */,
@RequestParam(required = false, defaultValue = "true") Boolean isDesc/* 是否倒序 */,
@PathVariable Integer index/* 页数 */,
@PathVariable Integer count/* 行数 */) throws UnsupportedEncodingException {
//移除不必要条件
Byte gender = null;
if (user_gender_array != null && user_gender_array.length == 1) {
gender = user_gender_array[0];
}
if (user_name != null) {
//如果为非空字符串则解决中文乱码:URLDecoder.decode(String,"UTF-8");
user_name = "".equals(user_name) ? null : URLDecoder.decode(user_name, "UTF-8");
}
if (orderBy != null && "".equals(orderBy)) {
orderBy = null;
}
//封装查询条件
User user = new User()
.setUser_name(user_name)
.setUser_gender(gender);
OrderUtil orderUtil = null;
if (orderBy != null) {
logger.info("根据{}排序,是否倒序:{}", orderBy, isDesc);
orderUtil = new OrderUtil(orderBy, isDesc);
}
JSONObject object = new JSONObject();
logger.info("按条件获取第{}页的{}条用户", index + 1, count);
PageUtil pageUtil = new PageUtil(index, count);
List<User> userList = userService.getList(user, orderUtil, pageUtil);
object.put("userList", JSONArray.parseArray(JSON.toJSONString(userList)));
logger.info("按条件获取用户总数量");
Integer userCount = userService.getTotal(user);
object.put("userCount", userCount);
logger.info("获取分页信息");
pageUtil.setTotal(userCount);
object.put("totalPage", pageUtil.getTotalPage());
object.put("pageUtil", pageUtil);
return object.toJSONString();
}
}
```
4.4 前台开发
商城详情页
```java package com.xq.tmall.controller.fore;
import com.alibaba.fastjson.JSONObject; import com.xq.tmall.controller.BaseController; import com.xq.tmall.entity.Category; import com.xq.tmall.entity.Product; import com.xq.tmall.entity.User; import com.xq.tmall.service.CategoryService; import com.xq.tmall.service.ProductImageService; import com.xq.tmall.service.ProductService; import com.xq.tmall.service.UserService; import com.xq.tmall.util.OrderUtil; import com.xq.tmall.util.PageUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.List; import java.util.Map;
/* * 前台天猫-主页 / @Controller public class ForeHomeController extends BaseController { @Autowired private UserService userService; @Autowired private CategoryService categoryService; @Autowired private ProductService productService; @Autowired private ProductImageService productImageService;
//转到前台天猫-主页
@RequestMapping(value = "/", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map) {
logger.info("检查用户是否登录");
Object userId
参考文献
- 基于SSM的分布式商城的设计与实现(中国地质大学(北京)·刘彤月)
- 购物网站的设计与开发(山东大学·王振海)
- 龙城电子商城购物系统的设计与实现(电子科技大学·任艳梅)
- 基于SSM框架的B2C网上商城系统的设计与实现(湖南大学·陈峰)
- 基于Spring与Hibernate的智能电子商城系统的设计与实现(北京邮电大学·王昶太)
- 基于SSM框架的网上商城系统的设计与实现(北京邮电大学·赵浩翔)
- 基于SSM框架的电子商城项目的设计与实现(山东大学·李天庆)
- 基于SSM框架的电子商城项目的设计与实现(山东大学·李天庆)
- 基于Spring Boot的电子商城设计与实现(哈尔滨工业大学·李晨)
- B2B电子商务平台系统的设计与研发(山东大学·李丽君)
- 基于JAVA的B2C电子商城设计与实现(西安电子科技大学·胡峰)
- 基于SSM框架的B2C网上商城系统的设计与实现(湖南大学·陈峰)
- 电子商城系统的设计与实现(电子科技大学·李晓玲)
- 基于SSM框架的电子商城项目的设计与实现(山东大学·李天庆)
- 电子商务M站系统的设计与实现(北京交通大学·胡霞)
本文内容包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主题。发布者:毕设项目助手 ,原文地址:https://m.bishedaima.com/yuanma/35464.html