mirror of https://github.com/halo-dev/halo
👽 优化了大量重复代码,持续优化中
parent
d0d7e90a16
commit
ec92b35f2f
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ import java.util.Map;
|
|||
@EnableWebMvc
|
||||
@ComponentScan(basePackages = "cc.ryanc.halo.web.controller")
|
||||
@PropertySource(value = "classpath:application.yaml",ignoreResourceNotFound = true,encoding = "UTF-8")
|
||||
public class MvcConfiguration implements WebMvcConfigurer {
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private LoginInterceptor loginInterceptor;
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
|||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class StartupConfiguration implements ApplicationListener<ContextRefreshedEvent>{
|
||||
public class StartupConfig implements ApplicationListener<ContextRefreshedEvent>{
|
||||
|
||||
@Autowired
|
||||
private OptionsService optionsService;
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -86,8 +86,6 @@ public class AdminController extends BaseController{
|
|||
|
||||
model.addAttribute("mediaCount",HaloConst.ATTACHMENTS.size());
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
this.getNewComments(session);
|
||||
return "admin/admin_index";
|
||||
}
|
||||
|
@ -99,9 +97,8 @@ public class AdminController extends BaseController{
|
|||
* @return 模板路径admin/admin_login
|
||||
*/
|
||||
@GetMapping(value = "/login")
|
||||
public String login(HttpSession session,Model model){
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
User user = (User) session.getAttribute("user");
|
||||
public String login(HttpSession session){
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
//如果session存在,跳转到后台首页
|
||||
if(null!=user){
|
||||
return "redirect:/admin";
|
||||
|
@ -210,12 +207,10 @@ public class AdminController extends BaseController{
|
|||
/**
|
||||
* 不可描述的页面
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_halo
|
||||
*/
|
||||
@GetMapping(value = "/halo")
|
||||
public String halo(Model model){
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
public String halo(){
|
||||
return "admin/admin_halo";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,8 +69,6 @@ public class AttachmentController {
|
|||
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
|
||||
model.addAttribute("attachments",attachments);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_attachment";
|
||||
}
|
||||
|
||||
|
@ -90,9 +88,6 @@ public class AttachmentController {
|
|||
Page<Attachment> attachments = attachmentService.findAllAttachments(pageable);
|
||||
model.addAttribute("attachments",attachments);
|
||||
model.addAttribute("id",id);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/widget/_attachment-select";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.util.HaloUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -36,10 +34,7 @@ public class BackupController {
|
|||
* @return 模板路径admin/admin_backup
|
||||
*/
|
||||
@GetMapping
|
||||
public String backup(Model model){
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
public String backup(){
|
||||
return "admin/admin_backup";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -10,7 +9,6 @@ import org.springframework.ui.Model;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.websocket.server.PathParam;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -35,11 +33,7 @@ public class CategoryController {
|
|||
*/
|
||||
@GetMapping
|
||||
public String categories(Model model){
|
||||
List<Category> categories = categoryService.findAllCategories();
|
||||
model.addAttribute("categories",categories);
|
||||
model.addAttribute("statusName","添加");
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_category";
|
||||
}
|
||||
|
||||
|
@ -102,13 +96,9 @@ public class CategoryController {
|
|||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String toEditCategory(Model model,@PathParam("cateId") Long cateId){
|
||||
List<Category> categories = categoryService.findAllCategories();
|
||||
Optional<Category> category = categoryService.findByCateId(cateId);
|
||||
model.addAttribute("updateCategory",category.get());
|
||||
model.addAttribute("categories",categories);
|
||||
model.addAttribute("statusName","修改");
|
||||
//设置选项
|
||||
model.addAttribute("options", HaloConst.OPTIONS);
|
||||
return "admin/admin_category";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,9 +73,6 @@ public class CommentController extends BaseController{
|
|||
model.addAttribute("checkCount",commentService.findAllComments(1,pageable).getTotalElements());
|
||||
model.addAttribute("trashCount",commentService.findAllComments(2,pageable).getTotalElements());
|
||||
model.addAttribute("status",status);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_comment";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Menu;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.service.MenuService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -10,7 +9,6 @@ import org.springframework.ui.Model;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.websocket.server.PathParam;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
|
@ -34,11 +32,7 @@ public class MenuController {
|
|||
*/
|
||||
@GetMapping
|
||||
public String menus(Model model){
|
||||
List<Menu> menus = menuService.findAllMenus();
|
||||
model.addAttribute("menus",menus);
|
||||
model.addAttribute("statusName","添加");
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "/admin/admin_menu";
|
||||
}
|
||||
|
||||
|
@ -67,13 +61,9 @@ public class MenuController {
|
|||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String updateMenu(@RequestParam("menuId") Long menuId,Model model){
|
||||
List<Menu> menus = menuService.findAllMenus();
|
||||
Menu menu = menuService.findByMenuId(menuId).get();
|
||||
model.addAttribute("statusName","修改");
|
||||
model.addAttribute("updateMenu",menu);
|
||||
model.addAttribute("menus",menus);
|
||||
//设置选项
|
||||
model.addAttribute("options", HaloConst.OPTIONS);
|
||||
return "/admin/admin_menu";
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import cc.ryanc.halo.service.OptionsService;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -26,13 +25,10 @@ public class OptionController {
|
|||
/**
|
||||
* 请求跳转到option页面并完成渲染
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_option
|
||||
*/
|
||||
@GetMapping
|
||||
public String options(Model model){
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
public String options(){
|
||||
return "admin/admin_option";
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package cc.ryanc.halo.web.controller.admin;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
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.LinkService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -43,8 +42,7 @@ public class PageController {
|
|||
* @return 模板路径admin/admin_page
|
||||
*/
|
||||
@GetMapping
|
||||
public String pages(Model model){
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
public String pages(){
|
||||
return "admin/admin_page";
|
||||
}
|
||||
|
||||
|
@ -59,9 +57,6 @@ public class PageController {
|
|||
List<Link> links = linkService.findAllLinks();
|
||||
model.addAttribute("links",links);
|
||||
model.addAttribute("statusName","添加");
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options", HaloConst.OPTIONS);
|
||||
return "admin/admin_page_link";
|
||||
}
|
||||
|
||||
|
@ -79,8 +74,6 @@ public class PageController {
|
|||
model.addAttribute("updateLink",link.get());
|
||||
model.addAttribute("statusName","修改");
|
||||
model.addAttribute("links",links);
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_page_link";
|
||||
}
|
||||
|
||||
|
@ -134,7 +127,6 @@ public class PageController {
|
|||
Pageable pageable = new PageRequest(page,size,sort);
|
||||
Page<Gallery> galleries = galleryService.findAllGalleries(pageable);
|
||||
model.addAttribute("galleries",galleries);
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_page_gallery";
|
||||
}
|
||||
|
||||
|
@ -168,8 +160,6 @@ public class PageController {
|
|||
public String gallery(Model model,@PathParam("galleryId") Long galleryId){
|
||||
Optional<Gallery> gallery = galleryService.findByGalleryId(galleryId);
|
||||
model.addAttribute("gallery",gallery.get());
|
||||
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/widget/_gallery-detail";
|
||||
}
|
||||
|
||||
|
|
|
@ -72,10 +72,6 @@ public class PostController extends BaseController{
|
|||
model.addAttribute("draftCount",postService.findPostByStatus(1,pageable).getTotalElements());
|
||||
model.addAttribute("trashCount",postService.findPostByStatus(2,pageable).getTotalElements());
|
||||
model.addAttribute("status",status);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
|
||||
return "admin/admin_post";
|
||||
}
|
||||
|
||||
|
@ -115,8 +111,6 @@ public class PostController extends BaseController{
|
|||
public String viewPost(@PathParam("postId") Long postId,Model model){
|
||||
Optional<Post> post = postService.findByPostId(postId);
|
||||
model.addAttribute("post",post.get());
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("post");
|
||||
}
|
||||
|
||||
|
@ -134,8 +128,6 @@ public class PostController extends BaseController{
|
|||
model.addAttribute("categories",categories);
|
||||
model.addAttribute("tags",tags);
|
||||
model.addAttribute("btnPush","发布");
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
}catch (Exception e){
|
||||
log.error("未知错误:{0}",e.getMessage());
|
||||
}
|
||||
|
@ -247,8 +239,6 @@ public class PostController extends BaseController{
|
|||
List<Category> categories = categoryService.findAllCategories();
|
||||
model.addAttribute("categories",categories);
|
||||
model.addAttribute("btnPush","更新");
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
}catch (Exception e){
|
||||
log.error("未知错误:{0}",e.getMessage());
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -37,8 +36,6 @@ public class TagController {
|
|||
List<Tag> tags = tagService.findAllTags();
|
||||
model.addAttribute("tags",tags);
|
||||
model.addAttribute("statusName","新增");
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_tag";
|
||||
}
|
||||
|
||||
|
@ -106,7 +103,6 @@ public class TagController {
|
|||
model.addAttribute("statusName","修改");
|
||||
model.addAttribute("updateTag",tag);
|
||||
model.addAttribute("tags",tags);
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_tag";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,6 @@ public class ThemeController extends BaseController{
|
|||
if(null!=HaloConst.THEMES){
|
||||
model.addAttribute("themes",HaloConst.THEMES);
|
||||
}
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_theme";
|
||||
}
|
||||
|
||||
|
@ -147,8 +145,6 @@ public class ThemeController extends BaseController{
|
|||
@GetMapping(value = "/options")
|
||||
public String setting(Model model,@RequestParam("theme") String theme){
|
||||
model.addAttribute("themeDir",theme);
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "themes/"+theme+"/module/options";
|
||||
}
|
||||
|
||||
|
@ -162,8 +158,6 @@ public class ThemeController extends BaseController{
|
|||
public String editor(Model model){
|
||||
List<String> tpls = HaloUtil.getTplName(BaseController.THEME);
|
||||
model.addAttribute("tpls",tpls);
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return "admin/admin_theme-editor";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.service.UserService;
|
||||
import cc.ryanc.halo.util.HaloUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -29,14 +28,10 @@ public class UserController {
|
|||
/**
|
||||
* 获取用户信息并跳转
|
||||
*
|
||||
* @param model model
|
||||
* @return 模板路径admin/admin_profile
|
||||
*/
|
||||
@GetMapping
|
||||
public String profile(Model model){
|
||||
model.addAttribute("user",userService.findUser());
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
public String profile(){
|
||||
return "admin/admin_profile";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
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.User;
|
||||
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.UserService;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -39,14 +32,6 @@ public class ArchivesController extends BaseController {
|
|||
@Autowired
|
||||
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);
|
||||
model.addAttribute("posts",posts);
|
||||
|
||||
//文章总数
|
||||
model.addAttribute("postsCount",postService.findAllPosts().size());
|
||||
|
||||
model.addAttribute("is_archives",true);
|
||||
|
||||
//包含[List<Post>,year,month,count]
|
||||
|
@ -89,23 +71,9 @@ public class ArchivesController extends BaseController {
|
|||
List<Archive> archivesLess = postService.findPostGroupByYear();
|
||||
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("options",HaloConst.OPTIONS);
|
||||
return this.render("archives");
|
||||
}
|
||||
|
||||
|
@ -130,21 +98,6 @@ public class ArchivesController extends BaseController {
|
|||
Page<Post> posts = postService.findPostByYearAndMonth(year,month,pageable);
|
||||
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>]
|
||||
List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
model.addAttribute("archives",archives);
|
||||
|
@ -152,8 +105,6 @@ public class ArchivesController extends BaseController {
|
|||
//是否是归档页,用于判断输出链接
|
||||
model.addAttribute("isArchives","true");
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("archives");
|
||||
}
|
||||
|
||||
|
@ -187,28 +138,11 @@ public class ArchivesController extends BaseController {
|
|||
}
|
||||
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>]
|
||||
List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
|
||||
//菜单列表
|
||||
List<Menu> menus = menuService.findAllMenus();
|
||||
model.addAttribute("menus",menus);
|
||||
|
||||
model.addAttribute("archives",archives);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("post");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
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.User;
|
||||
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.UserService;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -39,14 +33,6 @@ public class IndexController extends BaseController {
|
|||
@Autowired
|
||||
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);
|
||||
model.addAttribute("posts",posts);
|
||||
|
||||
//文章总数
|
||||
model.addAttribute("postsCount",postService.findAllPosts().size());
|
||||
|
||||
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>]
|
||||
List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
model.addAttribute("archives",archives);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("index");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
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.HaloConst;
|
||||
import cc.ryanc.halo.service.*;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
import cc.ryanc.halo.service.LinkService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -23,18 +25,9 @@ public class PagesController extends BaseController {
|
|||
@Autowired
|
||||
private GalleryService galleryService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
@Autowired
|
||||
private MenuService menuService;
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private LinkService linkService;
|
||||
|
||||
|
@ -48,9 +41,6 @@ public class PagesController extends BaseController {
|
|||
@GetMapping(value = "/about")
|
||||
public String about(Model model){
|
||||
model.addAttribute("about","709831589");
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("about");
|
||||
}
|
||||
|
||||
|
@ -64,14 +54,8 @@ public class PagesController extends BaseController {
|
|||
List<Gallery> galleries = galleryService.findAllGalleries();
|
||||
model.addAttribute("galleries",galleries);
|
||||
|
||||
//用户信息
|
||||
User user = userService.findUser();
|
||||
model.addAttribute("user",user);
|
||||
|
||||
model.addAttribute("is_gallery",true);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("gallery");
|
||||
}
|
||||
|
||||
|
@ -88,29 +72,12 @@ public class PagesController extends BaseController {
|
|||
List<Link> links = linkService.findAllLinks();
|
||||
model.addAttribute("links",links);
|
||||
|
||||
//用户信息
|
||||
User user = userService.findUser();
|
||||
model.addAttribute("user",user);
|
||||
|
||||
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>]
|
||||
List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
model.addAttribute("archives",archives);
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("links");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
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.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 org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -31,18 +33,9 @@ public class TagsController extends BaseController {
|
|||
@Autowired
|
||||
private TagService tagService;
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
@Autowired
|
||||
private MenuService menuService;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*
|
||||
|
@ -55,27 +48,10 @@ public class TagsController extends BaseController {
|
|||
List<Tag> tags = tagService.findAllTags();
|
||||
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>]
|
||||
List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
model.addAttribute("archives",archives);
|
||||
|
||||
|
||||
//设置选项
|
||||
model.addAttribute("options",HaloConst.OPTIONS);
|
||||
return this.render("tags");
|
||||
}
|
||||
|
||||
|
@ -112,13 +88,6 @@ public class TagsController extends BaseController {
|
|||
Pageable pageable = new PageRequest(page-1,size,sort);
|
||||
Page<Post> posts = postService.findPostsByTags(tag,pageable);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,22 +96,24 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<@commonTag method="categories">
|
||||
<#list categories as cate>
|
||||
<tr>
|
||||
<td>${cate.cateName}</td>
|
||||
<td>${cate.cateUrl}</td>
|
||||
<td>${(cate.cateDesc)!}</td>
|
||||
<td>2</td>
|
||||
<td>
|
||||
<#if updateCategory?? && updateCategory.cateId==cate.cateId>
|
||||
<a href="#" class="btn btn-primary btn-xs " disabled>正在修改</a>
|
||||
<tr>
|
||||
<td>${cate.cateName}</td>
|
||||
<td>${cate.cateUrl}</td>
|
||||
<td>${(cate.cateDesc)!}</td>
|
||||
<td>2</td>
|
||||
<td>
|
||||
<#if updateCategory?? && updateCategory.cateId==cate.cateId>
|
||||
<a href="#" class="btn btn-primary btn-xs " disabled>正在修改</a>
|
||||
<#else >
|
||||
<a data-pjax="true" href="/admin/category/edit?cateId=${cate.cateId}" class="btn btn-primary btn-xs ">修改</a>
|
||||
</#if>
|
||||
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/category/remove?cateId=${cate.cateId}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
<a data-pjax="true" href="/admin/category/edit?cateId=${cate.cateId}" class="btn btn-primary btn-xs ">修改</a>
|
||||
</#if>
|
||||
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/category/remove?cateId=${cate.cateId}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</#list>
|
||||
</@commonTag>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -93,22 +93,24 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<@commonTag method="menus">
|
||||
<#list menus as menu>
|
||||
<tr>
|
||||
<td>${menu.menuName}</td>
|
||||
<td>${menu.menuUrl}</td>
|
||||
<td>${(menu.menuSort)!}</td>
|
||||
<td>${menu.menuIcon}</td>
|
||||
<td>
|
||||
<#if updateMenu?? && menu.menuId==updateMenu.menuId>
|
||||
<a href="#" class="btn btn-primary btn-xs " disabled="">正在修改</a>
|
||||
<tr>
|
||||
<td>${menu.menuName}</td>
|
||||
<td>${menu.menuUrl}</td>
|
||||
<td>${(menu.menuSort)!}</td>
|
||||
<td>${menu.menuIcon}</td>
|
||||
<td>
|
||||
<#if updateMenu?? && menu.menuId==updateMenu.menuId>
|
||||
<a href="#" class="btn btn-primary btn-xs " disabled="">正在修改</a>
|
||||
<#else>
|
||||
<a data-pjax="true" href="/admin/menus/edit?menuId=${menu.menuId}" class="btn btn-primary btn-xs ">修改</a>
|
||||
</#if>
|
||||
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/menus/remove?menuId=${menu.menuId}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
<a data-pjax="true" href="/admin/menus/edit?menuId=${menu.menuId}" class="btn btn-primary btn-xs ">修改</a>
|
||||
</#if>
|
||||
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/menus/remove?menuId=${menu.menuId}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</#list>
|
||||
</@commonTag>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<footer class="main-footer">
|
||||
<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>
|
|
@ -1,10 +1,12 @@
|
|||
<div class="page-top animated fadeInDown">
|
||||
<div class="nav">
|
||||
<#list menus?sort_by('menuSort') as menu>
|
||||
<li>
|
||||
<a href="${menu.menuUrl}">${menu.menuName} </a>
|
||||
</li>
|
||||
</#list>
|
||||
<@commonTag method="menus">
|
||||
<#list menus?sort_by('menuSort') as menu>
|
||||
<li>
|
||||
<a href="${menu.menuUrl}">${menu.menuName} </a>
|
||||
</li>
|
||||
</#list>
|
||||
</@commonTag>
|
||||
</div>
|
||||
<div class="information">
|
||||
<div class="back_btn">
|
||||
|
|
|
@ -48,33 +48,39 @@
|
|||
<b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<#list categories as cate>
|
||||
<li>
|
||||
<a class="sidebar_archives-link" href="/categories/${cate.cateUrl}/">${cate.cateName}<span class="sidebar_archives-count">4</span></a>
|
||||
</li>
|
||||
</#list>
|
||||
<@commonTag method="categories">
|
||||
<#list categories as cate>
|
||||
<li>
|
||||
<a class="sidebar_archives-link" href="/categories/${cate.cateUrl}/">${cate.cateName}<span class="sidebar_archives-count">4</span></a>
|
||||
</li>
|
||||
</#list>
|
||||
</@commonTag>
|
||||
</ul>
|
||||
</li>
|
||||
</#if>
|
||||
|
||||
<!-- Pages -->
|
||||
<#list menus?sort_by("menuSort") as menu>
|
||||
<li>
|
||||
<a href="${menu.menuUrl}" title="${menu.menuName}">
|
||||
<#if menu.menuIcon!="">
|
||||
<i class="material-icons sidebar-material-icons">${menu.menuIcon}</i>
|
||||
</#if>
|
||||
${menu.menuName}
|
||||
</a>
|
||||
</li>
|
||||
</#list>
|
||||
<@commonTag method="menus">
|
||||
<#list menus?sort_by("menuSort") as menu>
|
||||
<li>
|
||||
<a href="${menu.menuUrl}" title="${menu.menuName}">
|
||||
<#if menu.menuIcon!="">
|
||||
<i class="material-icons sidebar-material-icons">${menu.menuIcon}</i>
|
||||
</#if>
|
||||
${menu.menuName}
|
||||
</a>
|
||||
</li>
|
||||
</#list>
|
||||
</@commonTag>
|
||||
|
||||
<#if options.theme_material_other_sidebar_postcount?default('true') == 'true'>
|
||||
<!-- Article Number -->
|
||||
<li>
|
||||
<a href="/archives">
|
||||
文章总数
|
||||
<span class="sidebar-badge">${postsCount}</span>
|
||||
<@articleTag method="postsCount">
|
||||
<span class="sidebar-badge">${postsCount}</span>
|
||||
</@articleTag>
|
||||
</a>
|
||||
</li>
|
||||
</#if>
|
||||
|
|
Loading…
Reference in New Issue