diff --git a/bin/halo.sh b/bin/halo.sh
index 427704ed2..4defc72e2 100644
--- a/bin/halo.sh
+++ b/bin/halo.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-APP_NAME=halo-0.0.1.jar
+APP_NAME=halo-0.0.2.jar
usage() {
echo "用法: sh halo.sh [start(启动)|stop(停止)|restart(重启)|status(状态)]"
diff --git a/pom.xml b/pom.xml
index 73c3fa8ec..bf28c35dd 100755
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
cc.ryanc
halo
- 0.0.1
+ 0.0.2
halo
diff --git a/src/main/java/cc/ryanc/halo/repository/PostRepository.java b/src/main/java/cc/ryanc/halo/repository/PostRepository.java
index 0ad49275a..b864530aa 100644
--- a/src/main/java/cc/ryanc/halo/repository/PostRepository.java
+++ b/src/main/java/cc/ryanc/halo/repository/PostRepository.java
@@ -147,14 +147,33 @@ public interface PostRepository extends JpaRepository{
@Query(value = "select * from halo_post where post_status=0 and post_type='post' and year(post_date)=:year and month(post_date)=:month order by post_date desc",countQuery = "select count(*) from halo_post where post_status=0 and year(post_date)=:year and month(post_date)=:month",nativeQuery = true)
Page findPostByYearAndMonth(@Param("year") String year,@Param("month") String month,Pageable pageable);
- List findPostByCategories(Category category);
+ /**
+ * 根据分类目录查询文章
+ *
+ * @param category category
+ * @param pageable pageable
+ * @return Page>
+ */
+ Page findPostByCategories(Category category,Pageable pageable);
/**
* 根据标签查询文章
*
* @param tag tag
* @param pageable pageable
- * @return page
+ * @return Page>
*/
Page findPostsByTags(Tag tag,Pageable pageable);
+
+ /**
+ * 模糊查询文章
+ *
+ * @param postType 文章类型,post or page
+ * @param postStatus 0,1,2
+ * @param keyword 关键词
+ * @param pageable 分页信息
+ * @return Page>
+ */
+ @Query(value = "select * from halo_post where post_status = 0 and post_type='post' and post_title like '%=:keyword%' or post_content like '%=:keyword%'",nativeQuery = true)
+ Page findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(String keyword,Pageable pageable);
}
diff --git a/src/main/java/cc/ryanc/halo/service/PostService.java b/src/main/java/cc/ryanc/halo/service/PostService.java
index dedf68c12..65a58663b 100755
--- a/src/main/java/cc/ryanc/halo/service/PostService.java
+++ b/src/main/java/cc/ryanc/halo/service/PostService.java
@@ -1,5 +1,6 @@
package cc.ryanc.halo.service;
+import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.Archive;
@@ -175,6 +176,15 @@ public interface PostService {
*/
List findPostByYear(String year);
+ /**
+ * 根据分类目录查询文章
+ *
+ * @param category category
+ * @param pageable pageable
+ * @return Page>
+ */
+ Page findPostByCategories(Category category,Pageable pageable);
+
/**
* 根据标签查询文章
*
@@ -184,6 +194,15 @@ public interface PostService {
*/
Page findPostsByTags(Tag tag, Pageable pageable);
+ /**
+ * 搜索文章
+ *
+ * @param keyword 关键词
+ * @param pageable 分页信息
+ * @return Page>
+ */
+ Page searchByKeywords(String keyword,Pageable pageable);
+
/**
* 生成rss
*
diff --git a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java
index db6c43110..2f3782160 100755
--- a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java
+++ b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java
@@ -1,5 +1,6 @@
package cc.ryanc.halo.service.impl;
+import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.Archive;
@@ -277,6 +278,18 @@ public class PostServiceImpl implements PostService {
return postRepository.findPostByYearAndMonth(year, month, null);
}
+ /**
+ * 根据分类目录查询文章
+ *
+ * @param category category
+ * @param pageable pageable
+ * @return Page>
+ */
+ @Override
+ public Page findPostByCategories(Category category, Pageable pageable) {
+ return postRepository.findPostByCategories(category,pageable);
+ }
+
/**
* 根据标签查询文章
*
@@ -289,6 +302,18 @@ public class PostServiceImpl implements PostService {
return postRepository.findPostsByTags(tag, pageable);
}
+ /**
+ * 搜索文章
+ *
+ * @param keyword 关键词
+ * @param pageable 分页信息
+ * @return List>
+ */
+ @Override
+ public Page searchByKeywords(String keyword,Pageable pageable) {
+ return postRepository.findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(keyword,pageable);
+ }
+
/**
* 生成rss
*
diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java
index d9cac6e5a..043444c4b 100755
--- a/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java
+++ b/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java
@@ -164,7 +164,7 @@ public class PageController {
} catch (Exception e) {
e.printStackTrace();
}
- return "redirect:/admin/page/gallery";
+ return "redirect:/admin/page/galleries";
}
/**
diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/CategoriesController.java b/src/main/java/cc/ryanc/halo/web/controller/front/CategoriesController.java
index 3dbc6321f..895c3bc40 100644
--- a/src/main/java/cc/ryanc/halo/web/controller/front/CategoriesController.java
+++ b/src/main/java/cc/ryanc/halo/web/controller/front/CategoriesController.java
@@ -1,6 +1,17 @@
package cc.ryanc.halo.web.controller.front;
+import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
+import cc.ryanc.halo.model.dto.HaloConst;
+import cc.ryanc.halo.service.CategoryService;
+import cc.ryanc.halo.service.PostService;
+import cc.ryanc.halo.web.controller.core.BaseController;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@@ -16,7 +27,19 @@ import java.util.List;
*/
@Controller
@RequestMapping(value = "categories")
-public class CategoriesController {
+public class CategoriesController extends BaseController {
+
+ @Autowired
+ private CategoryService categoryService;
+
+ @Autowired
+ private PostService postService;
+
+ public String categories(Model model){
+ List categories = categoryService.findAllCategories();
+ model.addAttribute("categories",categories);
+ return this.render("categories");
+ }
/**
* 根据分类路径查询文章
@@ -28,7 +51,30 @@ public class CategoriesController {
@GetMapping(value = "{cateUrl}")
public String categories(Model model,
@PathVariable("cateUrl") String cateUrl) {
- List posts;
- return null;
+ return this.categories(model,cateUrl,1);
+ }
+
+ /**
+ * 根据分类目录查询所有文章 分页
+ *
+ * @param model model
+ * @param cateUrl 分类目录路径
+ * @param page 页码
+ * @return string
+ */
+ public String categories(Model model,
+ @PathVariable("cateUrl") String cateUrl,
+ @PathVariable("page") Integer page){
+ Category category = categoryService.findByCateUrl(cateUrl);
+ Sort sort = new Sort(Sort.Direction.DESC,"postDate");
+ Integer size = 10;
+ if(!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))){
+ size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
+ }
+ Pageable pageable = new PageRequest(page-1,size,sort);
+ Page posts = postService.findPostByCategories(category,pageable);
+ model.addAttribute("posts",posts);
+ model.addAttribute("category",category);
+ return this.render("category");
}
}
diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java b/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java
index a17fd5624..56334718c 100644
--- a/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java
+++ b/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java
@@ -94,4 +94,18 @@ public class IndexController extends BaseController {
List posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable).getContent();
return posts;
}
+
+ /**
+ * 搜索文章
+ *
+ * @param keyword keyword
+ * @param model model
+ * @return 模板路径/themes/{theme}/index
+ */
+ @GetMapping(value = "search")
+ public String search(@PathParam("keyword") String keyword,Model model){
+ Page posts = postService.searchByKeywords(keyword,null);
+ model.addAttribute("posts",posts);
+ return this.render("index");
+ }
}
diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java b/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java
index ac7c65978..3fafd271c 100644
--- a/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java
+++ b/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java
@@ -84,6 +84,6 @@ public class TagsController extends BaseController {
Page posts = postService.findPostsByTags(tag, pageable);
model.addAttribute("posts", posts);
model.addAttribute("tag", tag);
- return this.render("tags");
+ return this.render("tag");
}
}
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index 57f53c377..fce080e88 100755
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -28,7 +28,7 @@ spring:
jpa:
hibernate:
ddl-auto: update
- show-sql: false
+ show-sql: true
freemarker:
allow-request-override: false
cache: false
diff --git a/src/main/resources/templates/admin/admin_page.ftl b/src/main/resources/templates/admin/admin_page.ftl
index 2b319af0c..1bc23bf24 100755
--- a/src/main/resources/templates/admin/admin_page.ftl
+++ b/src/main/resources/templates/admin/admin_page.ftl
@@ -98,7 +98,7 @@
#list>
<#else>
- 暂无页面 |
+ 暂无页面 |
#if>
diff --git a/src/main/resources/templates/admin/admin_page_gallery.ftl b/src/main/resources/templates/admin/admin_page_gallery.ftl
index e18e2d6cd..2d5b746f4 100644
--- a/src/main/resources/templates/admin/admin_page_gallery.ftl
+++ b/src/main/resources/templates/admin/admin_page_gallery.ftl
@@ -77,7 +77,7 @@
diff --git a/src/main/resources/templates/admin/widget/_gallery-detail.ftl b/src/main/resources/templates/admin/widget/_gallery-detail.ftl
index 6347c618c..341f02324 100644
--- a/src/main/resources/templates/admin/widget/_gallery-detail.ftl
+++ b/src/main/resources/templates/admin/widget/_gallery-detail.ftl
@@ -35,25 +35,31 @@
+
@@ -115,6 +121,7 @@
}
function btn_save() {
$('#galleryForm').submit();
+ parent.location.reload();
}