——————————DescriptionStart——————————
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明





基于javaweb的SSM+Maven二手图书商城平台(java+ssm+jsp+js+jquery+mysql)
项目介绍
用户角色包含以下功能: 用户登录,查看商品详情,按分类查看,查看我的书架,上传二手书等功能。 PS:这个没有管理员角色。
环境需要
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项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jquery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ssm_sebook_market 登录
——————————CodeStart——————————
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
| mav.addObject("categories",categories); return mav; }
@RequestMapping("/goBookStore.do") public ModelAndView goBookStore(Page page,Category category){ ModelAndView mav = new ModelAndView("bookStore"); Map<Integer, String> categories = categoryService.listByMap(); Category curCategory = category.getId() !=0?categoryService.get(category.getId()):new Category(); String categoryName = curCategory.getName() == null?"所有二手书":curCategory.getName(); int total = bookService.count(); page.calculateEnd(total); if (page.getStart() < 0) { page.setStart(0); }else if (page.getStart() > total){ page.setEnd(page.getEnd()); } PageHelper.offsetPage(page.getStart(),16); List<Book> books = curCategory.getId() == 0?bookService.listByBookType(1):bookService.listByCategoryId(1,curCategory.getId()); mav.addObject("categoryName",categoryName); mav.addObject("books",books); mav.addObject("categories",categories); return mav; }
@RequestMapping("/goAskBookStore.do") public ModelAndView goAskBookStore(Page page){ ModelAndView mav = new ModelAndView("askBookStore"); int total = bookService.count(); page.calculateEnd(total); if (page.getStart() < 0) { page.setStart(0); }else if (page.getStart() > total){ page.setEnd(page.getEnd()); } PageHelper.offsetPage(page.getStart(),16); List<Book> books = bookService.listByBookType(0); mav.addObject("books",books); return mav; }
} package com.daniel.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 49 50 51 52
| private BookImageService bookImageService; @Autowired private CategoryService categoryService;
private static final Logger log = Logger.getLogger(BookController.class);
@RequestMapping(value = "/{id}",method = RequestMethod.GET) public ModelAndView getBookDetail(@PathVariable("id") String id) { ModelAndView mav = new ModelAndView("bookDetail"); int intId = Integer.parseInt(id); Book curBook = bookService.get(intId); curBook.setBookImage(bookImageService.getByBookId(intId)); curBook.setUser(userService.get(bookService.getUserId(intId))); mav.addObject("book",curBook); return mav; }
@RequestMapping(value = "",method = RequestMethod.POST) public Result uploadSell(HttpServletRequest request,Book book, @RequestParam(value = "image" , required = false) MultipartFile file){ User user = (User) request.getSession().getAttribute("user"); try { if(file != null && book != null){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long time = System.currentTimeMillis(); String timeStr= sdf.format(time); book.setDate(timeStr); book.setUser(user); bookService.add(book); BookImage bookImage = new BookImage(); bookImage.setBook(book); bookImageService.add(bookImage); String imageName = bookImage.getId()+".jpg"; String imagePath = request.getServletContext().getRealPath("/img/book-list/article/"); File filePath = new File(imagePath,imageName); if (!filePath.getParentFile().exists()){ filePath.getParentFile().mkdir(); }
|
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
| @RequestMapping("/books") public class BookController {
@Autowired private UserService userService; @Autowired private BookService bookService; @Autowired private BookImageService bookImageService; @Autowired private CategoryService categoryService;
private static final Logger log = Logger.getLogger(BookController.class);
@RequestMapping(value = "/{id}",method = RequestMethod.GET) public ModelAndView getBookDetail(@PathVariable("id") String id) { ModelAndView mav = new ModelAndView("bookDetail"); int intId = Integer.parseInt(id); Book curBook = bookService.get(intId); curBook.setBookImage(bookImageService.getByBookId(intId)); curBook.setUser(userService.get(bookService.getUserId(intId))); mav.addObject("book",curBook); return mav; }
@RequestMapping(value = "",method = RequestMethod.POST) public Result uploadSell(HttpServletRequest request,Book book, @RequestParam(value = "image" , required = false) MultipartFile file){ User user = (User) request.getSession().getAttribute("user"); try { if(file != null && book != null){
|
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
| }
private void addDoc(IndexWriter writer,Book book) throws IOException { Document doc = new Document(); doc.add(new TextField("id",book.getId()+"",Field.Store.YES)); doc.add(new TextField("name",book.getName(),Field.Store.YES)); writer.addDocument(doc); }
} package com.daniel.controller;
@RestController @RequestMapping("/users") public class UserController {
@Autowired private UserService userService;
private static final Logger log = Logger.getLogger(UserController.class);
@RequestMapping("") public ModelAndView login() { return new ModelAndView("login"); }
@RequestMapping(value = "/sessions",method = RequestMethod.POST) @ResponseBody public Result checkLogin(@RequestBody User user, HttpServletRequest request) { boolean flag = userService.checkUser(user);
|
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
| private UserService userService;
private static final Logger log = Logger.getLogger(UserController.class);
@RequestMapping("") public ModelAndView login() { return new ModelAndView("login"); }
@RequestMapping(value = "/sessions",method = RequestMethod.POST) @ResponseBody public Result checkLogin(@RequestBody User user, HttpServletRequest request) { boolean flag = userService.checkUser(user); log.info("request: user/login , user: " + user.toString()); if (flag) { Map data = new HashMap(); data.put("currentUser",user); request.getSession().setAttribute("user",userService.getByStudentid(user.getStudentid())); return ResultGenerator.genSuccessResult(data); }else { return ResultGenerator.genFailResult("学号或密码输入错误!"); } }
@RequestMapping(value = "/sessions",method = RequestMethod.DELETE) public Result logout(HttpServletRequest request) { request.getSession().removeAttribute("user"); return ResultGenerator.genSuccessResult(); } } package com.daniel.interceptor;
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=461122512008200nd
https://javayms.pages.dev?id=461122512008200nd