修复保存带html后缀路径的问题

具体表现为: 新建文章时, "永久链接"以.html或者.htm结尾, 可以保存, 查看时ControllerNPE
pull/8/head
Henry 2018-05-09 16:50:57 +08:00
parent b9023a7b26
commit 2d1143389e
1 changed files with 13 additions and 0 deletions

View File

@ -176,6 +176,7 @@ public class PostController extends BaseController{
List<Tag> tags = tagService.strListToTagList(StringUtils.trim(tagList));
post.setTags(tags);
}
post.setPostUrl(urlFilter(post.getPostUrl()));
postService.saveByPost(post);
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate()));
}catch (Exception e){
@ -183,6 +184,17 @@ public class PostController extends BaseController{
}
}
private static String urlFilter(String url) {
if (null != url) {
final boolean urlEndsWithHtmlPostFix = url.endsWith(".html") || url.endsWith(".htm");
if (urlEndsWithHtmlPostFix) {
return url.substring(0, url.lastIndexOf("."));
}
}
return url;
}
/**
*
*
@ -282,6 +294,7 @@ public class PostController extends BaseController{
@GetMapping(value = "/checkUrl")
@ResponseBody
public boolean checkUrlExists(@PathParam("postUrl") String postUrl){
postUrl = urlFilter(postUrl);
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
return null!=post;
}