基于javaweb的SSM农产品商城管理系统(java+ssm+jsp+jquery+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

400923571103

410923571103

430923571103

440923571103

450923571103

460923571103

基于javaweb的SSM农产品商城管理系统(java+ssm+jsp+jquery+mysql)

项目介绍

本项目分为普通用户与管理员两种角色;

管理员角色包含以下功能: 管理员登录,用户管理,一级分类管理,二级分类管理,农产品管理,订单管理,留言管理,公告管理等功能。

用户角色包含以下功能: 查看首页,用户登录,提交留言,查看商品详情,加入购物车,确认订单,查看我的订单,修改密码等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目; 6.数据库:MySql 5.7等版本均可;

技术栈

  1. 后端:Spring springmvc mybatis

  2. 前端:JSP+css+javascript+jQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2.使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat

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


@Controller
public class indexController {
@Autowired
private CategoryService categoryService;
@Autowired
private ProductService productService;

@RequestMapping("/index")
public String index(Model model,HttpServletRequest request) throws Exception {
//查询一级分类
List<Category> cList = categoryService.findCategory();
request.getSession().getServletContext().setAttribute("cList",cList);
// model.addAttribute("cList", cList);
//查询热门商品
List<Product> hList= productService.findHotProduct();
model.addAttribute("hList", hList);
//查询最新商品
List<Product> nList = productService.findNewProduct();
model.addAttribute("nList", nList);

//滚动图片专用,最多显示3个商品
List<Product> sList;
if(hList.size()>3)
{
sList = new ArrayList<Product>();
sList.add(hList.get(0));
sList.add(hList.get(1));
sList.add(hList.get(2));
model.addAttribute("sList", sList);
}
else
{
model.addAttribute("sList", hList);
}

return "index";
}

@RequestMapping("/about")
public String about(Model model,HttpServletRequest request) throws Exception {
return "about";
}

@RequestMapping("/contact")
public String contact(Model model,HttpServletRequest request) throws Exception {
return "contact";
}

@RequestMapping("/delivery")
public String delivery(Model model,HttpServletRequest request) throws Exception {
return "delivery";
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
		char c = words.charAt(index);
sb.append(c);
// 将c 输出到图片
graphics2d.rotate(theta, x, 20);
graphics2d.drawString(String.valueOf(c), x, 20);
graphics2d.rotate(-theta, x, 20);
x += 30;
}

// 将生成的字母存入到session中
request.getSession().setAttribute("checkcode", sb.toString());
System.out.println(sb.toString());
// 步骤五 绘制干扰线
graphics.setColor(getRandColor(160, 200));
int x1;
int x2;
int y1;
int y2;
for (int i = 0; i < 30; i++) {
x1 = random.nextInt(width);
x2 = random.nextInt(12);
y1 = random.nextInt(height);
y2 = random.nextInt(12);
graphics.drawLine(x1, y1, x1 + x2, x2 + y2);
}

// 将上面图片输出到浏览器 ImageIO
graphics.dispose();// 释放资源
ImageIO.write(bufferedImage, "jpg", response.getOutputStream());
}

private Color getRandColor(int fc, int bc) {
// 取其随机颜色
Random random = new Random();
if (fc > 255) {
fc = 255;
}
if (bc > 255) {
bc = 255;
}
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
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
	public String regist() {
return "regist";
}

@RequestMapping("/userRegist")
public String userRegist(Model model, HttpServletRequest request,
@Validated User user, BindingResult bindingResult,
@RequestParam String checkImg) throws Exception {
if (bindingResult.hasErrors()) {
List<ObjectError> errors =bindingResult.getAllErrors();
List<String> list = new ArrayList<>();
for (ObjectError objectError : errors) {
String str = new String(objectError.getDefaultMessage()
.getBytes("ISO-8859-1"), "gbk");
list.add(str);
}
model.addAttribute("errors", list);
return "regist";
}
// 查看验证码
String sessionCode = (String) request.getSession().getAttribute(
"checkcode");
// System.out.println("adadadad" + sessionCode);
if (!sessionCode.equalsIgnoreCase(checkImg)) {
// model.addAttribute("message", "验证码错误请重新注册");
throw new zdyException("验证码错误请重新注册");
}
// 开始写入数据库
userService.saveUser(user);
//model.addAttribute("message", "注册成功请去邮箱激活");
model.addAttribute("message", "注册成功请登录");
return "msg";
}

@RequestMapping("/activeUser")
public String activeUser(@RequestParam String code,Model model) throws zdyException,Exception {
/*
* 根据传递激活码进行用户查询. 如果用户不为空: 修改用户状态 改为1 如果用户为空: 激活码被篡改了.
*/
User activeUser = userService.findByCode(code);
if(activeUser==null){
// model.addAttribute("message", "激活码被篡改了,请重新注册");
throw new zdyException("激活码被篡改了,请重新注册");
}
activeUser.setState(1);
activeUser.setCode(null);
userService.activeUser(activeUser);
model.addAttribute("message", "激活码成功");
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
	return "login";
}

// 用户登录
@RequestMapping("/userLogin")
public String userLogin(HttpServletRequest request,
@RequestParam String checkImg, User user, Model model)
throws zdyException, Exception {
String sessionCode = (String) request.getSession().getAttribute(
"checkcode");
if (!sessionCode.equalsIgnoreCase(checkImg)) {
//model.addAttribute("message", "验证码输入错误请重新注册");
//throw new zdyException("验证码输入错误请重新注册");
request.getSession().setAttribute("message", "验证码输入错误请重新注册");
return "redirect:login.action";
}
User loginUser = userService.loginFindByUnameAndPwd(user.getUsername(),
user.getPassword());
if (loginUser == null) {
//model.addAttribute("message", "密码输入错误请重新登陆");
request.getSession().setAttribute("message", "密码输入错误请重新登陆");
//throw new zdyException("密码输入错误请重新登陆");
return "redirect:login.action";
}
request.getSession().setAttribute("loginUser", loginUser);
request.getSession().removeAttribute("message");
return "redirect:index.action";
}

// 用户退出
@RequestMapping("userLogout")
public String userLogout(HttpServletRequest request,
HttpServletResponse response, Model model) {
request.getSession().removeAttribute("loginUser");
response.setHeader("content-type", "text/html;charset=UTF-8");
response.setHeader("refresh", "5;url=/shop/index.action");
model.addAttribute("message", "退出成功,系统将在5秒之后跳转到首页......");
return "msg";
}

//进入管理员页面
@RequestMapping("/admin")
public String AdminIndex(){
return "admin/index";
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("/updateState")
public String updateState(@RequestParam int oid ) throws Exception {
orderService.updateOrderStatus(oid, 3);
return "redirect:myOrder.action?page=1";
}
}
package com.shop.controller;




@Controller
public class checkImgController {
@RequestMapping("checkImg")
public void checkImg(HttpServletRequest request ,HttpServletResponse response) throws IOException {

int width = 120;
int height = 30;

// 步骤一 绘制一张内存中图片
BufferedImage bufferedImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);

// 步骤二 图片绘制背景颜色 ---通过绘图对象
Graphics graphics = bufferedImage.getGraphics();// 得到画图对象 --- 画笔
// 绘制任何图形之前 都必须指定一个颜色
graphics.setColor(getRandColor(200, 250));
graphics.fillRect(0, 0, width, height);
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/adminOrder_updateState")
public String adminOrder_updateState(@RequestParam int oid, @RequestParam int status, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}

orderService.updateOrderStatus(oid, status);

return "redirect:/admin/adminOrder_findAllByPage.action?page=1";
}

//后台留言管理
@RequestMapping("/admin/adminMessage_findAllByPage")
public String adminMessage_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}

PageBean<Message> pageBean = messageService.findAllMessageByPage(page);
model.addAttribute("pageBean", pageBean);

return "admin/message/list";
}

@RequestMapping("/admin/adminMessage_delete")
public String adminOrder_updateState(@RequestParam int messageid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}

messageService.deleteMessage(messageid);

return "redirect:/admin/adminMessage_findAllByPage.action?page=1";
}


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