├── AdminProductController.java ├── README.md ├── 用户首页.png ├── 登陆页面.png └── 管理员页面.png /AdminProductController.java: -------------------------------------------------------------------------------- 1 | package com.dmh.web.admin; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.domain.PageRequest; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.*; 9 | import org.springframework.web.multipart.MultipartFile; 10 | 11 | import com.dmh.entity.Classification; 12 | import com.dmh.entity.Product; 13 | import com.dmh.entity.pojo.ResultBean; 14 | import com.dmh.service.ClassificationService; 15 | import com.dmh.service.ProductService; 16 | import com.dmh.utils.FileUtil; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | import javax.servlet.http.HttpServletResponse; 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.net.URLEncoder; 23 | import java.nio.file.Files; 24 | import java.nio.file.Paths; 25 | import java.util.Date; 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | @Controller 30 | @RequestMapping("/admin/product") 31 | public class AdminProductController { 32 | @Autowired 33 | private ProductService productService; 34 | @Autowired 35 | private ClassificationService classificationService; 36 | 37 | @RequestMapping("/toList.html") 38 | public String toList() { 39 | return "admin/product/list"; 40 | } 41 | 42 | @RequestMapping("/toAdd.html") 43 | public String toAdd() { 44 | return "admin/product/add"; 45 | } 46 | 47 | @RequestMapping("/toEdit.html") 48 | public String toEdit(int id, Map map) { 49 | Product product = productService.findById(id); 50 | Classification classification = classificationService.findById(product.getCsid()); 51 | product.setCategorySec(classification); 52 | map.put("product", product); 53 | return "admin/product/edit"; 54 | } 55 | 56 | @ResponseBody 57 | @RequestMapping("/list.do") 58 | public ResultBean> listProduct(int pageindex, 59 | @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) { 60 | Pageable pageable = new PageRequest(pageindex, pageSize, null); 61 | List list = productService.findAll(pageable).getContent(); 62 | return new ResultBean<>(list); 63 | } 64 | 65 | @ResponseBody 66 | @RequestMapping("/getTotal") 67 | public ResultBean getTotal() { 68 | Pageable pageable = new PageRequest(1, 15, null); 69 | int total = (int) productService.findAll(pageable).getTotalElements(); 70 | return new ResultBean<>(total); 71 | } 72 | 73 | @RequestMapping("/del.do") 74 | @ResponseBody 75 | public ResultBean del(int id) { 76 | productService.delById(id); 77 | return new ResultBean<>(true); 78 | } 79 | 80 | @RequestMapping(method = RequestMethod.POST, value = "/add.do") 81 | public void add(MultipartFile image, 82 | String title, 83 | Double marketPrice, 84 | Double shopPrice, 85 | int isHot, 86 | String desc, 87 | int csid, 88 | HttpServletRequest request, 89 | HttpServletResponse response) throws Exception { 90 | Product product = new Product(); 91 | product.setTitle(title); 92 | product.setMarketPrice(marketPrice); 93 | product.setShopPrice(shopPrice); 94 | product.setDesc(desc); 95 | product.setIsHot(isHot); 96 | product.setCsid(csid); 97 | product.setPdate(new Date()); 98 | String imgUrl = FileUtil.saveFile(image); 99 | product.setImage(imgUrl); 100 | int id = productService.create(product); 101 | if (id <= 0) { 102 | request.setAttribute("message", "添加失败!"); 103 | request.getRequestDispatcher("toAdd.html").forward(request, response); 104 | } else { 105 | request.getRequestDispatcher("toEdit.html?id=" + id).forward(request, response); 106 | } 107 | } 108 | 109 | 110 | @RequestMapping(method = RequestMethod.POST, value = "/update.do") 111 | public void update(int id, 112 | String title, 113 | Double marketPrice, 114 | Double shopPrice, 115 | String desc, 116 | int csid, 117 | int isHot, 118 | MultipartFile image, 119 | HttpServletRequest request, 120 | HttpServletResponse response) throws Exception { 121 | Product product = productService.findById(id); 122 | product.setTitle(title); 123 | product.setMarketPrice(marketPrice); 124 | product.setShopPrice(shopPrice); 125 | product.setDesc(desc); 126 | product.setIsHot(isHot); 127 | product.setCsid(csid); 128 | product.setPdate(new Date()); 129 | String imgUrl = FileUtil.saveFile(image); 130 | if (StringUtils.isNotBlank(imgUrl)) { 131 | product.setImage(imgUrl); 132 | } 133 | boolean flag = false; 134 | try { 135 | productService.update(product); 136 | flag = true; 137 | } catch (Exception e) { 138 | throw new Exception(e); 139 | } 140 | if (!flag) { 141 | request.setAttribute("message", "更新失败!"); 142 | } 143 | response.sendRedirect("toList.html"); 144 | } 145 | 146 | @RequestMapping(method = RequestMethod.GET, value = "/img/{filename:.+}") 147 | public void getImage(@PathVariable(name = "filename", required = true) String filename, 148 | HttpServletResponse res) throws IOException { 149 | File file = new File("file/" + filename); 150 | if (file != null && file.exists()) { 151 | res.setHeader("content-type", "application/octet-stream"); 152 | res.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); 153 | res.setContentLengthLong(file.length()); 154 | Files.copy(Paths.get(file.toURI()), res.getOutputStream()); 155 | } 156 | } 157 | 158 | 159 | } 160 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # java-kaoshi 2 | 基于springboot+vue实现的java在线考试系统,系统自动生成试卷,有用户、教师、管理员三种角色 。用户功能:登录注册、个人中心编辑、搜索功能、在线考试、在线留言等;教师功能:评阅试卷、编辑试卷试题等;管理员功能:考试管理、题库管理、成绩查询、学生管理、留言管理、教师管理。系统页面设计良好、内容丰富、功能齐全,适合用做课设和毕设等学习。详细请点击仓库名称进入查看网站前后台图片,感兴趣的小伙伴请联系Q:2364821220 3 | # 网站截图 4 | ![image](https://github.com/hzl0898/java-kaoshi/blob/main/用户首页.png) 5 | ![image](https://github.com/hzl0898/java-kaoshi/blob/main/管理员页面.png) 6 | -------------------------------------------------------------------------------- /用户首页.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hzl0898/java-kaoshi/352569e85eaf9f8ddb004219925737d42d5a7b1e/用户首页.png -------------------------------------------------------------------------------- /登陆页面.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hzl0898/java-kaoshi/352569e85eaf9f8ddb004219925737d42d5a7b1e/登陆页面.png -------------------------------------------------------------------------------- /管理员页面.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hzl0898/java-kaoshi/352569e85eaf9f8ddb004219925737d42d5a7b1e/管理员页面.png --------------------------------------------------------------------------------