From ca04d6ea9c72aa4d41d9bc105117b233eadf28d8 Mon Sep 17 00:00:00 2001 From: aim467 <709544711@qq.com> Date: Fri, 18 Jun 2021 22:51:41 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20.gitignore=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 +++++++++ WebRoot/WEB-INF/classes/applicationContext.xml | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d51ef34..e18fd6e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,12 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + + +# idea file +.idea +.settings +.project +.classpath +SSMBlogv2.iml +target \ No newline at end of file diff --git a/WebRoot/WEB-INF/classes/applicationContext.xml b/WebRoot/WEB-INF/classes/applicationContext.xml index 5f57b08..04cebef 100644 --- a/WebRoot/WEB-INF/classes/applicationContext.xml +++ b/WebRoot/WEB-INF/classes/applicationContext.xml @@ -19,7 +19,7 @@ - + @@ -83,4 +83,4 @@ class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> - \ No newline at end of file + From 37d46cb81ea1a3281dffdad0eec749f9e03a7984 Mon Sep 17 00:00:00 2001 From: aim467 <709544711@qq.com> Date: Fri, 18 Jun 2021 22:58:21 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/ArticleController.java | 48 ++++++++++++------------ src/controller/CategoryController.java | 16 ++++---- src/controller/CommentController.java | 22 +++++------ src/controller/LoginController.java | 2 +- src/controller/UploadfileController.java | 4 +- src/entity/Msg.java | 10 ++--- src/mapping/BlogMapper.java | 2 +- src/service/ArticleService.java | 18 ++++----- src/service/CommentService.java | 8 ++-- src/service/LoginService.java | 8 ++-- src/utils/MD5.java | 12 +++--- src/utils/Myutil.java | 4 +- src/utils/UploadUtil.java | 4 +- 13 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/controller/ArticleController.java b/src/controller/ArticleController.java index 3d3698a..08e36f7 100644 --- a/src/controller/ArticleController.java +++ b/src/controller/ArticleController.java @@ -33,7 +33,7 @@ public class ArticleController { @Autowired private ArticleService articleService; - // 返回文章列表,进行 分页 + // 杩斿洖鏂囩珷鍒楄〃锛岃繘琛 鍒嗛〉 @RequestMapping("/articles") @ResponseBody public Msg getArticlesList( @@ -45,7 +45,7 @@ public Msg getArticlesList( return Msg.success().add("pageInfo", pageInfo); } - // 获取分类信息 + // 鑾峰彇鍒嗙被淇℃伅 @RequestMapping(value="getCategoryName", method=RequestMethod.POST, produces="application/json") @ResponseBody public Msg getCategoryName() { @@ -55,13 +55,13 @@ public Msg getCategoryName() { map.put("category", list); msg.setCode(200); - msg.setMsg("返回分类名字!"); + msg.setMsg("杩斿洖鍒嗙被鍚嶅瓧锛"); msg.setExtend(map); return msg; } - // 后台新建博客文章,判断是否登陆,我用 ajax 请求无法跳转页面, - // 使用了window.location='${APP_PATH }/islogin'; 请求跳转 + // 鍚庡彴鏂板缓鍗氬鏂囩珷,鍒ゆ柇鏄惁鐧婚檰锛屾垜鐢 ajax 璇锋眰鏃犳硶璺宠浆椤甸潰锛 + // 浣跨敤浜唚indow.location='${APP_PATH }/islogin'; 璇锋眰璺宠浆 @RequestMapping(value="/islogin") public String newarticle(HttpServletRequest request, HttpServletResponse response) throws IOException { if(request.getSession().getAttribute("username") != null) { @@ -71,11 +71,11 @@ public String newarticle(HttpServletRequest request, HttpServletResponse respons return "admin/error"; } - // 新建文章 + // 鏂板缓鏂囩珷 @RequestMapping(value="/newarticle") public String editarticle(HttpServletRequest request, HttpServletResponse response) { - //得到 session 的值,判断是否已经登陆 + //寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 if(request.getSession().getAttribute("username") != null) { String username = request.getSession().getAttribute("username").toString(); if(username != null) { @@ -85,7 +85,7 @@ public String editarticle(HttpServletRequest request, HttpServletResponse respon return "admin/error"; } - // 保存 md 和 HTML 到数据库 + // 淇濆瓨 md 鍜 HTML 鍒版暟鎹簱 @RequestMapping(value = "saveArticle", method = RequestMethod.POST) public ModelAndView saveArticle( HttpServletRequest request, @@ -95,7 +95,7 @@ public ModelAndView saveArticle( ModelAndView view = new ModelAndView(); Map map = new HashMap(); - // 获取文章对应的 分类Id + // 鑾峰彇鏂囩珷瀵瑰簲鐨 鍒嗙被Id Integer categoryId = articleService.getCategoryId(request .getParameter("categoryName")); @@ -110,14 +110,14 @@ public ModelAndView saveArticle( blog.setCreatedtime(date); articleService.save(blog); - // 获得文章的标题,标题介绍,日期,分类等信息 - map.put("message", "新建文章成功!"); + // 鑾峰緱鏂囩珷鐨勬爣棰橈紝鏍囬浠嬬粛锛屾棩鏈燂紝鍒嗙被绛変俊鎭 + map.put("message", "鏂板缓鏂囩珷鎴愬姛锛"); view.setViewName("admin/newsuccess"); view.addObject("map", map); return view; } - // 编辑文章 + // 缂栬緫鏂囩珷 @RequestMapping("/edit") public String edit(@RequestParam(value="id", required=true, defaultValue="1") int id, HttpServletRequest request, HttpServletResponse response, Model model) { @@ -128,7 +128,7 @@ public String edit(@RequestParam(value="id", required=true, defaultValue="1") in return "admin/error"; } - // 保存修改文章 + // 淇濆瓨淇敼鏂囩珷 @RequestMapping(value="/updatearticle", method=RequestMethod.POST) public ModelAndView updatearticle(HttpServletRequest request, HttpServletResponse response,@RequestParam(value = "test-editormd-markdown-doc", required = false) String edmdDoc, @RequestParam(value = "editorhtml", required = false) String edmdHtml) { @@ -136,9 +136,9 @@ public ModelAndView updatearticle(HttpServletRequest request, HttpServletRespons String dateStr; Map map = new HashMap(); - // 获取隐藏域文章的 id + // 鑾峰彇闅愯棌鍩熸枃绔犵殑 id int id = Integer.parseInt(request.getParameter("id")); - // 获取文章对应的 分类Id + // 鑾峰彇鏂囩珷瀵瑰簲鐨 鍒嗙被Id Integer categoryId = articleService.getCategoryId(request .getParameter("categoryName")); @@ -159,15 +159,15 @@ public ModelAndView updatearticle(HttpServletRequest request, HttpServletRespons blog.setCreatedtime(date); articleService.update(blog); - // 获得文章的标题,标题介绍,日期,分类等信息 - map.put("message", "修改文章成功!"); + // 鑾峰緱鏂囩珷鐨勬爣棰橈紝鏍囬浠嬬粛锛屾棩鏈燂紝鍒嗙被绛変俊鎭 + map.put("message", "淇敼鏂囩珷鎴愬姛锛"); view.setViewName("admin/editsuccess"); view.addObject("map", map); return view; } - //通过 id 查找文章并返回 + //閫氳繃 id 鏌ユ壘鏂囩珷骞惰繑鍥 @RequestMapping("/getarticlebyid") @ResponseBody public Blog getarticlebyid(@RequestParam(value="id", defaultValue="1") int id) { @@ -176,7 +176,7 @@ public Blog getarticlebyid(@RequestParam(value="id", defaultValue="1") int id) { } - // 显示文章 + // 鏄剧ず鏂囩珷 @RequestMapping(value="showarticle", method=RequestMethod.GET) public String showarticle(@RequestParam(value="id", defaultValue="1")int id, Model model) { String mdString = articleService.getArticleMdStr(id); @@ -185,7 +185,7 @@ public String showarticle(@RequestParam(value="id", defaultValue="1")int id, Mod return "showarticle"; } - // 侧边栏阅读模式 + // 渚ц竟鏍忛槄璇绘ā寮 @RequestMapping(value="/showarticlecustomcontanier", method=RequestMethod.GET) public String showarticlecustomcontainer(HttpServletRequest request, HttpServletResponse response, Model model, @RequestParam(value="id", defaultValue="1")int id) { @@ -195,7 +195,7 @@ public String showarticlecustomcontainer(HttpServletRequest request, HttpServlet return "showarticlecustomcontanier"; } - // 删除文章 + // 鍒犻櫎鏂囩珷 @RequestMapping(value="/delete", method=RequestMethod.GET) public void delete(@RequestParam(value="id", required=true)int id,HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -206,14 +206,14 @@ public void delete(@RequestParam(value="id", required=true)int id,HttpServletReq } } - // 没有登陆的时候,就不能删除文章 + // 娌℃湁鐧婚檰鐨勬椂鍊欙紝灏变笉鑳藉垹闄ゆ枃绔 @RequestMapping("/deletenologin") public String deletenologin() { return "admin/error"; } /* - // 返回正常模式 + // 杩斿洖姝e父妯″紡 @RequestMapping(value="/backhtml", method=RequestMethod.POST) public String backhtml(HttpServletRequest request, HttpServletResponse response, Model model, @RequestParam(value="md", required=true)String md) { @@ -222,7 +222,7 @@ public String backhtml(HttpServletRequest request, HttpServletResponse response, return "showarticle"; }*/ - // 返回评论数最多的四篇文章 + // 杩斿洖璇勮鏁版渶澶氱殑鍥涚瘒鏂囩珷 @RequestMapping("/postarticle") @ResponseBody public Msg postarticle() { diff --git a/src/controller/CategoryController.java b/src/controller/CategoryController.java index 148cb81..2ba04e6 100644 --- a/src/controller/CategoryController.java +++ b/src/controller/CategoryController.java @@ -27,7 +27,7 @@ public class CategoryController { @Autowired private CategoryService categoryService; - // tags 返回标签(我把它理解为分类) + // tags 杩斿洖鏍囩锛堟垜鎶婂畠鐞嗚В涓哄垎绫伙級 @RequestMapping(value="/getTags",method=RequestMethod.GET) @ResponseBody public Msg getTags() { @@ -36,7 +36,7 @@ public Msg getTags() { } - // 分类的后台管理 + // 鍒嗙被鐨勫悗鍙扮鐞 @RequestMapping(value="/tagadmin") public String tagadmin(HttpServletRequest request, HttpServletResponse response) { String username = null; @@ -50,16 +50,16 @@ public String tagadmin(HttpServletRequest request, HttpServletResponse response) return "admin/tagadmin"; } - // 新建分类 + // 鏂板缓鍒嗙被 @RequestMapping(value="/newtag", method=RequestMethod.POST) public String newtag(@RequestParam(value="name", required=true) String name, @RequestParam(value="level", required=true)String level,Model model) { categoryService.newtag(name, level); - model.addAttribute("msg", "新建分类成功!"); + model.addAttribute("msg", "鏂板缓鍒嗙被鎴愬姛锛"); return "admin/newtagsuccess"; } - // 删除分类 + // 鍒犻櫎鍒嗙被 @RequestMapping(value="deletetag", method=RequestMethod.GET) @ResponseBody public Msg deletetag(HttpServletRequest request, HttpServletResponse response, @@ -69,10 +69,10 @@ public Msg deletetag(HttpServletRequest request, HttpServletResponse response, username = request.getSession().getAttribute("username").toString(); } if(username == null) { - return Msg.fail().add("msg", "你没有登陆"); + return Msg.fail().add("msg", "浣犳病鏈夌櫥闄"); } categoryService.deltag(id); - return Msg.success().add("msg", "删除分类成功!"); + return Msg.success().add("msg", "鍒犻櫎鍒嗙被鎴愬姛锛"); } @RequestMapping("tag") @@ -81,7 +81,7 @@ public String tag(@RequestParam("id")int id, Model model) { return "tag"; } - // 返回该分类所有的文章 + // 杩斿洖璇ュ垎绫绘墍鏈夌殑鏂囩珷 @RequestMapping(value="/tagarticle", method=RequestMethod.GET) @ResponseBody public Msg tagarticle(@RequestParam("id") int id, diff --git a/src/controller/CommentController.java b/src/controller/CommentController.java index b87462c..8f4c619 100644 --- a/src/controller/CommentController.java +++ b/src/controller/CommentController.java @@ -22,7 +22,7 @@ public class CommentController { @Autowired private CommentService commentService; - // 提交评论 + // 鎻愪氦璇勮 @RequestMapping(value="/sendcomment", method=RequestMethod.POST) @ResponseBody public Msg sendcomment(@RequestParam(value="id", required=true)int id, @@ -30,20 +30,20 @@ public Msg sendcomment(@RequestParam(value="id", required=true)int id, System.out.println("name = " + name + " \ncomment = " + comment); commentService.sendcomment(id, name, comment); Msg msg = Msg.success(); - msg.setMsg("提交评论成功!"); + msg.setMsg("鎻愪氦璇勮鎴愬姛锛"); return msg; } - // 获得评论 + // 鑾峰緱璇勮 @RequestMapping(value="/getComments", method=RequestMethod.GET) @ResponseBody public Msg getComments(@RequestParam("id")int id) { - // 获取文章所有的评论 + // 鑾峰彇鏂囩珷鎵鏈夌殑璇勮 List list = commentService.getComments(id); return Msg.success().add("commentsList", list); } - // 获得所有评论 + // 鑾峰緱鎵鏈夎瘎璁 @RequestMapping(value="/getallcomments", method=RequestMethod.GET) @ResponseBody public Msg getallcomments() { @@ -51,10 +51,10 @@ public Msg getallcomments() { return Msg.success().add("commentList", list); } - // 评论后台管理 + // 璇勮鍚庡彴绠$悊 @RequestMapping("/commentback") public String commentback(HttpServletRequest request,HttpServletResponse response) { - //得到 session 的值,判断是否已经登陆 + //寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 if(request.getSession().getAttribute("username") != null) { String username = request.getSession().getAttribute("username").toString(); if(username != null) { @@ -64,17 +64,17 @@ public String commentback(HttpServletRequest request,HttpServletResponse respons return "admin/error"; } - // 删除一条评论 + // 鍒犻櫎涓鏉¤瘎璁 @RequestMapping(value="/deleteacomment",method=RequestMethod.GET) @ResponseBody public Msg deleteacomment(@RequestParam("id") int id) { commentService.deletea(id); Msg msg = Msg.success(); - msg.setMsg("此条评论已删除!"); + msg.setMsg("姝ゆ潯璇勮宸插垹闄わ紒"); return msg; } - // 提交评论 + // 鎻愪氦璇勮 @RequestMapping(value="/sendheartword", method=RequestMethod.POST) @ResponseBody public Msg sendheartword(@RequestParam(value="id", required=true)int id, @@ -82,7 +82,7 @@ public Msg sendheartword(@RequestParam(value="id", required=true)int id, System.out.println("name = " + name + " \ncomment = " + comment); commentService.sendcomment(id, name, comment); Msg msg = Msg.success(); - msg.setMsg("我收到你的心声了!"); + msg.setMsg("鎴戞敹鍒颁綘鐨勫績澹颁簡锛"); return msg; } diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java index 43e514c..05e81e3 100644 --- a/src/controller/LoginController.java +++ b/src/controller/LoginController.java @@ -38,7 +38,7 @@ public String validatelogin(@RequestParam(value="username", required=false)Strin return "admin/loginfail"; } - // 退出登陆 + // 閫鍑虹櫥闄 @RequestMapping("logout") public String logout(HttpServletRequest request, HttpServletResponse response) { request.getSession().removeAttribute("username"); diff --git a/src/controller/UploadfileController.java b/src/controller/UploadfileController.java index 9d2741c..6255ad7 100644 --- a/src/controller/UploadfileController.java +++ b/src/controller/UploadfileController.java @@ -34,12 +34,12 @@ public void uploadImg( String filePath = "/upload/" + DateUtil.getDays() + "/" + Myutil.random(5) + suffix; String resultPath = UploadUtil.uploadImg(filePath, file.getInputStream()); System.out.println("path="+resultPath); - response.getWriter().write( "{\"success\": 1, \"message\":\"上传成功\",\"url\":\"" + filePath + "\"}" ); + response.getWriter().write( "{\"success\": 1, \"message\":\"涓婁紶鎴愬姛\",\"url\":\"" + filePath + "\"}" ); } catch (Exception e) { e.printStackTrace(); log.error("upload failed ", e); try { - response.getWriter().write( "{\"success\": 0, \"message\":\"上传失败\",\"url\":\""+ "\"}" ); + response.getWriter().write( "{\"success\": 0, \"message\":\"涓婁紶澶辫触\",\"url\":\""+ "\"}" ); } catch (IOException e1) { e1.printStackTrace(); } diff --git a/src/entity/Msg.java b/src/entity/Msg.java index c8ed08c..b424433 100644 --- a/src/entity/Msg.java +++ b/src/entity/Msg.java @@ -3,25 +3,25 @@ import java.util.Map; public class Msg { - //状态码 100-成功 200-失败 + //鐘舵佺爜 100-鎴愬姛 200-澶辫触 private int code; - //提示信息 + //鎻愮ず淇℃伅 private String msg; - //用户要返回给浏览器的数据 + //鐢ㄦ埛瑕佽繑鍥炵粰娴忚鍣ㄧ殑鏁版嵁 private Map extend = new HashMap(); public static Msg success(){ Msg result = new Msg(); result.setCode(100); - result.setMsg("处理成功!"); + result.setMsg("澶勭悊鎴愬姛锛"); return result; } public static Msg fail(){ Msg result = new Msg(); result.setCode(200); - result.setMsg("处理失败!"); + result.setMsg("澶勭悊澶辫触锛"); return result; } diff --git a/src/mapping/BlogMapper.java b/src/mapping/BlogMapper.java index 246bd15..06cf00c 100644 --- a/src/mapping/BlogMapper.java +++ b/src/mapping/BlogMapper.java @@ -92,7 +92,7 @@ public interface BlogMapper { List selectAll(); - // 新添加的方法 + // 鏂版坊鍔犵殑鏂规硶 List selectByExampleWithCategory(BlogExample example); Blog selectByPrimaryKeyWithCategory(Integer id); diff --git a/src/service/ArticleService.java b/src/service/ArticleService.java index 7664bd3..4d3d4e1 100644 --- a/src/service/ArticleService.java +++ b/src/service/ArticleService.java @@ -23,27 +23,27 @@ public class ArticleService { @Autowired private CommentMapper commentMapper; - // 获得所有的文章信息不带分类信息 + // 鑾峰緱鎵鏈夌殑鏂囩珷淇℃伅涓嶅甫鍒嗙被淇℃伅 public List getAllArticle() { return blogMapper.selectAll(); } - //通过主键获取博客文章带分类信息 + //閫氳繃涓婚敭鑾峰彇鍗氬鏂囩珷甯﹀垎绫讳俊鎭 public Blog selectByPrimaryKeyWithCategory(Integer id) { return blogMapper.selectByPrimaryKeyWithCategory(id); } - //获取所有的文章带分类信息 + //鑾峰彇鎵鏈夌殑鏂囩珷甯﹀垎绫讳俊鎭 public List getAll() { return blogMapper.selectByExampleWithCategory(null); } - // 获取所有的分类信息 + // 鑾峰彇鎵鏈夌殑鍒嗙被淇℃伅 public List getCategoryName() { return categoryMapper.selectByExample(null); } - // 得到分类名所对应的 ID 值 + // 寰楀埌鍒嗙被鍚嶆墍瀵瑰簲鐨 ID 鍊 public Integer getCategoryId(String categoryName) { CategoryExample example = new CategoryExample(); example.createCriteria().andNameEqualTo(categoryName); @@ -52,16 +52,16 @@ public Integer getCategoryId(String categoryName) { return id; } - // 存储一篇博客 + // 瀛樺偍涓绡囧崥瀹 public void save(Blog blog) { blogMapper.insert(blog); } - // 获取 id 所对应博客文章储存在数据库的 md + // 鑾峰彇 id 鎵瀵瑰簲鍗氬鏂囩珷鍌ㄥ瓨鍦ㄦ暟鎹簱鐨 md public String getArticleMdStr(int id) { Blog blog = blogMapper.selectByPrimaryKeyWithCategory(id); String md = blog.getMd(); - // md 为 null,返回空字符串 + // md 涓 null,杩斿洖绌哄瓧绗︿覆 if(md == null) return ""; return md; @@ -87,7 +87,7 @@ public void update(Blog blog) { public List postarticle(List list) { List listRtnBlogs = new ArrayList(); if(list != null && list.size() > 4) { - // 把评论数最大的四篇文章取出来 + // 鎶婅瘎璁烘暟鏈澶х殑鍥涚瘒鏂囩珷鍙栧嚭鏉 for(int i = 0 ; i < 4; i++) { for(int j = i + 1; j < list.size(); j++) { diff --git a/src/service/CommentService.java b/src/service/CommentService.java index 7b33af8..9e95ab5 100644 --- a/src/service/CommentService.java +++ b/src/service/CommentService.java @@ -18,15 +18,15 @@ public class CommentService { @Autowired private CommentMapper commentMapper; - // 保存评论 + // 淇濆瓨璇勮 public void sendcomment(int id, String name, String comment) throws ParseException { if(name.equals("")) { - name = new String("匿名"); + name = new String("鍖垮悕"); } if(comment.equals("")) { - comment = new String("啥都没留下!"); + comment = new String("鍟ラ兘娌$暀涓嬶紒"); } - // 评论时间 + // 璇勮鏃堕棿 Date now = new Date(); Comment comment2 = new Comment(); diff --git a/src/service/LoginService.java b/src/service/LoginService.java index ffec214..e278d3d 100644 --- a/src/service/LoginService.java +++ b/src/service/LoginService.java @@ -24,18 +24,18 @@ public boolean validate(String username, String password) throws SaslException { if(usersMapper.selectByExample(example) != null) { user = usersMapper.selectByExample(example).get(0); } else { - // 用户不存在,登陆失败! + // 鐢ㄦ埛涓嶅瓨鍦紝鐧婚檰澶辫触锛 return false; } - // 获取数据库的密码 + // 鑾峰彇鏁版嵁搴撶殑瀵嗙爜 String passwordDB = user.getPassword(); - // password md5 加密 + // password md5 鍔犲瘑 String passmd5 = MD5.getMD5(password); System.out.println(passmd5); if(passwordDB.equals(passmd5)) return true; - // 密码错误! + // 瀵嗙爜閿欒锛 return false; } diff --git a/src/utils/MD5.java b/src/utils/MD5.java index 030cf71..2b21d4c 100644 --- a/src/utils/MD5.java +++ b/src/utils/MD5.java @@ -7,7 +7,7 @@ public class MD5 { /** - * 对字符串md5加密 + * 瀵瑰瓧绗︿覆md5鍔犲瘑 * * @param str * @return @@ -15,15 +15,15 @@ public class MD5 { */ public static String getMD5(String str) throws SaslException { try { - // 生成一个MD5加密计算摘要 + // 鐢熸垚涓涓狹D5鍔犲瘑璁$畻鎽樿 MessageDigest md = MessageDigest.getInstance("MD5"); - // 计算md5函数 + // 璁$畻md5鍑芥暟 md.update(str.getBytes()); - // digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符 - // BigInteger函数则将8位的字符串转换成32位hex值,用字符串来表示;得到字符串形式的 hash 值 + // digest()鏈鍚庣‘瀹氳繑鍥瀖d5 hash鍊硷紝杩斿洖鍊间负8涓哄瓧绗︿覆銆傚洜涓簃d5 hash鍊兼槸16浣嶇殑hex鍊硷紝瀹為檯涓婂氨鏄8浣嶇殑瀛楃 + // BigInteger鍑芥暟鍒欏皢8浣嶇殑瀛楃涓茶浆鎹㈡垚32浣峢ex鍊硷紝鐢ㄥ瓧绗︿覆鏉ヨ〃绀猴紱寰楀埌瀛楃涓插舰寮忕殑 hash 鍊 return new BigInteger(1, md.digest()).toString(16); } catch (Exception e) { - throw new SaslException("MD5加密出现错误"); + throw new SaslException("MD5鍔犲瘑鍑虹幇閿欒"); } } } diff --git a/src/utils/Myutil.java b/src/utils/Myutil.java index 2ce9741..e4e67d7 100644 --- a/src/utils/Myutil.java +++ b/src/utils/Myutil.java @@ -5,10 +5,10 @@ public class Myutil { /** - * 返回随机数 + * 杩斿洖闅忔満鏁 * * @param n - * 个数 + * 涓暟 * @return */ public static String random(int n) { diff --git a/src/utils/UploadUtil.java b/src/utils/UploadUtil.java index b82c709..4b503cc 100644 --- a/src/utils/UploadUtil.java +++ b/src/utils/UploadUtil.java @@ -8,7 +8,7 @@ public class UploadUtil { public static String uploadImg(String filePath, InputStream in) throws IOException { - //获取tomcat 的根目录(webapps 下的路径),editormd.root 在web.xml 中配置 + //鑾峰彇tomcat 鐨勬牴鐩綍锛坵ebapps 涓嬬殑璺緞锛夛紝editormd.root 鍦╳eb.xml 涓厤缃 String tomcatRootPath = System.getProperty("editormd.root") + ".."; String resultPath = tomcatRootPath + filePath; @@ -19,7 +19,7 @@ public static String uploadImg(String filePath, InputStream in) throws IOExcepti } /* - * 创建文件, 如果文件夹不存在将被创建 + * 鍒涘缓鏂囦欢锛 濡傛灉鏂囦欢澶逛笉瀛樺湪灏嗚鍒涘缓 * */ public static File createFile(String resultPath) { File file = new File(resultPath); From 03fd23225dac1ea249e337a133a2d8741a90b0a6 Mon Sep 17 00:00:00 2001 From: aim467 <709544711@qq.com> Date: Sat, 19 Jun 2021 00:12:39 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9Bean=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=9E=84=E9=80=A0=E5=99=A8=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=20=E6=8A=8AHttpSession=E6=B3=A8=E5=85=A5=E5=88=B0=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=99=A8=E6=9D=A5=E8=BF=9B=E8=A1=8C=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E5=87=BD=E6=95=B0=E5=81=9A=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WEB-INF/classes/applicationContext.xml | 4 +- src/applicationContext.xml | 4 +- src/controller/ArticleController.java | 83 ++++++++++--------- src/controller/CategoryController.java | 67 ++++++++------- src/controller/CommentController.java | 19 +++-- src/controller/LoginController.java | 8 +- 6 files changed, 100 insertions(+), 85 deletions(-) diff --git a/WebRoot/WEB-INF/classes/applicationContext.xml b/WebRoot/WEB-INF/classes/applicationContext.xml index 04cebef..6135075 100644 --- a/WebRoot/WEB-INF/classes/applicationContext.xml +++ b/WebRoot/WEB-INF/classes/applicationContext.xml @@ -18,8 +18,8 @@ class="org.springframework.jdbc.datasource.DriverManagerDataSource"> - - + + diff --git a/src/applicationContext.xml b/src/applicationContext.xml index 04cebef..6135075 100644 --- a/src/applicationContext.xml +++ b/src/applicationContext.xml @@ -18,8 +18,8 @@ class="org.springframework.jdbc.datasource.DriverManagerDataSource"> - - + + diff --git a/src/controller/ArticleController.java b/src/controller/ArticleController.java index 08e36f7..50ee2d8 100644 --- a/src/controller/ArticleController.java +++ b/src/controller/ArticleController.java @@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -30,8 +31,15 @@ @Controller public class ArticleController { + private final ArticleService articleService; + + private final HttpSession session; + @Autowired - private ArticleService articleService; + public ArticleController(ArticleService articleService, HttpSession session) { + this.articleService = articleService; + this.session = session; + } // 杩斿洖鏂囩珷鍒楄〃锛岃繘琛 鍒嗛〉 @RequestMapping("/articles") @@ -44,7 +52,7 @@ public Msg getArticlesList( PageInfo pageInfo = new PageInfo<>(articles, 5); return Msg.success().add("pageInfo", pageInfo); } - + // 鑾峰彇鍒嗙被淇℃伅 @RequestMapping(value="getCategoryName", method=RequestMethod.POST, produces="application/json") @ResponseBody @@ -53,34 +61,30 @@ public Msg getCategoryName() { List list = articleService.getCategoryName(); Map map = new HashMap<>(); map.put("category", list); - + msg.setCode(200); msg.setMsg("杩斿洖鍒嗙被鍚嶅瓧锛"); msg.setExtend(map); - return msg; + return msg; } - + // 鍚庡彴鏂板缓鍗氬鏂囩珷,鍒ゆ柇鏄惁鐧婚檰锛屾垜鐢 ajax 璇锋眰鏃犳硶璺宠浆椤甸潰锛 // 浣跨敤浜唚indow.location='${APP_PATH }/islogin'; 璇锋眰璺宠浆 @RequestMapping(value="/islogin") - public String newarticle(HttpServletRequest request, HttpServletResponse response) throws IOException { - if(request.getSession().getAttribute("username") != null) { - System.out.println("username = " + request.getSession().getAttribute("username")); + public String newarticle() throws IOException { + if(session.getAttribute("username") != null) { return "redirect:/newarticle"; } return "admin/error"; } - + // 鏂板缓鏂囩珷 @RequestMapping(value="/newarticle") - public String editarticle(HttpServletRequest request, HttpServletResponse response) + public String editarticle() { //寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 - if(request.getSession().getAttribute("username") != null) { - String username = request.getSession().getAttribute("username").toString(); - if(username != null) { - return "admin/newblog"; - } + if(session.getAttribute("username") != null) { + return "admin/newblog"; } return "admin/error"; } @@ -116,18 +120,18 @@ public ModelAndView saveArticle( view.addObject("map", map); return view; } - + // 缂栬緫鏂囩珷 @RequestMapping("/edit") - public String edit(@RequestParam(value="id", required=true, defaultValue="1") int id, - HttpServletRequest request, HttpServletResponse response, Model model) { - if(request.getSession().getAttribute("username") != null) { + public String edit(@RequestParam(value="id", required=true, defaultValue="1") int id, + Model model) { + if(session.getAttribute("username") != null) { model.addAttribute("blogid", id); return "admin/edit"; - } + } return "admin/error"; } - + // 淇濆瓨淇敼鏂囩珷 @RequestMapping(value="/updatearticle", method=RequestMethod.POST) public ModelAndView updatearticle(HttpServletRequest request, HttpServletResponse response,@RequestParam(value = "test-editormd-markdown-doc", required = false) String edmdDoc, @@ -135,7 +139,7 @@ public ModelAndView updatearticle(HttpServletRequest request, HttpServletRespons ModelAndView view = new ModelAndView(); String dateStr; Map map = new HashMap(); - + // 鑾峰彇闅愯棌鍩熸枃绔犵殑 id int id = Integer.parseInt(request.getParameter("id")); // 鑾峰彇鏂囩珷瀵瑰簲鐨 鍒嗙被Id @@ -165,8 +169,8 @@ public ModelAndView updatearticle(HttpServletRequest request, HttpServletRespons view.addObject("map", map); return view; } - - + + //閫氳繃 id 鏌ユ壘鏂囩珷骞惰繑鍥 @RequestMapping("/getarticlebyid") @ResponseBody @@ -174,8 +178,8 @@ public Blog getarticlebyid(@RequestParam(value="id", defaultValue="1") int id) { Blog blog = articleService.selectBlogById(id); return blog; } - - + + // 鏄剧ず鏂囩珷 @RequestMapping(value="showarticle", method=RequestMethod.GET) public String showarticle(@RequestParam(value="id", defaultValue="1")int id, Model model) { @@ -184,35 +188,33 @@ public String showarticle(@RequestParam(value="id", defaultValue="1")int id, Mod model.addAttribute("id", id); return "showarticle"; } - + // 渚ц竟鏍忛槄璇绘ā寮 @RequestMapping(value="/showarticlecustomcontanier", method=RequestMethod.GET) - public String showarticlecustomcontainer(HttpServletRequest request, HttpServletResponse response, - Model model, @RequestParam(value="id", defaultValue="1")int id) { + public String showarticlecustomcontainer( Model model, @RequestParam(value="id", defaultValue="1")int id) { String customMd = articleService.getArticleMdStr(id); model.addAttribute("customMd", customMd); model.addAttribute("id", id); return "showarticlecustomcontanier"; } - + // 鍒犻櫎鏂囩珷 - @RequestMapping(value="/delete", method=RequestMethod.GET) - public void delete(@RequestParam(value="id", required=true)int id,HttpServletRequest request, - HttpServletResponse response) throws IOException { - if(request.getSession().getAttribute("username") != null) { + @RequestMapping(value="/delete", method=RequestMethod.GET) + public void delete(@RequestParam(value="id", required=true)int id, HttpServletResponse response) throws IOException { + if(session.getAttribute("username") != null) { articleService.deleteArticleById(id); } else { response.sendRedirect("deletenologin"); } } - + // 娌℃湁鐧婚檰鐨勬椂鍊欙紝灏变笉鑳藉垹闄ゆ枃绔 @RequestMapping("/deletenologin") public String deletenologin() { return "admin/error"; } - - /* + + /* // 杩斿洖姝e父妯″紡 @RequestMapping(value="/backhtml", method=RequestMethod.POST) public String backhtml(HttpServletRequest request, HttpServletResponse response, @@ -221,22 +223,21 @@ public String backhtml(HttpServletRequest request, HttpServletResponse response, model.addAttribute("backmd", md); return "showarticle"; }*/ - + // 杩斿洖璇勮鏁版渶澶氱殑鍥涚瘒鏂囩珷 @RequestMapping("/postarticle") @ResponseBody public Msg postarticle() { List list = articleService.getAll(); List postList = articleService.postarticle(list); - System.out.println("size = " + postList.size()); return Msg.success().add("postList", postList); } - + @RequestMapping("about") public String about() { return "about"; } - + @RequestMapping("/contact") public String contact() { return "contact"; diff --git a/src/controller/CategoryController.java b/src/controller/CategoryController.java index 2ba04e6..58c948a 100644 --- a/src/controller/CategoryController.java +++ b/src/controller/CategoryController.java @@ -1,11 +1,10 @@ package controller; -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import entity.Blog; +import entity.Category; +import entity.Msg; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -13,43 +12,48 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; - -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; - import service.CategoryService; -import entity.Blog; -import entity.Category; -import entity.Msg; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.util.List; @Controller public class CategoryController { + private final CategoryService categoryService; + + private final HttpSession session; + @Autowired - private CategoryService categoryService; - + public CategoryController(CategoryService categoryService, HttpSession session) { + this.categoryService = categoryService; + this.session = session; + } + // tags 杩斿洖鏍囩锛堟垜鎶婂畠鐞嗚В涓哄垎绫伙級 - @RequestMapping(value="/getTags",method=RequestMethod.GET) + @RequestMapping(value="/getTags",method=RequestMethod.GET) @ResponseBody public Msg getTags() { List tags = categoryService.getCategory(); return Msg.success().add("tags", tags); } - - + + // 鍒嗙被鐨勫悗鍙扮鐞 - @RequestMapping(value="/tagadmin") - public String tagadmin(HttpServletRequest request, HttpServletResponse response) { + @RequestMapping(value="/tagadmin") + public String tagadmin() { String username = null; - if(request.getSession().getAttribute("username") != null) { - username = request.getSession().getAttribute("username").toString(); + if(session.getAttribute("username") != null) { + username = session.getAttribute("username").toString(); } - + if(username == null) { return "admin/error"; } return "admin/tagadmin"; } - + // 鏂板缓鍒嗙被 @RequestMapping(value="/newtag", method=RequestMethod.POST) public String newtag(@RequestParam(value="name", required=true) String name, @@ -58,15 +62,14 @@ public String newtag(@RequestParam(value="name", required=true) String name, model.addAttribute("msg", "鏂板缓鍒嗙被鎴愬姛锛"); return "admin/newtagsuccess"; } - + // 鍒犻櫎鍒嗙被 - @RequestMapping(value="deletetag", method=RequestMethod.GET) + @RequestMapping(value="deletetag", method=RequestMethod.GET) @ResponseBody - public Msg deletetag(HttpServletRequest request, HttpServletResponse response, - @RequestParam(value="id", required=true)int id) { + public Msg deletetag(@RequestParam(value="id", required=true)int id) { String username = null; - if(request.getSession().getAttribute("username") != null) { - username = request.getSession().getAttribute("username").toString(); + if(session.getAttribute("username") != null) { + username = session.getAttribute("username").toString(); } if(username == null) { return Msg.fail().add("msg", "浣犳病鏈夌櫥闄"); @@ -74,13 +77,13 @@ public Msg deletetag(HttpServletRequest request, HttpServletResponse response, categoryService.deltag(id); return Msg.success().add("msg", "鍒犻櫎鍒嗙被鎴愬姛锛"); } - + @RequestMapping("tag") public String tag(@RequestParam("id")int id, Model model) { model.addAttribute("id", id); return "tag"; } - + // 杩斿洖璇ュ垎绫绘墍鏈夌殑鏂囩珷 @RequestMapping(value="/tagarticle", method=RequestMethod.GET) @ResponseBody diff --git a/src/controller/CommentController.java b/src/controller/CommentController.java index 8f4c619..05da3cc 100644 --- a/src/controller/CommentController.java +++ b/src/controller/CommentController.java @@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -19,15 +20,21 @@ @Controller public class CommentController { + private final CommentService commentService; + + private final HttpSession session; + @Autowired - private CommentService commentService; - + public CommentController(CommentService commentService, HttpSession session) { + this.commentService = commentService; + this.session = session; + } + // 鎻愪氦璇勮 @RequestMapping(value="/sendcomment", method=RequestMethod.POST) @ResponseBody public Msg sendcomment(@RequestParam(value="id", required=true)int id, @RequestParam("name") String name, @RequestParam("comment") String comment) throws ParseException { - System.out.println("name = " + name + " \ncomment = " + comment); commentService.sendcomment(id, name, comment); Msg msg = Msg.success(); msg.setMsg("鎻愪氦璇勮鎴愬姛锛"); @@ -53,10 +60,10 @@ public Msg getallcomments() { // 璇勮鍚庡彴绠$悊 @RequestMapping("/commentback") - public String commentback(HttpServletRequest request,HttpServletResponse response) { + public String commentback() { //寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 - if(request.getSession().getAttribute("username") != null) { - String username = request.getSession().getAttribute("username").toString(); + if(session.getAttribute("username") != null) { + String username = session.getAttribute("username").toString(); if(username != null) { return "admin/commentadmin"; } diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java index 05e81e3..33a8585 100644 --- a/src/controller/LoginController.java +++ b/src/controller/LoginController.java @@ -15,9 +15,13 @@ @Controller public class LoginController { + private final LoginService service; + @Autowired - private LoginService service; - + public LoginController(LoginService service) { + this.service = service; + } + @RequestMapping("/login") public String login() { return "admin/login"; From 6d6a42ddc019bc77c09b9022572185fdf593092d Mon Sep 17 00:00:00 2001 From: aim467 <709544711@qq.com> Date: Sat, 19 Jun 2021 00:21:36 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/applicationContext.xml | 31 +- src/controller/ArticleController.java | 425 ++++++++++++----------- src/controller/CategoryController.java | 132 +++---- src/controller/CommentController.java | 143 ++++---- src/controller/LoginController.java | 70 ++-- src/controller/UploadfileController.java | 57 +-- 6 files changed, 434 insertions(+), 424 deletions(-) diff --git a/src/applicationContext.xml b/src/applicationContext.xml index 6135075..ac5b598 100644 --- a/src/applicationContext.xml +++ b/src/applicationContext.xml @@ -1,29 +1,26 @@ - + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> + - - - - + + + + - + classpath:mapping/*.xml @@ -59,8 +56,8 @@ - - + + diff --git a/src/controller/ArticleController.java b/src/controller/ArticleController.java index 50ee2d8..806eba4 100644 --- a/src/controller/ArticleController.java +++ b/src/controller/ArticleController.java @@ -31,215 +31,218 @@ @Controller public class ArticleController { - private final ArticleService articleService; - - private final HttpSession session; - - @Autowired - public ArticleController(ArticleService articleService, HttpSession session) { - this.articleService = articleService; - this.session = session; - } - - // 杩斿洖鏂囩珷鍒楄〃锛岃繘琛 鍒嗛〉 - @RequestMapping("/articles") - @ResponseBody - public Msg getArticlesList( - @RequestParam(value = "pn", defaultValue = "1") Integer pn) throws ParseException { - PageHelper.startPage(pn, 5); - List articles = articleService.getAll(); - - PageInfo pageInfo = new PageInfo<>(articles, 5); - return Msg.success().add("pageInfo", pageInfo); - } - - // 鑾峰彇鍒嗙被淇℃伅 - @RequestMapping(value="getCategoryName", method=RequestMethod.POST, produces="application/json") - @ResponseBody - public Msg getCategoryName() { - Msg msg = new Msg(); - List list = articleService.getCategoryName(); - Map map = new HashMap<>(); - map.put("category", list); - - msg.setCode(200); - msg.setMsg("杩斿洖鍒嗙被鍚嶅瓧锛"); - msg.setExtend(map); - return msg; - } - - // 鍚庡彴鏂板缓鍗氬鏂囩珷,鍒ゆ柇鏄惁鐧婚檰锛屾垜鐢 ajax 璇锋眰鏃犳硶璺宠浆椤甸潰锛 - // 浣跨敤浜唚indow.location='${APP_PATH }/islogin'; 璇锋眰璺宠浆 - @RequestMapping(value="/islogin") - public String newarticle() throws IOException { - if(session.getAttribute("username") != null) { - return "redirect:/newarticle"; - } - return "admin/error"; - } - - // 鏂板缓鏂囩珷 - @RequestMapping(value="/newarticle") - public String editarticle() - { - //寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 - if(session.getAttribute("username") != null) { - return "admin/newblog"; - } - return "admin/error"; - } - - // 淇濆瓨 md 鍜 HTML 鍒版暟鎹簱 - @RequestMapping(value = "saveArticle", method = RequestMethod.POST) - public ModelAndView saveArticle( - HttpServletRequest request, - HttpServletResponse response, - @RequestParam(value = "test-editormd-markdown-doc", required = false) String edmdDoc, - @RequestParam(value = "editorhtml", required = false) String edmdHtml) { - ModelAndView view = new ModelAndView(); - Map map = new HashMap(); - - // 鑾峰彇鏂囩珷瀵瑰簲鐨 鍒嗙被Id - Integer categoryId = articleService.getCategoryId(request - .getParameter("categoryName")); - - Blog blog = new Blog(); - blog.setCategoryid(categoryId); - blog.setContent(edmdHtml); - blog.setMd(edmdDoc); - blog.setTitle(request.getParameter("title")); - blog.setTitleintro(request.getParameter("titleIntro")); - String dateStr = request.getParameter("createdtime").replace('/', '-'); - Date date = DateUtil.fomatDate(dateStr); - blog.setCreatedtime(date); - - articleService.save(blog); - // 鑾峰緱鏂囩珷鐨勬爣棰橈紝鏍囬浠嬬粛锛屾棩鏈燂紝鍒嗙被绛変俊鎭 - map.put("message", "鏂板缓鏂囩珷鎴愬姛锛"); - view.setViewName("admin/newsuccess"); - view.addObject("map", map); - return view; - } - - // 缂栬緫鏂囩珷 - @RequestMapping("/edit") - public String edit(@RequestParam(value="id", required=true, defaultValue="1") int id, - Model model) { - if(session.getAttribute("username") != null) { - model.addAttribute("blogid", id); - return "admin/edit"; - } - return "admin/error"; - } - - // 淇濆瓨淇敼鏂囩珷 - @RequestMapping(value="/updatearticle", method=RequestMethod.POST) - public ModelAndView updatearticle(HttpServletRequest request, HttpServletResponse response,@RequestParam(value = "test-editormd-markdown-doc", required = false) String edmdDoc, - @RequestParam(value = "editorhtml", required = false) String edmdHtml) { - ModelAndView view = new ModelAndView(); - String dateStr; - Map map = new HashMap(); - - // 鑾峰彇闅愯棌鍩熸枃绔犵殑 id - int id = Integer.parseInt(request.getParameter("id")); - // 鑾峰彇鏂囩珷瀵瑰簲鐨 鍒嗙被Id - Integer categoryId = articleService.getCategoryId(request - .getParameter("categoryName")); - - Blog blog = new Blog(); - blog.setId(id); - blog.setCategoryid(categoryId); - blog.setContent(edmdHtml); - blog.setMd(edmdDoc); - blog.setTitle(request.getParameter("title")); - blog.setTitleintro(request.getParameter("titleIntro")); - if(request.getParameter("createdtime") != null) - { - dateStr = request.getParameter("createdtime").replace('/', '-'); - } else { - dateStr = new String("1996-2-10"); - } - Date date = DateUtil.fomatDate(dateStr); - blog.setCreatedtime(date); - - articleService.update(blog); - // 鑾峰緱鏂囩珷鐨勬爣棰橈紝鏍囬浠嬬粛锛屾棩鏈燂紝鍒嗙被绛変俊鎭 - map.put("message", "淇敼鏂囩珷鎴愬姛锛"); - view.setViewName("admin/editsuccess"); - view.addObject("map", map); - return view; - } - - - //閫氳繃 id 鏌ユ壘鏂囩珷骞惰繑鍥 - @RequestMapping("/getarticlebyid") - @ResponseBody - public Blog getarticlebyid(@RequestParam(value="id", defaultValue="1") int id) { - Blog blog = articleService.selectBlogById(id); - return blog; - } - - - // 鏄剧ず鏂囩珷 - @RequestMapping(value="showarticle", method=RequestMethod.GET) - public String showarticle(@RequestParam(value="id", defaultValue="1")int id, Model model) { - String mdString = articleService.getArticleMdStr(id); - model.addAttribute("mdString", mdString); - model.addAttribute("id", id); - return "showarticle"; - } - - // 渚ц竟鏍忛槄璇绘ā寮 - @RequestMapping(value="/showarticlecustomcontanier", method=RequestMethod.GET) - public String showarticlecustomcontainer( Model model, @RequestParam(value="id", defaultValue="1")int id) { - String customMd = articleService.getArticleMdStr(id); - model.addAttribute("customMd", customMd); - model.addAttribute("id", id); - return "showarticlecustomcontanier"; - } - - // 鍒犻櫎鏂囩珷 - @RequestMapping(value="/delete", method=RequestMethod.GET) - public void delete(@RequestParam(value="id", required=true)int id, HttpServletResponse response) throws IOException { - if(session.getAttribute("username") != null) { - articleService.deleteArticleById(id); - } else { - response.sendRedirect("deletenologin"); - } - } - - // 娌℃湁鐧婚檰鐨勬椂鍊欙紝灏变笉鑳藉垹闄ゆ枃绔 - @RequestMapping("/deletenologin") - public String deletenologin() { - return "admin/error"; - } - - /* - // 杩斿洖姝e父妯″紡 - @RequestMapping(value="/backhtml", method=RequestMethod.POST) - public String backhtml(HttpServletRequest request, HttpServletResponse response, - Model model, @RequestParam(value="md", required=true)String md) { - System.out.println("backmd = " + md); - model.addAttribute("backmd", md); - return "showarticle"; - }*/ - - // 杩斿洖璇勮鏁版渶澶氱殑鍥涚瘒鏂囩珷 - @RequestMapping("/postarticle") - @ResponseBody - public Msg postarticle() { - List list = articleService.getAll(); - List postList = articleService.postarticle(list); - return Msg.success().add("postList", postList); - } - - @RequestMapping("about") - public String about() { - return "about"; - } - - @RequestMapping("/contact") - public String contact() { - return "contact"; - } + private final ArticleService articleService; + + private final HttpSession session; + + @Autowired + public ArticleController(ArticleService articleService, HttpSession session) { + this.articleService = articleService; + this.session = session; + } + + // 杩斿洖鏂囩珷鍒楄〃锛岃繘琛 鍒嗛〉 + @RequestMapping("/articles") + @ResponseBody + public Msg getArticlesList(@RequestParam(value = "pn", defaultValue = "1") Integer pn) + throws ParseException { + PageHelper.startPage(pn, 5); + List articles = articleService.getAll(); + + PageInfo pageInfo = new PageInfo<>(articles, 5); + return Msg.success().add("pageInfo", pageInfo); + } + + // 鑾峰彇鍒嗙被淇℃伅 + @RequestMapping( + value = "getCategoryName", + method = RequestMethod.POST, + produces = "application/json") + @ResponseBody + public Msg getCategoryName() { + Msg msg = new Msg(); + List list = articleService.getCategoryName(); + Map map = new HashMap<>(); + map.put("category", list); + + msg.setCode(200); + msg.setMsg("杩斿洖鍒嗙被鍚嶅瓧锛"); + msg.setExtend(map); + return msg; + } + + // 鍚庡彴鏂板缓鍗氬鏂囩珷,鍒ゆ柇鏄惁鐧婚檰锛屾垜鐢 ajax 璇锋眰鏃犳硶璺宠浆椤甸潰锛 + // 浣跨敤浜唚indow.location='${APP_PATH }/islogin'; 璇锋眰璺宠浆 + @RequestMapping(value = "/islogin") + public String newarticle() throws IOException { + if (session.getAttribute("username") != null) { + return "redirect:/newarticle"; + } + return "admin/error"; + } + + // 鏂板缓鏂囩珷 + @RequestMapping(value = "/newarticle") + public String editarticle() { + // 寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 + if (session.getAttribute("username") != null) { + return "admin/newblog"; + } + return "admin/error"; + } + + // 淇濆瓨 md 鍜 HTML 鍒版暟鎹簱 + @RequestMapping(value = "saveArticle", method = RequestMethod.POST) + public ModelAndView saveArticle( + HttpServletRequest request, + HttpServletResponse response, + @RequestParam(value = "test-editormd-markdown-doc", required = false) String edmdDoc, + @RequestParam(value = "editorhtml", required = false) String edmdHtml) { + ModelAndView view = new ModelAndView(); + Map map = new HashMap(); + + // 鑾峰彇鏂囩珷瀵瑰簲鐨 鍒嗙被Id + Integer categoryId = articleService.getCategoryId(request.getParameter("categoryName")); + + Blog blog = new Blog(); + blog.setCategoryid(categoryId); + blog.setContent(edmdHtml); + blog.setMd(edmdDoc); + blog.setTitle(request.getParameter("title")); + blog.setTitleintro(request.getParameter("titleIntro")); + String dateStr = request.getParameter("createdtime").replace('/', '-'); + Date date = DateUtil.fomatDate(dateStr); + blog.setCreatedtime(date); + + articleService.save(blog); + // 鑾峰緱鏂囩珷鐨勬爣棰橈紝鏍囬浠嬬粛锛屾棩鏈燂紝鍒嗙被绛変俊鎭 + map.put("message", "鏂板缓鏂囩珷鎴愬姛锛"); + view.setViewName("admin/newsuccess"); + view.addObject("map", map); + return view; + } + + // 缂栬緫鏂囩珷 + @RequestMapping("/edit") + public String edit( + @RequestParam(value = "id", required = true, defaultValue = "1") int id, Model model) { + if (session.getAttribute("username") != null) { + model.addAttribute("blogid", id); + return "admin/edit"; + } + return "admin/error"; + } + + // 淇濆瓨淇敼鏂囩珷 + @RequestMapping(value = "/updatearticle", method = RequestMethod.POST) + public ModelAndView updatearticle( + HttpServletRequest request, + HttpServletResponse response, + @RequestParam(value = "test-editormd-markdown-doc", required = false) String edmdDoc, + @RequestParam(value = "editorhtml", required = false) String edmdHtml) { + ModelAndView view = new ModelAndView(); + String dateStr; + Map map = new HashMap(); + + // 鑾峰彇闅愯棌鍩熸枃绔犵殑 id + int id = Integer.parseInt(request.getParameter("id")); + // 鑾峰彇鏂囩珷瀵瑰簲鐨 鍒嗙被Id + Integer categoryId = articleService.getCategoryId(request.getParameter("categoryName")); + + Blog blog = new Blog(); + blog.setId(id); + blog.setCategoryid(categoryId); + blog.setContent(edmdHtml); + blog.setMd(edmdDoc); + blog.setTitle(request.getParameter("title")); + blog.setTitleintro(request.getParameter("titleIntro")); + if (request.getParameter("createdtime") != null) { + dateStr = request.getParameter("createdtime").replace('/', '-'); + } else { + dateStr = new String("1996-2-10"); + } + Date date = DateUtil.fomatDate(dateStr); + blog.setCreatedtime(date); + + articleService.update(blog); + // 鑾峰緱鏂囩珷鐨勬爣棰橈紝鏍囬浠嬬粛锛屾棩鏈燂紝鍒嗙被绛変俊鎭 + map.put("message", "淇敼鏂囩珷鎴愬姛锛"); + view.setViewName("admin/editsuccess"); + view.addObject("map", map); + return view; + } + + // 閫氳繃 id 鏌ユ壘鏂囩珷骞惰繑鍥 + @RequestMapping("/getarticlebyid") + @ResponseBody + public Blog getarticlebyid(@RequestParam(value = "id", defaultValue = "1") int id) { + Blog blog = articleService.selectBlogById(id); + return blog; + } + + // 鏄剧ず鏂囩珷 + @RequestMapping(value = "showarticle", method = RequestMethod.GET) + public String showarticle(@RequestParam(value = "id", defaultValue = "1") int id, Model model) { + String mdString = articleService.getArticleMdStr(id); + model.addAttribute("mdString", mdString); + model.addAttribute("id", id); + return "showarticle"; + } + + // 渚ц竟鏍忛槄璇绘ā寮 + @RequestMapping(value = "/showarticlecustomcontanier", method = RequestMethod.GET) + public String showarticlecustomcontainer( + Model model, @RequestParam(value = "id", defaultValue = "1") int id) { + String customMd = articleService.getArticleMdStr(id); + model.addAttribute("customMd", customMd); + model.addAttribute("id", id); + return "showarticlecustomcontanier"; + } + + // 鍒犻櫎鏂囩珷 + @RequestMapping(value = "/delete", method = RequestMethod.GET) + public void delete( + @RequestParam(value = "id", required = true) int id, HttpServletResponse response) + throws IOException { + if (session.getAttribute("username") != null) { + articleService.deleteArticleById(id); + } else { + response.sendRedirect("deletenologin"); + } + } + + // 娌℃湁鐧婚檰鐨勬椂鍊欙紝灏变笉鑳藉垹闄ゆ枃绔 + @RequestMapping("/deletenologin") + public String deletenologin() { + return "admin/error"; + } + + /* + // 杩斿洖姝e父妯″紡 + @RequestMapping(value="/backhtml", method=RequestMethod.POST) + public String backhtml(HttpServletRequest request, HttpServletResponse response, + Model model, @RequestParam(value="md", required=true)String md) { + System.out.println("backmd = " + md); + model.addAttribute("backmd", md); + return "showarticle"; + }*/ + + // 杩斿洖璇勮鏁版渶澶氱殑鍥涚瘒鏂囩珷 + @RequestMapping("/postarticle") + @ResponseBody + public Msg postarticle() { + List list = articleService.getAll(); + List postList = articleService.postarticle(list); + return Msg.success().add("postList", postList); + } + + @RequestMapping("about") + public String about() { + return "about"; + } + + @RequestMapping("/contact") + public String contact() { + return "contact"; + } } diff --git a/src/controller/CategoryController.java b/src/controller/CategoryController.java index 58c948a..11d4e52 100644 --- a/src/controller/CategoryController.java +++ b/src/controller/CategoryController.java @@ -21,78 +21,80 @@ @Controller public class CategoryController { - private final CategoryService categoryService; + private final CategoryService categoryService; - private final HttpSession session; + private final HttpSession session; - @Autowired - public CategoryController(CategoryService categoryService, HttpSession session) { - this.categoryService = categoryService; - this.session = session; - } + @Autowired + public CategoryController(CategoryService categoryService, HttpSession session) { + this.categoryService = categoryService; + this.session = session; + } - // tags 杩斿洖鏍囩锛堟垜鎶婂畠鐞嗚В涓哄垎绫伙級 - @RequestMapping(value="/getTags",method=RequestMethod.GET) - @ResponseBody - public Msg getTags() { - List tags = categoryService.getCategory(); - return Msg.success().add("tags", tags); - } + // tags 杩斿洖鏍囩锛堟垜鎶婂畠鐞嗚В涓哄垎绫伙級 + @RequestMapping(value = "/getTags", method = RequestMethod.GET) + @ResponseBody + public Msg getTags() { + List tags = categoryService.getCategory(); + return Msg.success().add("tags", tags); + } + // 鍒嗙被鐨勫悗鍙扮鐞 + @RequestMapping(value = "/tagadmin") + public String tagadmin() { + String username = null; + if (session.getAttribute("username") != null) { + username = session.getAttribute("username").toString(); + } - // 鍒嗙被鐨勫悗鍙扮鐞 - @RequestMapping(value="/tagadmin") - public String tagadmin() { - String username = null; - if(session.getAttribute("username") != null) { - username = session.getAttribute("username").toString(); - } + if (username == null) { + return "admin/error"; + } + return "admin/tagadmin"; + } - if(username == null) { - return "admin/error"; - } - return "admin/tagadmin"; - } + // 鏂板缓鍒嗙被 + @RequestMapping(value = "/newtag", method = RequestMethod.POST) + public String newtag( + @RequestParam(value = "name", required = true) String name, + @RequestParam(value = "level", required = true) String level, + Model model) { + categoryService.newtag(name, level); + model.addAttribute("msg", "鏂板缓鍒嗙被鎴愬姛锛"); + return "admin/newtagsuccess"; + } - // 鏂板缓鍒嗙被 - @RequestMapping(value="/newtag", method=RequestMethod.POST) - public String newtag(@RequestParam(value="name", required=true) String name, - @RequestParam(value="level", required=true)String level,Model model) { - categoryService.newtag(name, level); - model.addAttribute("msg", "鏂板缓鍒嗙被鎴愬姛锛"); - return "admin/newtagsuccess"; - } + // 鍒犻櫎鍒嗙被 + @RequestMapping(value = "deletetag", method = RequestMethod.GET) + @ResponseBody + public Msg deletetag(@RequestParam(value = "id", required = true) int id) { + String username = null; + if (session.getAttribute("username") != null) { + username = session.getAttribute("username").toString(); + } + if (username == null) { + return Msg.fail().add("msg", "浣犳病鏈夌櫥闄"); + } + categoryService.deltag(id); + return Msg.success().add("msg", "鍒犻櫎鍒嗙被鎴愬姛锛"); + } - // 鍒犻櫎鍒嗙被 - @RequestMapping(value="deletetag", method=RequestMethod.GET) - @ResponseBody - public Msg deletetag(@RequestParam(value="id", required=true)int id) { - String username = null; - if(session.getAttribute("username") != null) { - username = session.getAttribute("username").toString(); - } - if(username == null) { - return Msg.fail().add("msg", "浣犳病鏈夌櫥闄"); - } - categoryService.deltag(id); - return Msg.success().add("msg", "鍒犻櫎鍒嗙被鎴愬姛锛"); - } + @RequestMapping("tag") + public String tag(@RequestParam("id") int id, Model model) { + model.addAttribute("id", id); + return "tag"; + } - @RequestMapping("tag") - public String tag(@RequestParam("id")int id, Model model) { - model.addAttribute("id", id); - return "tag"; - } - - // 杩斿洖璇ュ垎绫绘墍鏈夌殑鏂囩珷 - @RequestMapping(value="/tagarticle", method=RequestMethod.GET) - @ResponseBody - public Msg tagarticle(@RequestParam("id") int id, - @RequestParam(value = "pn", defaultValue = "1") Integer pn, - Model model) { - PageHelper.startPage(pn, 5); - List list = categoryService.getTagArticles(id); - PageInfo pageInfo = new PageInfo<>(list, 5); - return Msg.success().add("pageInfo", pageInfo); - } + // 杩斿洖璇ュ垎绫绘墍鏈夌殑鏂囩珷 + @RequestMapping(value = "/tagarticle", method = RequestMethod.GET) + @ResponseBody + public Msg tagarticle( + @RequestParam("id") int id, + @RequestParam(value = "pn", defaultValue = "1") Integer pn, + Model model) { + PageHelper.startPage(pn, 5); + List list = categoryService.getTagArticles(id); + PageInfo pageInfo = new PageInfo<>(list, 5); + return Msg.success().add("pageInfo", pageInfo); + } } diff --git a/src/controller/CommentController.java b/src/controller/CommentController.java index 05da3cc..c5be2fb 100644 --- a/src/controller/CommentController.java +++ b/src/controller/CommentController.java @@ -20,77 +20,82 @@ @Controller public class CommentController { - private final CommentService commentService; + private final CommentService commentService; - private final HttpSession session; + private final HttpSession session; - @Autowired - public CommentController(CommentService commentService, HttpSession session) { - this.commentService = commentService; - this.session = session; - } + @Autowired + public CommentController(CommentService commentService, HttpSession session) { + this.commentService = commentService; + this.session = session; + } - // 鎻愪氦璇勮 - @RequestMapping(value="/sendcomment", method=RequestMethod.POST) - @ResponseBody - public Msg sendcomment(@RequestParam(value="id", required=true)int id, - @RequestParam("name") String name, @RequestParam("comment") String comment) throws ParseException { - commentService.sendcomment(id, name, comment); - Msg msg = Msg.success(); - msg.setMsg("鎻愪氦璇勮鎴愬姛锛"); - return msg; - } - - // 鑾峰緱璇勮 - @RequestMapping(value="/getComments", method=RequestMethod.GET) - @ResponseBody - public Msg getComments(@RequestParam("id")int id) { - // 鑾峰彇鏂囩珷鎵鏈夌殑璇勮 - List list = commentService.getComments(id); - return Msg.success().add("commentsList", list); - } - - // 鑾峰緱鎵鏈夎瘎璁 - @RequestMapping(value="/getallcomments", method=RequestMethod.GET) - @ResponseBody - public Msg getallcomments() { - List list = commentService.selectAll(); - return Msg.success().add("commentList", list); - } - - // 璇勮鍚庡彴绠$悊 - @RequestMapping("/commentback") - public String commentback() { - //寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 - if(session.getAttribute("username") != null) { - String username = session.getAttribute("username").toString(); - if(username != null) { - return "admin/commentadmin"; - } - } - return "admin/error"; - } - - // 鍒犻櫎涓鏉¤瘎璁 - @RequestMapping(value="/deleteacomment",method=RequestMethod.GET) - @ResponseBody - public Msg deleteacomment(@RequestParam("id") int id) { - commentService.deletea(id); - Msg msg = Msg.success(); - msg.setMsg("姝ゆ潯璇勮宸插垹闄わ紒"); - return msg; - } - - // 鎻愪氦璇勮 - @RequestMapping(value="/sendheartword", method=RequestMethod.POST) - @ResponseBody - public Msg sendheartword(@RequestParam(value="id", required=true)int id, - @RequestParam("name") String name, @RequestParam("comment") String comment) throws ParseException { - System.out.println("name = " + name + " \ncomment = " + comment); - commentService.sendcomment(id, name, comment); - Msg msg = Msg.success(); - msg.setMsg("鎴戞敹鍒颁綘鐨勫績澹颁簡锛"); - return msg; - } + // 鎻愪氦璇勮 + @RequestMapping(value = "/sendcomment", method = RequestMethod.POST) + @ResponseBody + public Msg sendcomment( + @RequestParam(value = "id", required = true) int id, + @RequestParam("name") String name, + @RequestParam("comment") String comment) + throws ParseException { + commentService.sendcomment(id, name, comment); + Msg msg = Msg.success(); + msg.setMsg("鎻愪氦璇勮鎴愬姛锛"); + return msg; + } + // 鑾峰緱璇勮 + @RequestMapping(value = "/getComments", method = RequestMethod.GET) + @ResponseBody + public Msg getComments(@RequestParam("id") int id) { + // 鑾峰彇鏂囩珷鎵鏈夌殑璇勮 + List list = commentService.getComments(id); + return Msg.success().add("commentsList", list); + } + + // 鑾峰緱鎵鏈夎瘎璁 + @RequestMapping(value = "/getallcomments", method = RequestMethod.GET) + @ResponseBody + public Msg getallcomments() { + List list = commentService.selectAll(); + return Msg.success().add("commentList", list); + } + + // 璇勮鍚庡彴绠$悊 + @RequestMapping("/commentback") + public String commentback() { + // 寰楀埌 session 鐨勫硷紝鍒ゆ柇鏄惁宸茬粡鐧婚檰 + if (session.getAttribute("username") != null) { + String username = session.getAttribute("username").toString(); + if (username != null) { + return "admin/commentadmin"; + } + } + return "admin/error"; + } + + // 鍒犻櫎涓鏉¤瘎璁 + @RequestMapping(value = "/deleteacomment", method = RequestMethod.GET) + @ResponseBody + public Msg deleteacomment(@RequestParam("id") int id) { + commentService.deletea(id); + Msg msg = Msg.success(); + msg.setMsg("姝ゆ潯璇勮宸插垹闄わ紒"); + return msg; + } + + // 鎻愪氦璇勮 + @RequestMapping(value = "/sendheartword", method = RequestMethod.POST) + @ResponseBody + public Msg sendheartword( + @RequestParam(value = "id", required = true) int id, + @RequestParam("name") String name, + @RequestParam("comment") String comment) + throws ParseException { + System.out.println("name = " + name + " \ncomment = " + comment); + commentService.sendcomment(id, name, comment); + Msg msg = Msg.success(); + msg.setMsg("鎴戞敹鍒颁綘鐨勫績澹颁簡锛"); + return msg; + } } diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java index 33a8585..5185e3f 100644 --- a/src/controller/LoginController.java +++ b/src/controller/LoginController.java @@ -12,40 +12,42 @@ import service.LoginService; - @Controller public class LoginController { - private final LoginService service; - - @Autowired - public LoginController(LoginService service) { - this.service = service; - } - - @RequestMapping("/login") - public String login() { - return "admin/login"; - } - - @RequestMapping(value="/validatellogin") - public String validatelogin(@RequestParam(value="username", required=false)String username, - @RequestParam(value="password",required=false)String password, HttpServletRequest request, - HttpServletResponse response) throws SaslException { - if(request.getSession().getAttribute("username") != null) { - return "admin/backadmin"; - } - if(service.validate(username, password)) { - HttpSession session = request.getSession(); - session.setAttribute("username", username); - return "admin/backadmin"; - } - return "admin/loginfail"; - } - - // 閫鍑虹櫥闄 - @RequestMapping("logout") - public String logout(HttpServletRequest request, HttpServletResponse response) { - request.getSession().removeAttribute("username"); - return "redirect:/login"; - } + private final LoginService service; + + @Autowired + public LoginController(LoginService service) { + this.service = service; + } + + @RequestMapping("/login") + public String login() { + return "admin/login"; + } + + @RequestMapping(value = "/validatellogin") + public String validatelogin( + @RequestParam(value = "username", required = false) String username, + @RequestParam(value = "password", required = false) String password, + HttpServletRequest request, + HttpServletResponse response) + throws SaslException { + if (request.getSession().getAttribute("username") != null) { + return "admin/backadmin"; + } + if (service.validate(username, password)) { + HttpSession session = request.getSession(); + session.setAttribute("username", username); + return "admin/backadmin"; + } + return "admin/loginfail"; + } + + // 閫鍑虹櫥闄 + @RequestMapping("logout") + public String logout(HttpServletRequest request, HttpServletResponse response) { + request.getSession().removeAttribute("username"); + return "redirect:/login"; + } } diff --git a/src/controller/UploadfileController.java b/src/controller/UploadfileController.java index 6255ad7..4645c40 100644 --- a/src/controller/UploadfileController.java +++ b/src/controller/UploadfileController.java @@ -18,32 +18,33 @@ @Controller public class UploadfileController { - Logger log = Logger.getLogger(this.getClass()); - - @RequestMapping(value = "uploadImg", method = RequestMethod.POST) - public void uploadImg( - HttpServletRequest request, - HttpServletResponse response, - @RequestParam(value = "editormd-image-file", required = false) MultipartFile file) { - log.info("upload img"); - try { - request.setCharacterEncoding("utf-8"); - response.setHeader("Content-Type", "text/html"); - String suffix = file.getOriginalFilename().substring( - file.getOriginalFilename().lastIndexOf(".")); - String filePath = "/upload/" + DateUtil.getDays() + "/" + Myutil.random(5) + suffix; - String resultPath = UploadUtil.uploadImg(filePath, file.getInputStream()); - System.out.println("path="+resultPath); - response.getWriter().write( "{\"success\": 1, \"message\":\"涓婁紶鎴愬姛\",\"url\":\"" + filePath + "\"}" ); - } catch (Exception e) { - e.printStackTrace(); - log.error("upload failed ", e); - try { - response.getWriter().write( "{\"success\": 0, \"message\":\"涓婁紶澶辫触\",\"url\":\""+ "\"}" ); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - + Logger log = Logger.getLogger(this.getClass()); + + @RequestMapping(value = "uploadImg", method = RequestMethod.POST) + public void uploadImg( + HttpServletRequest request, + HttpServletResponse response, + @RequestParam(value = "editormd-image-file", required = false) MultipartFile file) { + log.info("upload img"); + try { + request.setCharacterEncoding("utf-8"); + response.setHeader("Content-Type", "text/html"); + String suffix = + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + String filePath = "/upload/" + DateUtil.getDays() + "/" + Myutil.random(5) + suffix; + String resultPath = UploadUtil.uploadImg(filePath, file.getInputStream()); + System.out.println("path=" + resultPath); + response + .getWriter() + .write("{\"success\": 1, \"message\":\"涓婁紶鎴愬姛\",\"url\":\"" + filePath + "\"}"); + } catch (Exception e) { + e.printStackTrace(); + log.error("upload failed ", e); + try { + response.getWriter().write("{\"success\": 0, \"message\":\"涓婁紶澶辫触\",\"url\":\"" + "\"}"); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } } From 594828dfbb710d8237226eb5da027eae721f7a1f Mon Sep 17 00:00:00 2001 From: aim467 <709544711@qq.com> Date: Sat, 19 Jun 2021 11:27:26 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E4=B8=BAajax=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WEB-INF/classes/applicationContext.xml | 31 +++---- WebRoot/WEB-INF/jsp/admin/backadmin.jsp | 38 ++++----- WebRoot/WEB-INF/jsp/admin/editsuccess.jsp | 2 +- WebRoot/WEB-INF/jsp/admin/error.jsp | 14 ++- WebRoot/WEB-INF/jsp/admin/login.jsp | 85 ++++++++++++------- src/applicationContext.xml | 4 +- src/controller/AdminController.java | 36 ++++++++ src/controller/LoginController.java | 19 +++-- src/entity/Msg.java | 20 ++++- 9 files changed, 168 insertions(+), 81 deletions(-) create mode 100644 src/controller/AdminController.java diff --git a/WebRoot/WEB-INF/classes/applicationContext.xml b/WebRoot/WEB-INF/classes/applicationContext.xml index 6135075..c0385d6 100644 --- a/WebRoot/WEB-INF/classes/applicationContext.xml +++ b/WebRoot/WEB-INF/classes/applicationContext.xml @@ -1,29 +1,26 @@ - + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> + - - - - + + + + - + classpath:mapping/*.xml @@ -59,8 +56,8 @@ - - + + diff --git a/WebRoot/WEB-INF/jsp/admin/backadmin.jsp b/WebRoot/WEB-INF/jsp/admin/backadmin.jsp index 929cd7d..1569b57 100644 --- a/WebRoot/WEB-INF/jsp/admin/backadmin.jsp +++ b/WebRoot/WEB-INF/jsp/admin/backadmin.jsp @@ -15,17 +15,17 @@ src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> --> - - + + - + - - - + +
@@ -53,11 +53,11 @@
- + @@ -116,16 +116,16 @@ li.css("word-wrap","break-word").css("word-break","break-all") .css("overflow","hidden"); var div = $("
").addClass("btn-group").css("float","right"); - - /* */ - - + + var editBtn = $("").addClass("btn btn-primary").append("缂栬緫") .appendTo(div); editBtn.bind("click", function() { edit(item.id); - }); + }); var delBtn = $("").addClass("btn btn-danger").append("鍒犻櫎").attr("data-toggle", "modal") .attr("data-target", "#myModal").appendTo(div); delBtn.bind("click", function() { @@ -212,17 +212,17 @@ var navEle = $("").append(ul); navEle.appendTo("#page_nav_area"); } - + // 鏂板缓鍗氬鐨勬帶鍒跺櫒鏄犲皠 function newblog() { - window.location='${APP_PATH }/islogin'; + window.location='${APP_PATH }/islogin'; } - + // 缂栬緫鍗氬鍙戝嚭鐨勮姹 function edit(id) { window.location='${APP_PATH }/edit?id=' + id; }; - + // 鍒犻櫎鍑芥暟 function del(id, pageNum) { alert(id); @@ -235,7 +235,7 @@ alert("鍒犻櫎鎴愬姛锛"); // 鍥炲埌褰撳墠椤 to_page(pageNum); - } + } }); }); } diff --git a/WebRoot/WEB-INF/jsp/admin/editsuccess.jsp b/WebRoot/WEB-INF/jsp/admin/editsuccess.jsp index 42bd1b0..3d1f7ed 100644 --- a/WebRoot/WEB-INF/jsp/admin/editsuccess.jsp +++ b/WebRoot/WEB-INF/jsp/admin/editsuccess.jsp @@ -10,6 +10,6 @@ 鐜嬮攼楣忓崥瀹 - ${map.message }缁х画淇敼鏂囩珷 + ${map.message }缁х画淇敼鏂囩珷 \ No newline at end of file diff --git a/WebRoot/WEB-INF/jsp/admin/error.jsp b/WebRoot/WEB-INF/jsp/admin/error.jsp index d6e0da7..900601d 100644 --- a/WebRoot/WEB-INF/jsp/admin/error.jsp +++ b/WebRoot/WEB-INF/jsp/admin/error.jsp @@ -7,6 +7,18 @@ 鐜嬮攼楣忓崥瀹紒 - 浣犳病鏈夌櫥闄嗭紒 + + + \ No newline at end of file diff --git a/WebRoot/WEB-INF/jsp/admin/login.jsp b/WebRoot/WEB-INF/jsp/admin/login.jsp index 48786de..b00137e 100644 --- a/WebRoot/WEB-INF/jsp/admin/login.jsp +++ b/WebRoot/WEB-INF/jsp/admin/login.jsp @@ -1,44 +1,71 @@ <%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> + pageEncoding="UTF-8" %> <% - pageContext.setAttribute("APP_PATH", request.getContextPath()); + pageContext.setAttribute("APP_PATH", request.getContextPath()); %> - + - 鐜嬮攼楣忓崥瀹 - - + 鐜嬮攼楣忓崥瀹 + + -
-
-
-

鐧婚檰鐣岄潰

- - -
-
-
+
+
+
+

鐧婚檰鐣岄潰

+ + +
+
+
+ + \ No newline at end of file diff --git a/src/applicationContext.xml b/src/applicationContext.xml index ac5b598..b3f9e62 100644 --- a/src/applicationContext.xml +++ b/src/applicationContext.xml @@ -15,8 +15,8 @@ class="org.springframework.jdbc.datasource.DriverManagerDataSource"> - - + + diff --git a/src/controller/AdminController.java b/src/controller/AdminController.java new file mode 100644 index 0000000..a334e31 --- /dev/null +++ b/src/controller/AdminController.java @@ -0,0 +1,36 @@ +package controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import javax.servlet.http.HttpSession; + +@Controller +@RequestMapping(value = "/admin") +public class AdminController { + private final HttpSession session; + + @Autowired + public AdminController(HttpSession session) { + this.session = session; + } + + @RequestMapping(value = "/") + public String index() { + if (session.getAttribute("username") == null) { + return "admin/error"; + } + return "admin/backadmin"; + } + + /** + * 閲嶅畾鍚戝埌/admin/ + * + * @return + */ + @RequestMapping(value = "") + public String toLogin() { + return "redirect:/admin/"; + } +} diff --git a/src/controller/LoginController.java b/src/controller/LoginController.java index 5185e3f..5b6ee36 100644 --- a/src/controller/LoginController.java +++ b/src/controller/LoginController.java @@ -5,11 +5,14 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import entity.Msg; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import service.LoginService; @Controller @@ -26,22 +29,20 @@ public String login() { return "admin/login"; } - @RequestMapping(value = "/validatellogin") - public String validatelogin( + @RequestMapping(value = "/doLogin", method = RequestMethod.POST) + @ResponseBody + public Msg doLogin( @RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, - HttpServletRequest request, - HttpServletResponse response) + HttpServletRequest request) throws SaslException { - if (request.getSession().getAttribute("username") != null) { - return "admin/backadmin"; - } + if (service.validate(username, password)) { HttpSession session = request.getSession(); session.setAttribute("username", username); - return "admin/backadmin"; + return Msg.success("鐧诲綍鎴愬姛!锛屾鍦ㄨ繘鍏ュ悗鍙"); } - return "admin/loginfail"; + return Msg.fail("鐧诲綍澶辫触!"); } // 閫鍑虹櫥闄 diff --git a/src/entity/Msg.java b/src/entity/Msg.java index b424433..2c7c2d0 100644 --- a/src/entity/Msg.java +++ b/src/entity/Msg.java @@ -11,19 +11,33 @@ public class Msg { //鐢ㄦ埛瑕佽繑鍥炵粰娴忚鍣ㄧ殑鏁版嵁 private Map extend = new HashMap(); - public static Msg success(){ + public static Msg success() { Msg result = new Msg(); result.setCode(100); result.setMsg("澶勭悊鎴愬姛锛"); return result; } - - public static Msg fail(){ + + public static Msg success(String message) { + Msg result = new Msg(); + result.setCode(100); + result.setMsg(message); + return result; + } + + public static Msg fail() { Msg result = new Msg(); result.setCode(200); result.setMsg("澶勭悊澶辫触锛"); return result; } + + public static Msg fail(String message) { + Msg result = new Msg(); + result.setCode(200); + result.setMsg(message); + return result; + } public Msg add(String key,Object value){ this.getExtend().put(key, value); From 8e8a10d99e28f238e16565f6b3c32e17a1bac8c8 Mon Sep 17 00:00:00 2001 From: aim467 <709544711@qq.com> Date: Sat, 19 Jun 2021 11:44:32 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BC=98=E5=8C=96=E4=BA=86=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=92=8C=E4=BF=AE=E6=94=B9=E6=96=87=E7=AB=A0?= =?UTF-8?q?=20=E4=BD=BF=E7=94=A8Ajax=E5=AE=9E=E7=8E=B0=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E7=9A=84=E4=BF=9D=E5=AD=98=E4=B8=8E=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebRoot/WEB-INF/jsp/admin/edit.jsp | 110 ++++++++++++++++---------- WebRoot/WEB-INF/jsp/admin/newblog.jsp | 106 ++++++++++++++++--------- src/applicationContext.xml | 4 +- src/controller/ArticleController.java | 79 ++++++------------ src/entity/ArticleVO.java | 105 ++++++++++++++++++++++++ 5 files changed, 265 insertions(+), 139 deletions(-) create mode 100644 src/entity/ArticleVO.java diff --git a/WebRoot/WEB-INF/jsp/admin/edit.jsp b/WebRoot/WEB-INF/jsp/admin/edit.jsp index a87cb51..18db3bd 100644 --- a/WebRoot/WEB-INF/jsp/admin/edit.jsp +++ b/WebRoot/WEB-INF/jsp/admin/edit.jsp @@ -11,16 +11,16 @@ 鐜嬮攼楣忓崥瀹 - + - - + - - + +