基于javaweb的SpringBoot点餐系统(java+springboot+ssm+mysql+maven)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

070023312402

080023312402

100023312402

110023312402

基于javaweb的SpringBoot点餐系统(java+springboot+ssm+mysql+maven)

一、项目简述

功能:数据库采用mysq昨为数据存储,系统中涉及到的关 键表有,用户表、用户详情表、商品表、订单表、商品订 单关联表、评价表等等。本系统分为前端和后端,前端功 能有:登录注册、修改个人信息、修改收货地址、查看商 品、加购商品、结算商品,对订单进行评价、用户留言等 功能;后端功能有:登录、商品管理、用户管理、订单管 理、留言公告管理等功能。本系统中的购物车功能设计、io流读写图片存放本地、订单导出、“echarts插件实现订单信 息统计、后台批量操作、pagehelper实现分页等细节值得 学习。

二、项目运行

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

项目技术: JSP +Springboot+ SpringMVC + MyBatis + html+ 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
	State state = null;

int actionCode = ActionMap.getType( this.actionType );

Map<String, Object> conf = null;

switch ( actionCode ) {

case ActionMap.CONFIG:
return this.configManager.getAllConfig().toString();

case ActionMap.UPLOAD_IMAGE:
case ActionMap.UPLOAD_SCRAWL:
case ActionMap.UPLOAD_VIDEO:
case ActionMap.UPLOAD_FILE:
conf = this.configManager.getConfig( actionCode );
state = new Uploader( request, conf ).doExec();
break;

case ActionMap.CATCH_IMAGE:
conf = configManager.getConfig( actionCode );
String[] list = this.request.getParameterValues( (String)conf.get( "fieldName" ) );
state = new ImageHunter( conf ).capture( list );
break;

case ActionMap.LIST_IMAGE:
case ActionMap.LIST_FILE:
conf = configManager.getConfig( actionCode );
int start = this.getStartIndex();
state = new FileManager( conf ).listFile( start );
break;

}

return state.toJSONString();

}

public int getStartIndex () {

String start = this.request.getParameter( "start" );

try {
return Integer.parseInt( start );
} catch ( Exception e ) {
return 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

@RequestMapping("/admin/toProductBanner")
public String toProductBanner(Model model,@RequestParam(required = true, defaultValue = "1") Integer page){
PageHelper.startPage(page,5);
List<ProductBanner> productBannerList = productService.findAllProductBanner();
PageInfo<ProductBanner> pageInfo = new PageInfo<>(productBannerList);
model.addAttribute("page",pageInfo);
model.addAttribute("productBannerList",productBannerList);
return "/admin/product/product_banner_list";
}

@RequestMapping("/admin/toAddProductBanner")
public String toAddProductBanner(){
return "/admin/product/product_banner_edit";
}

/**
*选择上架状态 并且未关联热门的商品
*/
@GetMapping(value = "/admin/validProduct/list" ,produces = "application/json;charset=utf-8")
@ResponseBody
public Object getValidProduct(){
List<Product> validProductList = new ArrayList<>();
productService.findAllProductList().
stream().filter(product -> product.getStatus() == 1). //过滤上架的商品
collect(Collectors.toList()).forEach(product ->{
if (productService.findProductBannerById(product.getId()) == null){ //过滤未关联的商品
validProductList.add(product);
}
});
return ResponseMessageEnum.SUCCESS.appendObjectToString(validProductList);
}


@RequestMapping("/admin/addNewProductBanner")
public String addNewProductBanner(ProductBanner productBanner){
productService.addNewProductBanner(productBanner);
return "redirect:/admin/toProductBanner";
}
/**
* 删除商品类别
*/
@RequestMapping("/admin/deleteProductBanner")
public String deleteProductBanner(Integer id){
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
    for (Product product : productList) {
cartMap.put(product, buyCount);
}
session.setAttribute("cart", cartMap);
session.setAttribute("buyCount", 0);
return "/pages/order/cart";
}

/**
* 去我的购物车
*/
@GetMapping("/toMyCart")
public String tocart() {
return "/pages/order/cart";
}

/**
* 从购物车删除
*/
@PostMapping("/toDelete")
public String toDelete(Integer productId, HttpSession session, Model model) {
Product product = productService.findProductById(productId);
System.out.println(product);
((Map<Product, Integer>) session.getAttribute("cart")).remove(product);
System.out.println("size:" + ((Map<Product, Integer>) session.getAttribute("cart")).size());
return "/pages/order/cart";
}

/**
* 去支付订单页面
*/
@PostMapping("/toOrder")
public String toOrder(HttpSession session, String[] buyNum, Model model,@RequestParam("id") Integer[] id,
@RequestParam("checkId") Integer[] checkId) {
//1-获取session中用户基本信息 和详细信息
User user = (User) session.getAttribute("user");
UserInfo dbUserInfo = userService.findAdressByUserId(user.getId().toString());
//2-将购物车内的*全部*商品id和对应购买数量放入map中 key:商品id value:购买数量
Map<Integer,Integer> map = new HashMap<>();
for (int i = 0; i < id.length; i++){
map.put(id[i],Integer.parseInt(buyNum[i]));
}
//3-创建我的订单map集合 key:product产品信息 value:购买数量
Subject subject = SecurityUtils.getSubject();
Map<Product, Integer> myCartMap = new HashMap<>();
subject.getSession().setAttribute("myCartMap", myCartMap);
Map<Product, Integer> myOrder = (HashMap<Product, Integer>) session.getAttribute("myCartMap");
//4-从存储有全部商品和购买数量的map中 取出 被选中的信息(checkbox)放到我的订单map中
for (Integer cId :checkId){
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


/**
登录相关的controller
*/

@Controller
public class LoginController {

@Autowired
private UserService userService;

/**
* 通过shiro认证登录
*/
@PostMapping("/loginLogin")
public String loginLogin(Model model, String username, String password) {

//1-如果用户账号被禁用
User dbUser = userService.findUserByU_P(username, password);
if(dbUser != null && dbUser.getStatus() == 0){
model.addAttribute("errorInfo","该账号已禁用,请联系管理员...");
return "/login";
}
//2-通过subject进行登录操作
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
try {
//2-1-使用subject执行登录 并把user放到session中
subject.login(token);
User user = (User) subject.getPrincipal();
subject.getSession().setAttribute("user", user);
//2-2-初始化购物车
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
/**
*@描述 1-2-导出Excel-自定义列标题和数据
*/
protected Map<String,Object> getTitleArrayAndVarList(List<Object> dataList) {
Map<String,Object> dataMap = new HashMap<String,Object>();
//1-标题
String[] titleArray = {
"订单序号",
"订单编号",
"订单金额",
"收货人",
"收获地址",
"下单时间",
"订单状态"
};
dataMap.put("titles", Arrays.asList(titleArray));
//2-数据
List<OrderExcelExportVO> varList = new ArrayList<OrderExcelExportVO>();
for(int i=0;i<dataList.size();i++){
OrderExcelExportVO data = (OrderExcelExportVO)dataList.get(i);
List<Object> vpd = new ArrayList<>();
varList.add(data);
}
dataMap.put("varList", varList);

return dataMap;
}
/**
*@描述 1-3-导出excel-自定义Excel标题和文件名
*/
protected Map<String,String> getExcelTitleAndFileName(){
Map<String,String> excelMap = new HashMap<String,String>();
excelMap.put("excelTitle","订单信息表格");//excel标题
DateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String time = sdf.format(new Timestamp(System.currentTimeMillis()));
excelMap.put("fileName","订单信息表格" + time);//文件名
return excelMap;
}
/**
*@描述 1-4-创建AbstractExcelView
*/
protected AbstractExcelView getAbstractExcelView(Map<String, String> excelMap){
try {
ObjectExcelViewOrder erv = new ObjectExcelViewOrder(excelMap.get("fileName"),excelMap.get("excelTitle"));
return erv;
} catch (Exception e) {
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


/**
后端product模块相关的controller
*/
@Controller
public class Back_ProductController {

@Autowired
private ProductService productService;

@Autowired
private ProductKindService productKindService;

/**
* 按条件查找数据--模糊查询
* @return
*/
@RequestMapping("/admin/toSelect")
public String toSelect(@RequestParam("Pname") String Pname, Model model) {
List<Product> list = productService.findAllProductCondition(Pname);
model.addAttribute("productList", list);
return "/admin/product/product_list";
}

/**
*
* 后台展示商品列表


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