基于javaweb的SSM网上电商系统(java+ssm+mysql+tomcat+jsp)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

090023062402

100023062402

110023062402

120023062402

140023062402

基于javaweb的SSM网上电商系统(java+ssm+mysql+tomcat+jsp)

一、项目简述

功能:本系统分用户前台和管理员后台。 前台展示+后台管理,前台界面可实现用户登录,用户注 册,商品展示,商品明细展示,用户信息修改,密码修 改,购物车添加,商品购买,商品结算,订单查询,购物 车查询,后台管理可实现商品管理,订单管理,用户管理

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui等等。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26




/**
* 前台相关接口
*/
@Controller
@RequestMapping("/index")
public class IndexController{

@Autowired
private GoodService goodService;
@Autowired
private TypeService typeService;


/**
* 首页
* @return
*/
@GetMapping("/index")
public String index(HttpServletRequest request){
request.setAttribute("flag", 1);
// 今日推荐
List<Goods> todayList = goodService.getListByTopType(Tops.TYPE_TODAY, 1, 6); // 取前6个
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	return "/admin/admin_reset.jsp";
}

/**
* 管理员密码重置
* @return
*/
@PostMapping("/adminReset")
public String adminReset(int id, String password, HttpServletRequest request,
@RequestParam(required=false, defaultValue="1") int page) {
adminService.update(id, password);
return "redirect:adminList?page="+page;
}

/**
* 管理员添加
* @return
*/
@PostMapping("/adminSave")
public String adminSave(Admins admin, HttpServletRequest request,
@RequestParam(required=false, defaultValue="1") int page) {
if (Objects.nonNull(adminService.getByUsername(admin.getUsername()))) {
request.setAttribute("msg", "用户名已存在!");
return "/admin/admin_add.jsp";
}
adminService.add(admin);
return "redirect:adminList?flag=5&page="+page;
}

/**
* 管理员删除
* @return
*/
@GetMapping("/adminDelete")
public String adminDelete(int id,
@RequestParam(required=false, defaultValue="1") int page) {
adminService.delete(id);
return "redirect:adminList?flag=5&page="+page;
}

/**
* 图片上传
* @throws Exception
*/
@PostMapping("upload")
public @ResponseBody Map<String, Object> upload(MultipartFile imgFile) throws Exception {
Map<String, Object> map = new HashMap<>();
if (Objects.nonNull(imgFile) && !imgFile.isEmpty()) {
map.put("error", 0);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    // 设置居中样式
dataStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中
dataStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
// 设置数据字体
Font dataFont = wb.createFont();
dataFont.setFontHeightInPoints((short) 12); // 字体高度
dataFont.setFontName("宋体"); // 字体
dataStyle.setFont(dataFont);
// 遍历集合数据,产生数据行
Iterator<T> it = dataList.iterator();
int index = 0;
while (it.hasNext()) {
index++;// 0号位被占用 所以+1
row = sheet.createRow(index);
// 为序号赋值
HSSFCell sequenceCellValue = row.createCell(0);// 序号值永远是第0列
sequenceCellValue.setCellValue(index);
sequenceCellValue.setCellStyle(dataStyle);
sheet.autoSizeColumn(0);
T t = (T) it.next();
// 利用反射,根据传过来的字段名数组,动态调用对应的getXxx()方法得到属性值
for (int i = 0; i < fieldArray.length; i++) {
HSSFCell dataCell = row.createCell(i + 1);
dataCell.setCellStyle(dataStyle);
sheet.autoSizeColumn(i + 1);
String fieldName = fieldArray[i];
String getMethodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);// 取得对应getXxx()方法
Class<? extends Object> tCls = t.getClass();// 泛型为Object以及所有Object的子类
Method getMethod = tCls.getMethod(getMethodName, new Class[] {});// 通过方法名得到对应的方法
Object value = getMethod.invoke(t, new Object[] {});// 动态调用方,得到属性值
if (value != null) {
dataCell.setCellValue(value.toString());// 为当前列赋值
}
}
}

OutputStream outputStream = response.getOutputStream();// 打开流
wb.write(outputStream);// HSSFWorkbook写入流
wb.close();// HSSFWorkbook关闭
outputStream.flush();// 刷新流
outputStream.close();// 关闭流
return wb;
}
// XSSFCellStyle.ALIGN_CENTER 居中对齐
// XSSFCellStyle.ALIGN_LEFT 左对齐
// XSSFCellStyle.ALIGN_RIGHT 右对齐
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class IndexInterceptor extends HandlerInterceptorAdapter{

@Autowired
private TypeService typeService;
@Autowired
private CartService cartService;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
request.setAttribute("typeList", typeService.getList()); // 为所有页面设置类目列表
// 拦截指定路径
String uri = request.getRequestURI();
if(uri.contains("index/cart") || uri.contains("index/order") || uri.contains("index/my")) {
Object user = request.getSession().getAttribute("user");
if (Objects.isNull(user)) {
response.sendRedirect("login");
return false;
}
} // 默认放过
return true;
}

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// 拦截指定路径
String uri = request.getRequestURI();
if(uri.contains("index/cart")) { // 购物车相关请求后 更新session
Users user = (Users) request.getSession().getAttribute("user");
request.getSession().setAttribute("cartCount", cartService.getCount(user.getId()));
}
super.postHandle(request, response, handler, modelAndView);
}

}
package com.config;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
	Users user = (Users) session.getAttribute("user");
return cartService.save(goodId, user.getId());
}

/**
* 添加数量
*/
@PostMapping("/cartAdd")
public @ResponseBody boolean cartAdd(int id){
return cartService.add(id);
}

/**
* 减少数量
*/
@PostMapping("/cartLess")
public @ResponseBody boolean cartLess(int id){
return cartService.less(id);
}

/**
* 删除
*/
@PostMapping("/cartDelete")
public @ResponseBody boolean cartDelete(int id){
return cartService.delete(id);
}


/**
* 查看订单
* @return
* @throws UnsupportedEncodingException
*/
@GetMapping("/order")
public String order(HttpServletRequest request, HttpSession session,
@RequestParam(required=false, defaultValue="1")int page,
@RequestParam(required=false, defaultValue="6")int size) throws UnsupportedEncodingException{
Users user = (Users) session.getAttribute("user");
request.setAttribute("orderList", orderService.getListByUserid(user.getId(), page, size));
request.setAttribute("pageHtml", PageUtil.getPageHtml(request, orderService.getCountByUserid(user.getId()), page, size));
return "/index/order.jsp";
}

/**
* 直接购买
* @return
* @throws MyException
*/
@PostMapping("/orderAdd")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41


/**
* 前台拦截器
*/
public class IndexInterceptor extends HandlerInterceptorAdapter{

@Autowired
private TypeService typeService;
@Autowired
private CartService cartService;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
request.setAttribute("typeList", typeService.getList()); // 为所有页面设置类目列表
// 拦截指定路径
String uri = request.getRequestURI();
if(uri.contains("index/cart") || uri.contains("index/order") || uri.contains("index/my")) {
Object user = request.getSession().getAttribute("user");
if (Objects.isNull(user)) {
response.sendRedirect("login");
return false;
}
} // 默认放过
return true;
}

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// 拦截指定路径
String uri = request.getRequestURI();
if(uri.contains("index/cart")) { // 购物车相关请求后 更新session
Users user = (Users) request.getSession().getAttribute("user");
request.getSession().setAttribute("cartCount", cartService.getCount(user.getId()));
}
super.postHandle(request, response, handler, modelAndView);
}

}
package com.config;


项目链接:
https://javayms.github.io?id=351422292105200fh
https://javayms.pages.dev?id=351422292105200fh