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










基于javaweb的SSM新闻发布系统(java+ssm+mysql+jsp)
——————————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
| user.setId(getIpAddr(request)); newsComment.setCreateBy(user); newsCommentService.save(newsComment); return "redirect:"+"/demo/front/look?id="+newsId; } private String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if(ip == null || ip.length() == 0 ||"unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if(ip == null || ip.length() == 0 ||"unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if(ip == null || ip.length() == 0 ||"unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; } }
@Controller @RequestMapping(value = "/system/menu") public class MenuController {
|
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
| }
public Cell addCell(Row row, int column, Object val){ return this.addCell(row, column, val, 0, Class.class); }
public Cell addCell(Row row, int column, Object val, int align, Class<?> fieldType){ Cell cell = row.createCell(column); String cellFormatString = "@"; try { if(val == null){ cell.setCellValue(""); }else if(fieldType != Class.class){ cell.setCellValue((String)fieldType.getMethod("setValue", Object.class).invoke(null, val)); }else{ if(val instanceof String) { cell.setCellValue((String) val); }else if(val instanceof Integer) { cell.setCellValue((Integer) val); cellFormatString = "0"; }else if(val instanceof Long) { cell.setCellValue((Long) val); cellFormatString = "0"; }else if(val instanceof Double) { cell.setCellValue((Double) val); cellFormatString = "0.00"; }else if(val instanceof Float) { cell.setCellValue((Float) val); cellFormatString = "0.00"; }else if(val instanceof Date) { cell.setCellValue((Date) val); cellFormatString = "yyyy-MM-dd HH:mm"; }else { cell.setCellValue((String)Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(), "fieldtype."+val.getClass().getSimpleName()+"Type")).getMethod("setValue", Object.class).invoke(null, val)); } }
|
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
| * @param path * @return */ public static String upload(MultipartFile file, String path){ String fileName = file.getOriginalFilename();
File dest = new File(path + "/" + fileName); if(!dest.getParentFile().exists()){ dest.getParentFile().mkdir(); } try { file.transferTo(dest); return path + "/" + fileName; } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
public static String downLoad(String url, HttpServletRequest request,HttpServletResponse response){ String path=request.getRealPath("/"); String backuppath = path + url; response.reset(); response.setContentType("application/octet-stream; charset=utf-8"); response.setHeader("Content-Disposition", "attachment; filename="+backuppath); try { InputStream in = new FileInputStream(backuppath); OutputStream out = response.getOutputStream(); int b; while((b=in.read())!= -1) { out.write(b); } in.close(); out.close();
|
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
| public String list(SysDict sysDict, HttpServletRequest request, HttpServletResponse response, Model model) { PageInfo<SysDict> page = sysDictService.findPage(sysDict); model.addAttribute("pageInfo", page); return "/sys/sysDictList"; }
@RequestMapping(value = "form") public String form(SysDict sysDict, Model model) { model.addAttribute("sysDict", sysDict); return "/sys/sysDictForm"; }
@RequestMapping(value = "save") public String save(SysDict sysDict, Model model, RedirectAttributes redirectAttributes) { sysDictService.save(sysDict); return "redirect:"+"/demo/sysDict"; } @RequestMapping(value = "delete") public String delete(SysDict sysDict, RedirectAttributes redirectAttributes) { sysDictService.delete(sysDict); return "redirect:"+"/demo/sysDict"; }
}
|
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
| * @return 行对象 */ public Row addRow(){ return sheet.createRow(rownum++); }
public Cell addCell(Row row, int column, Object val){ return this.addCell(row, column, val, 0, Class.class); }
public Cell addCell(Row row, int column, Object val, int align, Class<?> fieldType){ Cell cell = row.createCell(column); String cellFormatString = "@"; try { if(val == null){ cell.setCellValue(""); }else if(fieldType != Class.class){ cell.setCellValue((String)fieldType.getMethod("setValue", Object.class).invoke(null, val)); }else{ if(val instanceof String) { cell.setCellValue((String) val); }else if(val instanceof Integer) { cell.setCellValue((Integer) val); cellFormatString = "0"; }else if(val instanceof Long) { cell.setCellValue((Long) val); cellFormatString = "0"; }else if(val instanceof Double) { cell.setCellValue((Double) val); cellFormatString = "0.00"; }else if(val instanceof Float) { cell.setCellValue((Float) val); cellFormatString = "0.00"; }else if(val instanceof Date) { cell.setCellValue((Date) val); cellFormatString = "yyyy-MM-dd HH:mm";
|
——————————PayStart——————————
项目链接:
https://javayms.github.io?id=282023232309201fc
https://javayms.pages.dev?id=282023232309201fc