基于javaweb的SpringBoot+MyBatis在线商城水果蔬菜商城果蔬商城(前台、后台)(java+springboot+ssm+freemarker+mysql+maven)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

该项目分为前台用户和后台管理员两个角色,

用户角色的功能:登录(JWT的token验证)、注册浏览商品、修改个人信息(上传图片)、修改密码、评论商品添加商品到购物车提交订单查看订单收藏商品等等功能。

管理员角色的功能:管理用户信息、管理用户评论信息、管理商品信息、管理订单信息等等功能。

350123222502

前台:

140123222502

150123222502

160123222502

170123222502

190123222502

200123222502

210123222502

220123222502

230123222502

240123222502

250123222502

后台:

260123222502

270123222502

280123222502

300123222502

310123222502

320123222502

330123222502

340123222502

技术框架

SpringBoot SpringMVC MyBatis FreeMarker JWT Redis

基于javaweb的SpringBoot+MyBatis在线商城水果蔬菜商城果蔬商城(前台、后台)(java+springboot+ssm+freemarker+mysql+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
    }

/**
* 打印到浏览器上下载
*
* @param response
* @param file
*/
public void writefile(HttpServletResponse response, File file) {
ServletOutputStream sos = null;
FileInputStream aa = null;
try {
aa = new FileInputStream(file);
sos = response.getOutputStream();
// 读取文件问字节码
byte[] data = new byte[(int) file.length()];
IOUtils.readFully(aa, data);
// 将文件流输出到浏览器
IOUtils.write(data, sos);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
sos.close();
aa.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.demo.controller.admin;

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

/**
* 商品添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model) {
model.addAttribute("productCategoryList", productCategoryMapper.selectAll());
return "admin/product/add";
}

/**
* 商品编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,Long id) {
Product selectByPrimaryKey = productMapper.selectByPrimaryKey(id);
if(selectByPrimaryKey == null) {
return "error/404";
}
model.addAttribute("productCategoryList", productCategoryMapper.selectAll());
model.addAttribute("Product", selectByPrimaryKey);
return "admin/product/edit";
}


/**
* 添加商品操作处理
* @param product
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> add(Product product){
return productService.add(product);
}


/**
* 编辑商品操作处理
* @param product
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public ResponseVo<Boolean> edit(Product product){
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("/upload")
@Controller
public class UploadController {

private String uploadPhotoSufix = ".jpg,.png,.gif,.jpeg";

private long uploadPhotoMaxSize = 10240; //大小1024KB

private String uploadPhotoPath = System.getProperty("user.dir") + "/src/main/resources/upload/photo/";

private long uploadAttachmentMaxSize = 204800; //大小204800KB

private String uploadAttachmentPath = System.getProperty("user.dir") + "/src/main/resources/upload/attachment/";

private Logger log = LoggerFactory.getLogger(UploadController.class);

@Autowired
private AttachmentMapper attachmentMapper;

/**
* 图片统一上传类
*
* @param photo
* @return
*/
@RequestMapping(value = "/upload_photo", method = RequestMethod.POST)
@ResponseBody
public ResponseVo<String> uploadPhoto(@RequestParam(name = "photo", required = true) MultipartFile photo) {
//判断文件类型是否是图片
String originalFilename = photo.getOriginalFilename();
//获取文件后缀
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
if (!uploadPhotoSufix.contains(suffix.toLowerCase())) {
return ResponseVo.errorByMsg(CodeMsg.UPLOAD_PHOTO_SUFFIX_ERROR);
}
//photo.getSize()单位是B
if (photo.getSize() / 1024 > uploadPhotoMaxSize) {
CodeMsg codeMsg = CodeMsg.UPLOAD_PHOTO_ERROR;
codeMsg.setMsg("图片大小不能超过" + (uploadPhotoMaxSize / 1024) + "M");
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
	model.addAttribute("onThirdMenus", menuService.getThirdMenus(allMenusByStateAndPrimaryKeys).getData());
model.addAttribute("parentMenu", menuMapper.selectByPrimaryKey(selectByPrimaryKey.getParentId()));
model.addAttribute("currentMenu", selectByPrimaryKey);
return "admin/menu/index";
}

/**
* 菜单添加图标页面
* @param model
* @return
*/
@RequestMapping(value="/icon",method=RequestMethod.GET)
public String icon(Model model) {
return "admin/menu/icon";
}

/**
* 菜单添加页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model) {
List<Menu> allMenus = menuMapper.selectAll();
model.addAttribute("FirstMenus",menuService.getFirstMenus(allMenus).getData());
return "admin/menu/add";
}

/**
* 菜单编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,Integer id) {
Menu selectByPrimaryKey = menuMapper.selectByPrimaryKey(id);
if(selectByPrimaryKey == null) {
return "error/404";
}
List<Menu> allMenus = menuMapper.selectAll();
model.addAttribute("FirstMenus",menuService.getFirstMenus(allMenus).getData());
model.addAttribute("SecondMenus",menuService.getSecondMenus(allMenus).getData());
model.addAttribute("editMenu",selectByPrimaryKey);
return "admin/menu/edit";
}

/**
* 菜单添加按钮页面
* @param model
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



/**
* 公用的上传类
*/
@RequestMapping("/upload")
@Controller
public class UploadController {

private String uploadPhotoSufix = ".jpg,.png,.gif,.jpeg";

private long uploadPhotoMaxSize = 10240; //大小1024KB

private String uploadPhotoPath = System.getProperty("user.dir") + "/src/main/resources/upload/photo/";

private long uploadAttachmentMaxSize = 204800; //大小204800KB

private String uploadAttachmentPath = System.getProperty("user.dir") + "/src/main/resources/upload/attachment/";

private Logger log = LoggerFactory.getLogger(UploadController.class);

@Autowired
private AttachmentMapper attachmentMapper;

/**
* 图片统一上传类
*
* @param photo
* @return
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        } finally {
try {
sos.close();
aa.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.demo.controller.admin;




/**
* 后台管理系统邮箱控制器

*
*/


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