基于javaweb的在线美食分享推荐系统(java+ssm+jsp+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的在线美食分享推荐系统(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.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
使用说明
登录管理控制层:
@Controller
public class loginController {
@Autowired
private UserService userService;
@RequestMapping(“login”)
public String login() {
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”;
//admin/adminUser_login.action
//adminUser_login管理员登录
@RequestMapping(“/admin/adminUser_login”)
public String adminUser_login(HttpServletRequest request,Model model,@RequestParam String username,@RequestParam String password) throws Exception{
Adminuser adminuserLogin = userService.adminUser_login(username,password);
System.out.println(username);
System.out.println(password);
if(adminuserLogin == null){
model.addAttribute(“message”, “改用户未被授予管理员身份!”);
return “admin/index”;
request.getSession().setAttribute(“adminuserLogin”, adminuserLogin);
// model.addAttribute(“adminuserLogin”, adminuserLogin);
return “admin/home”;
管理员管理控制层:
@Controller
public class AdminController {
@Autowired
private UserService userService;
@Autowired
public CategoryService categoryService;
@Autowired
public CategorySecondService categorySecondService;
@Autowired
public ProductService productService;
@Autowired
private OrderService orderService;
@Autowired
private MessageService messageService;
@RequestMapping(“/admin/admin_findAll”)
public String admin_findAll(Model model, HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
List userList = userService.admin_findAll();
model.addAttribute(“userList”, userList);
return “admin/user/list”;
@RequestMapping(“/admin/adminCategory_findAll”)
public String adminCategory_findAll(Model model, HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
List categoryList = categoryService.adminbFindCategory();
/*for (Category category : categoryList) {
System.out.println(category.getCname());
}*/
model.addAttribute(“categoryList”, categoryList);
return “admin/category/list”;
@RequestMapping(“/admin/adminCategory_add”)
public String adminCategory_add(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
// List categoryList = categoryService.adminbFindCategory();
// model.addAttribute(“categoryList”, categoryList);
return “admin/category/add”;
@RequestMapping(“/admin/adminCategory_save”)
public String adminCategory_save(@RequestParam String cname,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Category addCategory = new Category();
addCategory.setCname(cname);
categoryService.addCategory(addCategory);
return “redirect:/admin/adminCategory_findAll.action”;
@RequestMapping(“/admin/adminCategory_edit”)
public String adminCategory_delete(@RequestParam int cid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Category existCategory = categoryService.findCategory(cid);
model.addAttribute(“existCategory”, existCategory);
return “admin/category/edit”;
@RequestMapping(“/admin/adminCategory_update”)
public String adminCategory_update(@RequestParam int cid,
@RequestParam String cname,HttpServletRequest request) {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Category category = new Category();
category.setCid(cid);
category.setCname(cname);
categoryService.adminCategory_update(category);
return “redirect:/admin/adminCategory_findAll.action”;
@RequestMapping(“/admin/adminCategory_delete”)
public String adminCategory_delete(@RequestParam int cid,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
categorySecondService.adminCategorySecond_deleteByCid(cid);
categoryService.deleteCategoryByCid(cid);
return “redirect:/admin/adminCategory_findAll.action”;
// admin 的二级分类的管理
@RequestMapping(“/admin/adminCategorySecond_findAllByPage”)
public String adminCategorySecond_findAllByPage(@RequestParam int page,Model model,HttpServletRequest request) {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
PageBean csPageBean = categorySecondService
.adminCategorySecond_findAllByPage(page);
/*List list = csPageBean.getList();
for (Categorysecond categorysecond : list) {
System.out.println(categorysecond.getCsname());
}*/
model.addAttribute(“csPageBean”, csPageBean);
return “admin/categorysecond/list”;
@RequestMapping(“admin/adminCategorySecond_addPage”)
public String adminCategorySecond_addPage(Model model,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
List categoryList = categoryService.adminbFindCategory();
model.addAttribute(“categoryList”, categoryList);
return “admin/categorysecond/add”;
@RequestMapping(“admin/adminCategorySecond_save”)
public String adminCategorySecond_save(@RequestParam String csname,@RequestParam int cid,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Categorysecond categorysecond = new Categorysecond();
categorysecond.setCsname(csname);
categorysecond.setCid(cid);
categorySecondService.adminCategorySecond_save(categorysecond);
return “redirect:/admin/adminCategorySecond_findAllByPage.action?page=1”;
@RequestMapping(“admin/adminCategorySecond_edit”)
public String adminCategorySecond_edit(@RequestParam int csid,Model model,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Categorysecond findByCsid = categorySecondService.findByCsid(csid);
model.addAttribute(“findByCsid”, findByCsid);
return “admin/categorysecond/edit”;
@RequestMapping(“admin/adminCategorySecond_update”)
public String adminCategorySecond_update(@RequestParam String csname,@RequestParam int csid,HttpServletRequest request){
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Categorysecond categorysecond = new Categorysecond();
categorysecond.setCsname(csname);
categorysecond.setCsid(csid);
categorySecondService.adminCategorySecond_update(categorysecond);
return “redirect:/admin/adminCategorySecond_findAllByPage.action?page=1”;
@RequestMapping(“admin/adminCategorySecond_delete”)
public String adminCategorySecond_delete(@RequestParam int csid,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
categorySecondService.adminCategorySecond_delete(csid);
return “redirect:/admin/adminCategorySecond_findAllByPage.action?page=1”;
//admin的商品管理
@RequestMapping(“/admin/adminProduct_findAllByPage”)
public String adminProduct_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 allProPageBean = productService.findAllProduct(page);
model.addAttribute(“allProPageBean”, allProPageBean);
return “admin/product/list”;
@RequestMapping(“/admin/adminProduct_addPage”)
public String adminProduct_addPage(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
//查询出所有的二级分类
List cslist = categorySecondService.findAll();
/*for (Categorysecond categorysecond : cslist) {
System.out.println(categorysecond.getCsname());
}*/
model.addAttribute(“cslist”, cslist);
return “admin/product/add”;
@RequestMapping(“/admin/adminProduct_save”)
public String adminProduct_save(Product product,HttpServletRequest request,MultipartFile file) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
product.setPdate(new Date());
// 上传图片
if (file != null) {
String path = request.getServletContext().getRealPath(
“/products”);
String uploadFileName = file.getOriginalFilename();
String fileName = UUIDUtiils.getUUID()+uploadFileName;
File diskFile = new File(path + “//” + fileName);
file.transferTo(diskFile);
product.setImage(“products/” + fileName);
System.out.println(product.getImage());
productService.adminProduct_save(product);
return “redirect:/admin/adminProduct_findAllByPage.action?page=1”;
@RequestMapping(“admin/adminProduct_deletecs”)
public String adminProduct_deletecs(@RequestParam int pid,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
productService.adminProduct_deletecs(pid);
return “redirect:/admin/adminProduct_findAllByPage.action?page=1”;
/**
编辑商品
@param pid
@param model
@param request
@return
@throws Exception
*/
@RequestMapping(“admin/adminProduct_edit”)
public String adminProduct_edit(@RequestParam int pid,Model model,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Product product = productService.finbProductByPid(pid);
model.addAttribute(“findByPid”, product);
//查询出所有的二级分类
List cslist = categorySecondService.findAll();
model.addAttribute(“cslist”, cslist);
return “admin/product/edit”;
@RequestMapping(“/admin/adminProduct_update”)
public String adminProduct_update(Product product,HttpServletRequest request,MultipartFile file) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
product.setPdate(new Date());
// 上传图片
if (file != null) {
String path = request.getServletContext().getRealPath(
“/products”);
String uploadFileName = file.getOriginalFilename();
String fileName = UUIDUtiils.getUUID()+uploadFileName;
File diskFile = new File(path + “//” + fileName);
file.transferTo(diskFile);
product.setImage(“products/” + fileName);
productService.adminProduct_update(product);
return “redirect:/admin/adminProduct_findAllByPage.action?page=1”;
/** 订单管理模块 **/
@RequestMapping(“/admin/adminOrder_findAllByPage”)
public String adminOrder_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 allProPageBean = orderService.findAllOrderByStateAndPage(page);
model.addAttribute(“pageBean”, allProPageBean);
return “admin/order/list”;
//adminOrder_findByState
@RequestMapping(“/admin/adminOrder_findByState”)
public String adminOrder_findByState(@RequestParam int page,@RequestParam int state, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
PageBean allProPageBean = orderService.findAllOrderByStateAndPage(state,page);
model.addAttribute(“pageBean”, allProPageBean);
return “admin/order/list”;
//订单详情
//adminOrder_findOrderItem
@RequestMapping(“/admin/adminOrder_findOrderItem”)
public String adminOrder_findOrderItem(@RequestParam int oid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute(“adminuserLogin”);
if(adminuserLogin==null){
request.getSession().setAttribute(“message”,“对不起您还没有登录”);
return “admin/index”;
Orders orderItems = orderService.findOrderByOid(oid);
model.addAttribute(“orderItems”, orderItems);
return “admin/order/list”;
//更新订单状态
@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 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”;
留言管理控制层:
@Controller
public class messageController {
@Autowired
private MessageService messageService;
@RequestMapping(“/saveMessage”)
public String saveMessage(@RequestParam String messageinfo,HttpServletRequest request,Model model) throws Exception {
Message Message = new Message();
User loginUser = (User) request.getSession().getAttribute(“loginUser”);
if(loginUser==null){
model.addAttribute(“message”, “对不起您还没有登录”);
return “msg”;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Message.setMessage(messageinfo);
Message.setUid(loginUser.getUid());
Message.setMessagedate(sdf.format(new Date()));
messageService.insertMessage(Message);
request.getSession().setAttribute(“Message”, Message);
return “redirect:/messageList.action?page=1”;
// 显示留言板全部留言
@RequestMapping(“/messageList”)
public String messageList(@RequestParam int page, Model model,
HttpServletRequest request) throws Exception {
PageBean pageBean = messageService.findAllMessageByPage(page);
model.addAttribute(“pageBean”, pageBean);
return “messageList”;