基于javaweb的SSM+Maven校园外卖点餐系统(java+ssm+jsp+maven+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

292223170607

320023012402

330023012402

340023012402

350023012402

360023012402

370023012402

基于javaweb的SSM+Maven校园外卖点餐系统(java+ssm+jsp+maven+mysql)

一、项目简述 环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Spring + SpringMVC + MyBatis + css + JavaScript + JQuery + Ajax + layui+ maven等等。

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
51
52
53
@RequestMapping("/foreLogin")
public String foreLogin(Customer customer, HttpSession session, Model model){
Customer cst = customerService.foreLogin(customer);
if (cst!=null){
session.setAttribute("cst",cst);
return "redirect:foreIndex";
}else {
return "redirect:foreLoginMsg";
}
}

/**
* 用户登陆返回信息
* @return
*/
@RequestMapping("/foreLoginMsg")
public String foreLoginMsg(HttpServletRequest request){
request.setAttribute("msg","true");
return "forepage/forelogin";
}

/**
* 客户注销
* @param session
* @return
*/
@RequestMapping("/foreCstLoginOut")
public String cstLoginOut(HttpSession session){
session.setAttribute("cst",null);
return "redirect:foreIndex";
}

/**
* 立即购买
* @param session
* @param pid 商品id
* @param number 商品数量
* @return 重定向到支付 , 传入订单项id
*/
@RequestMapping("/forebuyone")
public String forebuyone(HttpSession session, int pid, int number, float totalPrice){
Customer cst = (Customer) session.getAttribute("cst");
Product product = productService.get(pid);

int oiid = 0;

boolean find = false;
List<OrderItem> orderItems = orderItemService.listByCustomer(cst.getId());//获得订单项表中该用户的所有订单id为空的订单项
for (OrderItem oi : orderItems) {
//基于用户对象customer,查询没有生成订单的订单项集合
// 如果产品是一样的话,就进行数量追加
if(oi.getProduct().getId().intValue()==product.getId().intValue()){
//如果已经存在这个产品对应的OrderItem,并且还没有生成订单,即还在购物车中。 那么就应该在对应的OrderItem基础上,调整数量
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

long maxSize = ((Long) conf.get("maxSize")).longValue();

if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
}

savePath = PathFormat.parse(savePath, originFileName);

String physicalPath = (String) conf.get("rootPath") + savePath;

InputStream is = fileStream.openStream();
State storageState = StorageManager.saveFileByInputStream(is,
physicalPath, maxSize);
is.close();

if (storageState.isSuccess()) {
storageState.putInfo("url", PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);
}

return storageState;
} catch (FileUploadException e) {
return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR);
} catch (IOException e) {
}
return new BaseState(false, AppInfo.IO_ERROR);
}

private static boolean validType(String type, String[] allowTypes) {
List<String> list = Arrays.asList(allowTypes);

return list.contains(type);
}
}
package com.demo.controller;

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
				return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
}

String savePath = (String) conf.get("savePath");
String originFileName = fileStream.getName();
String suffix = FileType.getSuffixByFilename(originFileName);

originFileName = originFileName.substring(0,
originFileName.length() - suffix.length());
savePath = savePath + suffix;

long maxSize = ((Long) conf.get("maxSize")).longValue();

if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
}

savePath = PathFormat.parse(savePath, originFileName);

String physicalPath = (String) conf.get("rootPath") + savePath;

InputStream is = fileStream.openStream();
State storageState = StorageManager.saveFileByInputStream(is,
physicalPath, maxSize);
is.close();

if (storageState.isSuccess()) {
storageState.putInfo("url", PathFormat.format(savePath));
storageState.putInfo("type", suffix);
storageState.putInfo("original", originFileName + suffix);
}

return storageState;
} catch (FileUploadException e) {
return new BaseState(false, AppInfo.PARSE_REQUEST_ERROR);
} catch (IOException e) {
}
return new BaseState(false, AppInfo.IO_ERROR);
}

private static boolean validType(String type, String[] allowTypes) {
List<String> list = Arrays.asList(allowTypes);

return list.contains(type);
}
}
package com.demo.controller;

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




public class BinaryUploader {

public static final State save(HttpServletRequest request,
Map<String, Object> conf) {
FileItemStream fileStream = null;
boolean isAjaxUpload = request.getHeader( "X_Requested_With" ) != null;

if (!ServletFileUpload.isMultipartContent(request)) {
return new BaseState(false, AppInfo.NOT_MULTIPART_CONTENT);
}

ServletFileUpload upload = new ServletFileUpload(
new DiskFileItemFactory());

if ( isAjaxUpload ) {
upload.setHeaderEncoding( "UTF-8" );
}

try {
FileItemIterator iterator = upload.getItemIterator(request);

while (iterator.hasNext()) {
fileStream = iterator.next();

if (!fileStream.isFormField())
break;
fileStream = null;
}

if (fileStream == null) {
return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
}
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
}

@RequestMapping("/deleteProduct")
public String del(@RequestParam(value = "id")int id, HttpSession session){
productService.del(id);
String imageName = id+".jpg";
File file = new File(session.getServletContext().getRealPathhttps://yms-1257401191.cos.ap-nanjing.myqcloud.com/product"),imageName);
file.delete();
return "redirect:list";
}

@RequestMapping("/editProduct")
public String editUI(@RequestParam(value = "id")int id, Model model){
//获得要修改商品的信息
Product product = productService.get(id);
model.addAttribute("product",product);
System.out.println(product);

List<Category> categoryList = categoryService.list();
List<User> userList = userService.list();
//通过商品id 返回所属分类
Category categoryByid = productService.getCategoryByCid(id);
model.addAttribute("crrentCategory",categoryByid);
//通过id返回所属商家
User userById = userService.getUserByPid(id);
model.addAttribute("crrentUser",userById);

model.addAttribute("categoryList",categoryList);
model.addAttribute("userList",userList);

return "productmodule/product-edit";
}

@RequestMapping("/updateProduct")
public String update(Product product, HttpSession session, UploadUtil upload) throws IOException {
productService.update(product);
if(upload!=null){

String imageName = product.getId()+".jpg";

File file = new File(session.getServletContext().getRealPathhttps://yms-1257401191.cos.ap-nanjing.myqcloud.com/product"),imageName);
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
        totalProductNumber += oi.getNumber();
}
model.addAttribute("ois", ois);
model.addAttribute("size", totalProductNumber);

return "forepage/foreCart";
}

/**
* 删除订单项
* @param oiid 订单项id
* @param session
* @return
*/
@RequestMapping("/foreDelOrderItem")
@ResponseBody
public String foreDelOrderItem(int oiid, HttpSession session){
Customer customer = (Customer) session.getAttribute("cst");
if(customer==null){
return "noSuccess";
}
orderItemService.del(oiid);
return "success";
}

/*
点击提交订单
1. 从session中获取cst对象
2. 通过参数Order接受收货人
3. 根据当前时间加上一个4位随机数生成订单号
4. 根据上述参数,创建订单对象
5. 把订单状态设置为未支付
6. 从session中获取订单项集合 ( 在结算功能的ForeController.buy() 13行,订单项集合被放到了session中 )
7. 把订单加入到数据库,并且遍历订单项集合,设置每个订单项的order,更新到数据库
8. 统计本次订单的总金额
9. 客户端跳转到确认支付页forePayed,并带上订单id和总金额
*/
@RequestMapping("/foreCreateOrder")
public String createOrder(Model model, String address, HttpSession session){
/*
提交订单后,设置code,客户id,支付状态,地址
*/
Order order = new Order();
Customer customer =(Customer) session.getAttribute("cst");
String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + RandomUtils.nextInt(10000);
order.setCode(orderCode);
order.setAddress(address);
order.setCstid(customer.getId());
order.setStatus(0);//未支付


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