👽 优化了大量重复代码,持续优化中

pull/1/head
RYAN0UP_ 2018-04-26 23:54:02 +08:00
parent d0d7e90a16
commit ec92b35f2f
26 changed files with 212 additions and 304 deletions

View File

@ -0,0 +1,47 @@
package cc.ryanc.halo.config;
import cc.ryanc.halo.model.tag.ArticleTagDirective;
import cc.ryanc.halo.model.tag.CommonTagDirective;
import cc.ryanc.halo.service.OptionsService;
import cc.ryanc.halo.service.UserService;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
/**
* @author : RYAN0UP
* @version : 1.0
* @date : 2018/4/26
*/
@Configuration
public class FreeMarkerConfig {
@Autowired
private freemarker.template.Configuration configuration;
@Autowired
private OptionsService optionsService;
@Autowired
private UserService userService;
@Autowired
private CommonTagDirective commonTagDirective;
@Autowired
private ArticleTagDirective articleTagDirective;
@PostConstruct
public void setSharedVariable(){
configuration.setSharedVariable("commonTag",commonTagDirective);
configuration.setSharedVariable("articleTag",articleTagDirective);
try{
configuration.setSharedVariable("options",optionsService.findAllOptions());
configuration.setSharedVariable("user",userService.findUser());
}catch (TemplateModelException e){
e.printStackTrace();
}
}
}

View File

@ -29,7 +29,7 @@ import java.util.Map;
@EnableWebMvc @EnableWebMvc
@ComponentScan(basePackages = "cc.ryanc.halo.web.controller") @ComponentScan(basePackages = "cc.ryanc.halo.web.controller")
@PropertySource(value = "classpath:application.yaml",ignoreResourceNotFound = true,encoding = "UTF-8") @PropertySource(value = "classpath:application.yaml",ignoreResourceNotFound = true,encoding = "UTF-8")
public class MvcConfiguration implements WebMvcConfigurer { public class MvcConfig implements WebMvcConfigurer {
@Autowired @Autowired
private LoginInterceptor loginInterceptor; private LoginInterceptor loginInterceptor;

View File

@ -24,7 +24,7 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
@Configuration @Configuration
public class StartupConfiguration implements ApplicationListener<ContextRefreshedEvent>{ public class StartupConfig implements ApplicationListener<ContextRefreshedEvent>{
@Autowired @Autowired
private OptionsService optionsService; private OptionsService optionsService;

View File

@ -0,0 +1,40 @@
package cc.ryanc.halo.model.tag;
import cc.ryanc.halo.service.PostService;
import freemarker.core.Environment;
import freemarker.template.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Map;
/**
* @author : RYAN0UP
* @version : 1.0
* @date : 2018/4/26
*/
@Component
public class ArticleTagDirective implements TemplateDirectiveModel {
private static final String METHOD_KEY = "method";
@Autowired
private PostService postService;
@Override
public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
if(map.containsKey(METHOD_KEY)){
String method = map.get(METHOD_KEY).toString();
switch (method){
case "postsCount":
environment.setVariable("postsCount",builder.build().wrap(postService.findAllPosts().size()));
break;
default:
break;
}
}
templateDirectiveBody.render(environment.getOut());
}
}

View File

@ -0,0 +1,47 @@
package cc.ryanc.halo.model.tag;
import cc.ryanc.halo.service.CategoryService;
import cc.ryanc.halo.service.MenuService;
import freemarker.core.Environment;
import freemarker.template.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Map;
/**
* @author : RYAN0UP
* @version : 1.0
* @date : 2018/4/26
*/
@Component
public class CommonTagDirective implements TemplateDirectiveModel {
private static final String METHOD_KEY = "method";
@Autowired
private MenuService menuService;
@Autowired
private CategoryService categoryService;
@Override
public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
if(map.containsKey(METHOD_KEY)){
String method = map.get(METHOD_KEY).toString();
switch (method){
case "menus":
environment.setVariable("menus",builder.build().wrap(menuService.findAllMenus()));
break;
case "categories":
environment.setVariable("categories",builder.build().wrap(categoryService.findAllCategories()));
break;
default:
break;
}
}
templateDirectiveBody.render(environment.getOut());
}
}

View File

@ -86,8 +86,6 @@ public class AdminController extends BaseController{
model.addAttribute("mediaCount",HaloConst.ATTACHMENTS.size()); model.addAttribute("mediaCount",HaloConst.ATTACHMENTS.size());
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
this.getNewComments(session); this.getNewComments(session);
return "admin/admin_index"; return "admin/admin_index";
} }
@ -99,9 +97,8 @@ public class AdminController extends BaseController{
* @return admin/admin_login * @return admin/admin_login
*/ */
@GetMapping(value = "/login") @GetMapping(value = "/login")
public String login(HttpSession session,Model model){ public String login(HttpSession session){
model.addAttribute("options",HaloConst.OPTIONS); User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
User user = (User) session.getAttribute("user");
//如果session存在跳转到后台首页 //如果session存在跳转到后台首页
if(null!=user){ if(null!=user){
return "redirect:/admin"; return "redirect:/admin";
@ -210,12 +207,10 @@ public class AdminController extends BaseController{
/** /**
* *
* *
* @param model model
* @return admin/admin_halo * @return admin/admin_halo
*/ */
@GetMapping(value = "/halo") @GetMapping(value = "/halo")
public String halo(Model model){ public String halo(){
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_halo"; return "admin/admin_halo";
} }
} }

View File

@ -69,8 +69,6 @@ public class AttachmentController {
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable); Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
model.addAttribute("attachments",attachments); model.addAttribute("attachments",attachments);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_attachment"; return "admin/admin_attachment";
} }
@ -90,9 +88,6 @@ public class AttachmentController {
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable); Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
model.addAttribute("attachments",attachments); model.addAttribute("attachments",attachments);
model.addAttribute("id",id); model.addAttribute("id",id);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/widget/_attachment-select"; return "admin/widget/_attachment-select";
} }

View File

@ -1,13 +1,11 @@
package cc.ryanc.halo.web.controller.admin; package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.util.HaloUtil; import cc.ryanc.halo.util.HaloUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -36,10 +34,7 @@ public class BackupController {
* @return admin/admin_backup * @return admin/admin_backup
*/ */
@GetMapping @GetMapping
public String backup(Model model){ public String backup(){
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_backup"; return "admin/admin_backup";
} }

View File

@ -1,7 +1,6 @@
package cc.ryanc.halo.web.controller.admin; package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Category; import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.CategoryService; import cc.ryanc.halo.service.CategoryService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -10,7 +9,6 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.websocket.server.PathParam; import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Optional; import java.util.Optional;
/** /**
@ -35,11 +33,7 @@ public class CategoryController {
*/ */
@GetMapping @GetMapping
public String categories(Model model){ public String categories(Model model){
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
model.addAttribute("statusName","添加"); model.addAttribute("statusName","添加");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_category"; return "admin/admin_category";
} }
@ -102,13 +96,9 @@ public class CategoryController {
*/ */
@GetMapping(value = "/edit") @GetMapping(value = "/edit")
public String toEditCategory(Model model,@PathParam("cateId") Long cateId){ public String toEditCategory(Model model,@PathParam("cateId") Long cateId){
List<Category> categories = categoryService.findAllCategories();
Optional<Category> category = categoryService.findByCateId(cateId); Optional<Category> category = categoryService.findByCateId(cateId);
model.addAttribute("updateCategory",category.get()); model.addAttribute("updateCategory",category.get());
model.addAttribute("categories",categories);
model.addAttribute("statusName","修改"); model.addAttribute("statusName","修改");
//设置选项
model.addAttribute("options", HaloConst.OPTIONS);
return "admin/admin_category"; return "admin/admin_category";
} }
} }

View File

@ -73,9 +73,6 @@ public class CommentController extends BaseController{
model.addAttribute("checkCount",commentService.findAllComments(1,pageable).getTotalElements()); model.addAttribute("checkCount",commentService.findAllComments(1,pageable).getTotalElements());
model.addAttribute("trashCount",commentService.findAllComments(2,pageable).getTotalElements()); model.addAttribute("trashCount",commentService.findAllComments(2,pageable).getTotalElements());
model.addAttribute("status",status); model.addAttribute("status",status);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_comment"; return "admin/admin_comment";
} }

View File

@ -1,7 +1,6 @@
package cc.ryanc.halo.web.controller.admin; package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Menu; import cc.ryanc.halo.model.domain.Menu;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.MenuService; import cc.ryanc.halo.service.MenuService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -10,7 +9,6 @@ import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.websocket.server.PathParam; import javax.websocket.server.PathParam;
import java.util.List;
/** /**
* @author : RYAN0UP * @author : RYAN0UP
@ -34,11 +32,7 @@ public class MenuController {
*/ */
@GetMapping @GetMapping
public String menus(Model model){ public String menus(Model model){
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
model.addAttribute("statusName","添加"); model.addAttribute("statusName","添加");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "/admin/admin_menu"; return "/admin/admin_menu";
} }
@ -67,13 +61,9 @@ public class MenuController {
*/ */
@GetMapping(value = "/edit") @GetMapping(value = "/edit")
public String updateMenu(@RequestParam("menuId") Long menuId,Model model){ public String updateMenu(@RequestParam("menuId") Long menuId,Model model){
List<Menu> menus = menuService.findAllMenus();
Menu menu = menuService.findByMenuId(menuId).get(); Menu menu = menuService.findByMenuId(menuId).get();
model.addAttribute("statusName","修改"); model.addAttribute("statusName","修改");
model.addAttribute("updateMenu",menu); model.addAttribute("updateMenu",menu);
model.addAttribute("menus",menus);
//设置选项
model.addAttribute("options", HaloConst.OPTIONS);
return "/admin/admin_menu"; return "/admin/admin_menu";
} }

View File

@ -5,7 +5,6 @@ import cc.ryanc.halo.service.OptionsService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Map; import java.util.Map;
@ -26,13 +25,10 @@ public class OptionController {
/** /**
* option * option
* *
* @param model model
* @return admin/admin_option * @return admin/admin_option
*/ */
@GetMapping @GetMapping
public String options(Model model){ public String options(){
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_option"; return "admin/admin_option";
} }

View File

@ -2,7 +2,6 @@ package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Gallery; import cc.ryanc.halo.model.domain.Gallery;
import cc.ryanc.halo.model.domain.Link; import cc.ryanc.halo.model.domain.Link;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.GalleryService; import cc.ryanc.halo.service.GalleryService;
import cc.ryanc.halo.service.LinkService; import cc.ryanc.halo.service.LinkService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -43,8 +42,7 @@ public class PageController {
* @return admin/admin_page * @return admin/admin_page
*/ */
@GetMapping @GetMapping
public String pages(Model model){ public String pages(){
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_page"; return "admin/admin_page";
} }
@ -59,9 +57,6 @@ public class PageController {
List<Link> links = linkService.findAllLinks(); List<Link> links = linkService.findAllLinks();
model.addAttribute("links",links); model.addAttribute("links",links);
model.addAttribute("statusName","添加"); model.addAttribute("statusName","添加");
//设置选项
model.addAttribute("options", HaloConst.OPTIONS);
return "admin/admin_page_link"; return "admin/admin_page_link";
} }
@ -79,8 +74,6 @@ public class PageController {
model.addAttribute("updateLink",link.get()); model.addAttribute("updateLink",link.get());
model.addAttribute("statusName","修改"); model.addAttribute("statusName","修改");
model.addAttribute("links",links); model.addAttribute("links",links);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_page_link"; return "admin/admin_page_link";
} }
@ -134,7 +127,6 @@ public class PageController {
Pageable pageable = new PageRequest(page,size,sort); Pageable pageable = new PageRequest(page,size,sort);
Page<Gallery> galleries = galleryService.findAllGalleries(pageable); Page<Gallery> galleries = galleryService.findAllGalleries(pageable);
model.addAttribute("galleries",galleries); model.addAttribute("galleries",galleries);
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_page_gallery"; return "admin/admin_page_gallery";
} }
@ -168,8 +160,6 @@ public class PageController {
public String gallery(Model model,@PathParam("galleryId") Long galleryId){ public String gallery(Model model,@PathParam("galleryId") Long galleryId){
Optional<Gallery> gallery = galleryService.findByGalleryId(galleryId); Optional<Gallery> gallery = galleryService.findByGalleryId(galleryId);
model.addAttribute("gallery",gallery.get()); model.addAttribute("gallery",gallery.get());
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/widget/_gallery-detail"; return "admin/widget/_gallery-detail";
} }

View File

@ -72,10 +72,6 @@ public class PostController extends BaseController{
model.addAttribute("draftCount",postService.findPostByStatus(1,pageable).getTotalElements()); model.addAttribute("draftCount",postService.findPostByStatus(1,pageable).getTotalElements());
model.addAttribute("trashCount",postService.findPostByStatus(2,pageable).getTotalElements()); model.addAttribute("trashCount",postService.findPostByStatus(2,pageable).getTotalElements());
model.addAttribute("status",status); model.addAttribute("status",status);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_post"; return "admin/admin_post";
} }
@ -115,8 +111,6 @@ public class PostController extends BaseController{
public String viewPost(@PathParam("postId") Long postId,Model model){ public String viewPost(@PathParam("postId") Long postId,Model model){
Optional<Post> post = postService.findByPostId(postId); Optional<Post> post = postService.findByPostId(postId);
model.addAttribute("post",post.get()); model.addAttribute("post",post.get());
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("post"); return this.render("post");
} }
@ -134,8 +128,6 @@ public class PostController extends BaseController{
model.addAttribute("categories",categories); model.addAttribute("categories",categories);
model.addAttribute("tags",tags); model.addAttribute("tags",tags);
model.addAttribute("btnPush","发布"); model.addAttribute("btnPush","发布");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
}catch (Exception e){ }catch (Exception e){
log.error("未知错误:{0}",e.getMessage()); log.error("未知错误:{0}",e.getMessage());
} }
@ -247,8 +239,6 @@ public class PostController extends BaseController{
List<Category> categories = categoryService.findAllCategories(); List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories); model.addAttribute("categories",categories);
model.addAttribute("btnPush","更新"); model.addAttribute("btnPush","更新");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
}catch (Exception e){ }catch (Exception e){
log.error("未知错误:{0}",e.getMessage()); log.error("未知错误:{0}",e.getMessage());
} }

View File

@ -1,7 +1,6 @@
package cc.ryanc.halo.web.controller.admin; package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.Tag; import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.TagService; import cc.ryanc.halo.service.TagService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -37,8 +36,6 @@ public class TagController {
List<Tag> tags = tagService.findAllTags(); List<Tag> tags = tagService.findAllTags();
model.addAttribute("tags",tags); model.addAttribute("tags",tags);
model.addAttribute("statusName","新增"); model.addAttribute("statusName","新增");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_tag"; return "admin/admin_tag";
} }
@ -106,7 +103,6 @@ public class TagController {
model.addAttribute("statusName","修改"); model.addAttribute("statusName","修改");
model.addAttribute("updateTag",tag); model.addAttribute("updateTag",tag);
model.addAttribute("tags",tags); model.addAttribute("tags",tags);
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_tag"; return "admin/admin_tag";
} }
} }

View File

@ -52,8 +52,6 @@ public class ThemeController extends BaseController{
if(null!=HaloConst.THEMES){ if(null!=HaloConst.THEMES){
model.addAttribute("themes",HaloConst.THEMES); model.addAttribute("themes",HaloConst.THEMES);
} }
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_theme"; return "admin/admin_theme";
} }
@ -147,8 +145,6 @@ public class ThemeController extends BaseController{
@GetMapping(value = "/options") @GetMapping(value = "/options")
public String setting(Model model,@RequestParam("theme") String theme){ public String setting(Model model,@RequestParam("theme") String theme){
model.addAttribute("themeDir",theme); model.addAttribute("themeDir",theme);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "themes/"+theme+"/module/options"; return "themes/"+theme+"/module/options";
} }
@ -162,8 +158,6 @@ public class ThemeController extends BaseController{
public String editor(Model model){ public String editor(Model model){
List<String> tpls = HaloUtil.getTplName(BaseController.THEME); List<String> tpls = HaloUtil.getTplName(BaseController.THEME);
model.addAttribute("tpls",tpls); model.addAttribute("tpls",tpls);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_theme-editor"; return "admin/admin_theme-editor";
} }

View File

@ -1,7 +1,6 @@
package cc.ryanc.halo.web.controller.admin; package cc.ryanc.halo.web.controller.admin;
import cc.ryanc.halo.model.domain.User; import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.UserService; import cc.ryanc.halo.service.UserService;
import cc.ryanc.halo.util.HaloUtil; import cc.ryanc.halo.util.HaloUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -29,14 +28,10 @@ public class UserController {
/** /**
* *
* *
* @param model model
* @return admin/admin_profile * @return admin/admin_profile
*/ */
@GetMapping @GetMapping
public String profile(Model model){ public String profile(){
model.addAttribute("user",userService.findUser());
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return "admin/admin_profile"; return "admin/admin_profile";
} }

View File

@ -1,15 +1,8 @@
package cc.ryanc.halo.web.controller.front; package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Menu;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.Archive;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.CategoryService;
import cc.ryanc.halo.service.MenuService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.service.UserService;
import cc.ryanc.halo.web.controller.core.BaseController; import cc.ryanc.halo.web.controller.core.BaseController;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -39,14 +32,6 @@ public class ArchivesController extends BaseController {
@Autowired @Autowired
private PostService postService; private PostService postService;
@Autowired
private UserService userService;
@Autowired
private CategoryService categoryService;
@Autowired
private MenuService menuService;
/** /**
* *
@ -76,9 +61,6 @@ public class ArchivesController extends BaseController {
Page<Post> posts = postService.findPostByStatus(0,pageable); Page<Post> posts = postService.findPostByStatus(0,pageable);
model.addAttribute("posts",posts); model.addAttribute("posts",posts);
//文章总数
model.addAttribute("postsCount",postService.findAllPosts().size());
model.addAttribute("is_archives",true); model.addAttribute("is_archives",true);
//包含[List<Post>,year,month,count] //包含[List<Post>,year,month,count]
@ -89,23 +71,9 @@ public class ArchivesController extends BaseController {
List<Archive> archivesLess = postService.findPostGroupByYear(); List<Archive> archivesLess = postService.findPostGroupByYear();
model.addAttribute("archivesLess",archivesLess); model.addAttribute("archivesLess",archivesLess);
//用户信息
User user = userService.findUser();
model.addAttribute("user",user);
//菜单列表
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
//所有分类目录
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
//是否是归档页,用于判断输出链接 //是否是归档页,用于判断输出链接
model.addAttribute("isArchives","true"); model.addAttribute("isArchives","true");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("archives"); return this.render("archives");
} }
@ -130,21 +98,6 @@ public class ArchivesController extends BaseController {
Page<Post> posts = postService.findPostByYearAndMonth(year,month,pageable); Page<Post> posts = postService.findPostByYearAndMonth(year,month,pageable);
model.addAttribute("posts",posts); model.addAttribute("posts",posts);
//文章总数
model.addAttribute("postsCount",postService.findAllPosts().size());
//用户信息
User user = userService.findUser();
model.addAttribute("user",user);
//分类目录
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
//菜单列表
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
//归档数据,包含[year,month,count,List<Post>] //归档数据,包含[year,month,count,List<Post>]
List<Archive> archives = postService.findPostGroupByYearAndMonth(); List<Archive> archives = postService.findPostGroupByYearAndMonth();
model.addAttribute("archives",archives); model.addAttribute("archives",archives);
@ -152,8 +105,6 @@ public class ArchivesController extends BaseController {
//是否是归档页,用于判断输出链接 //是否是归档页,用于判断输出链接
model.addAttribute("isArchives","true"); model.addAttribute("isArchives","true");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("archives"); return this.render("archives");
} }
@ -187,28 +138,11 @@ public class ArchivesController extends BaseController {
} }
model.addAttribute("post",post); model.addAttribute("post",post);
//文章总数
model.addAttribute("postsCount",postService.findAllPosts().size());
//用户信息
User user = userService.findUser();
model.addAttribute("user",user);
//所有分类目录
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
//归档数据,包含[year,month,count,List<Post>] //归档数据,包含[year,month,count,List<Post>]
List<Archive> archives = postService.findPostGroupByYearAndMonth(); List<Archive> archives = postService.findPostGroupByYearAndMonth();
//菜单列表
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
model.addAttribute("archives",archives); model.addAttribute("archives",archives);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("post"); return this.render("post");
} }
} }

View File

@ -1,15 +1,9 @@
package cc.ryanc.halo.web.controller.front; package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Menu;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.Archive;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.CategoryService;
import cc.ryanc.halo.service.MenuService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.service.UserService;
import cc.ryanc.halo.web.controller.core.BaseController; import cc.ryanc.halo.web.controller.core.BaseController;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -39,14 +33,6 @@ public class IndexController extends BaseController {
@Autowired @Autowired
private PostService postService; private PostService postService;
@Autowired
private UserService userService;
@Autowired
private CategoryService categoryService;
@Autowired
private MenuService menuService;
/** /**
* *
@ -83,29 +69,12 @@ public class IndexController extends BaseController {
Page<Post> posts = postService.findPostByStatus(0,pageable); Page<Post> posts = postService.findPostByStatus(0,pageable);
model.addAttribute("posts",posts); model.addAttribute("posts",posts);
//文章总数
model.addAttribute("postsCount",postService.findAllPosts().size());
model.addAttribute("is_home",true); model.addAttribute("is_home",true);
//用户信息
User user = userService.findUser();
model.addAttribute("user",user);
//所有分类目录
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
//菜单列表
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
//归档数据,包含[year,month,count,List<Post>] //归档数据,包含[year,month,count,List<Post>]
List<Archive> archives = postService.findPostGroupByYearAndMonth(); List<Archive> archives = postService.findPostGroupByYearAndMonth();
model.addAttribute("archives",archives); model.addAttribute("archives",archives);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("index"); return this.render("index");
} }

View File

@ -1,9 +1,11 @@
package cc.ryanc.halo.web.controller.front; package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.*; import cc.ryanc.halo.model.domain.Gallery;
import cc.ryanc.halo.model.domain.Link;
import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.Archive;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.service.GalleryService;
import cc.ryanc.halo.service.*; import cc.ryanc.halo.service.LinkService;
import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.web.controller.core.BaseController; import cc.ryanc.halo.web.controller.core.BaseController;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -23,18 +25,9 @@ public class PagesController extends BaseController {
@Autowired @Autowired
private GalleryService galleryService; private GalleryService galleryService;
@Autowired
private UserService userService;
@Autowired @Autowired
private PostService postService; private PostService postService;
@Autowired
private MenuService menuService;
@Autowired
private CategoryService categoryService;
@Autowired @Autowired
private LinkService linkService; private LinkService linkService;
@ -48,9 +41,6 @@ public class PagesController extends BaseController {
@GetMapping(value = "/about") @GetMapping(value = "/about")
public String about(Model model){ public String about(Model model){
model.addAttribute("about","709831589"); model.addAttribute("about","709831589");
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("about"); return this.render("about");
} }
@ -64,14 +54,8 @@ public class PagesController extends BaseController {
List<Gallery> galleries = galleryService.findAllGalleries(); List<Gallery> galleries = galleryService.findAllGalleries();
model.addAttribute("galleries",galleries); model.addAttribute("galleries",galleries);
//用户信息
User user = userService.findUser();
model.addAttribute("user",user);
model.addAttribute("is_gallery",true); model.addAttribute("is_gallery",true);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("gallery"); return this.render("gallery");
} }
@ -88,29 +72,12 @@ public class PagesController extends BaseController {
List<Link> links = linkService.findAllLinks(); List<Link> links = linkService.findAllLinks();
model.addAttribute("links",links); model.addAttribute("links",links);
//用户信息
User user = userService.findUser();
model.addAttribute("user",user);
model.addAttribute("is_links",true); model.addAttribute("is_links",true);
//文章总数
model.addAttribute("postsCount",postService.findAllPosts().size());
//菜单列表
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
//所有分类目录
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
//归档数据,包含[year,month,count,List<Post>] //归档数据,包含[year,month,count,List<Post>]
List<Archive> archives = postService.findPostGroupByYearAndMonth(); List<Archive> archives = postService.findPostGroupByYearAndMonth();
model.addAttribute("archives",archives); model.addAttribute("archives",archives);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("links"); return this.render("links");
} }
} }

View File

@ -1,9 +1,11 @@
package cc.ryanc.halo.web.controller.front; package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.*; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.Archive;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.*; import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.service.TagService;
import cc.ryanc.halo.web.controller.core.BaseController; import cc.ryanc.halo.web.controller.core.BaseController;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -31,18 +33,9 @@ public class TagsController extends BaseController {
@Autowired @Autowired
private TagService tagService; private TagService tagService;
@Autowired
private CategoryService categoryService;
@Autowired
private UserService userService;
@Autowired @Autowired
private PostService postService; private PostService postService;
@Autowired
private MenuService menuService;
/** /**
* *
* *
@ -55,27 +48,10 @@ public class TagsController extends BaseController {
List<Tag> tags = tagService.findAllTags(); List<Tag> tags = tagService.findAllTags();
model.addAttribute("tags",tags); model.addAttribute("tags",tags);
//所有分类目录
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
User user = userService.findUser();
model.addAttribute("user",user);
//文章总数
model.addAttribute("postsCount",postService.findAllPosts().size());
//菜单列表
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
//归档数据,包含[year,month,count,List<Post>] //归档数据,包含[year,month,count,List<Post>]
List<Archive> archives = postService.findPostGroupByYearAndMonth(); List<Archive> archives = postService.findPostGroupByYearAndMonth();
model.addAttribute("archives",archives); model.addAttribute("archives",archives);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("tags"); return this.render("tags");
} }
@ -112,13 +88,6 @@ public class TagsController extends BaseController {
Pageable pageable = new PageRequest(page-1,size,sort); Pageable pageable = new PageRequest(page-1,size,sort);
Page<Post> posts = postService.findPostsByTags(tag,pageable); Page<Post> posts = postService.findPostsByTags(tag,pageable);
model.addAttribute("posts",posts); model.addAttribute("posts",posts);
User user = userService.findUser();
model.addAttribute("user",user);
//菜单列表
List<Menu> menus = menuService.findAllMenus();
model.addAttribute("menus",menus);
//设置选项
model.addAttribute("options",HaloConst.OPTIONS);
return this.render("index"); return this.render("index");
} }
} }

View File

@ -96,6 +96,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<@commonTag method="categories">
<#list categories as cate> <#list categories as cate>
<tr> <tr>
<td>${cate.cateName}</td> <td>${cate.cateName}</td>
@ -112,6 +113,7 @@
</td> </td>
</tr> </tr>
</#list> </#list>
</@commonTag>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -93,6 +93,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<@commonTag method="menus">
<#list menus as menu> <#list menus as menu>
<tr> <tr>
<td>${menu.menuName}</td> <td>${menu.menuName}</td>
@ -109,6 +110,7 @@
</td> </td>
</tr> </tr>
</#list> </#list>
</@commonTag>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -1,4 +1,4 @@
<footer class="main-footer"> <footer class="main-footer">
<div class="pull-right hidden-xs"><a target="_blank" href="https://github.com/ruibaby/halo">1.0 Beta</a></div> <div class="pull-right hidden-xs"><a target="_blank" href="https://github.com/ruibaby/halo">1.0 Beta</a></div>
Thanks for using <strong><a href="/admin/halo">Halo</a>.</strong> Thanks for using <strong><a data-pjax="true" href="/admin/halo">Halo</a>.</strong>
</footer> </footer>

View File

@ -1,10 +1,12 @@
<div class="page-top animated fadeInDown"> <div class="page-top animated fadeInDown">
<div class="nav"> <div class="nav">
<@commonTag method="menus">
<#list menus?sort_by('menuSort') as menu> <#list menus?sort_by('menuSort') as menu>
<li> <li>
<a href="${menu.menuUrl}">${menu.menuName} </a> <a href="${menu.menuUrl}">${menu.menuName} </a>
</li> </li>
</#list> </#list>
</@commonTag>
</div> </div>
<div class="information"> <div class="information">
<div class="back_btn"> <div class="back_btn">

View File

@ -48,16 +48,19 @@
<b class="caret"></b> <b class="caret"></b>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<@commonTag method="categories">
<#list categories as cate> <#list categories as cate>
<li> <li>
<a class="sidebar_archives-link" href="/categories/${cate.cateUrl}/">${cate.cateName}<span class="sidebar_archives-count">4</span></a> <a class="sidebar_archives-link" href="/categories/${cate.cateUrl}/">${cate.cateName}<span class="sidebar_archives-count">4</span></a>
</li> </li>
</#list> </#list>
</@commonTag>
</ul> </ul>
</li> </li>
</#if> </#if>
<!-- Pages --> <!-- Pages -->
<@commonTag method="menus">
<#list menus?sort_by("menuSort") as menu> <#list menus?sort_by("menuSort") as menu>
<li> <li>
<a href="${menu.menuUrl}" title="${menu.menuName}"> <a href="${menu.menuUrl}" title="${menu.menuName}">
@ -68,13 +71,16 @@
</a> </a>
</li> </li>
</#list> </#list>
</@commonTag>
<#if options.theme_material_other_sidebar_postcount?default('true') == 'true'> <#if options.theme_material_other_sidebar_postcount?default('true') == 'true'>
<!-- Article Number --> <!-- Article Number -->
<li> <li>
<a href="/archives"> <a href="/archives">
文章总数 文章总数
<@articleTag method="postsCount">
<span class="sidebar-badge">${postsCount}</span> <span class="sidebar-badge">${postsCount}</span>
</@articleTag>
</a> </a>
</li> </li>
</#if> </#if>