Skip to content

Commit 0f6d25b

Browse files
author
leijiankun
committed
Upgrade to spring boot 1.5.10 and bootstrap4
1 parent 9342d31 commit 0f6d25b

2,826 files changed

Lines changed: 491 additions & 901013 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ SpringBlog
22
=====
33

44
SpringBlog is a very simple and clean-design blog system implemented with Spring Boot.
5-
It's one of my learning projects to explore awesome features in Spring Boot web programming. I had put it on production
6-
for my personal blog site [https://raysmond.com](https://raysmond.com) for about one year. Now, I turn to Hexo for my blog site.
5+
It's one of my learning projects to explore awesome features in Spring Boot web programming. You can check my blog
6+
site for demo [https://raysmond.com](http://raysmond.com).
77

88
There's no demo online. Here's the screenshot of my previous blog homepage.
99
![](http://7b1fa0.com1.z0.glb.clouddn.com/screencapture-blog-raysmond-8080-1480663084590.png)
@@ -18,7 +18,6 @@ SpringBlog is powered by many powerful frameworks and third-party projects:
1818
- [ACE Editor](http://ace.c9.io/) - A high performance code editor which I use to write posts and code.
1919
- [Pygments](http://pygments.org/) - A python library for highlighting code syntax
2020
- [Jade4j](https://github.com/neuland/jade4j) - [Jade](http://jade-lang.com/) is an elegant template language.
21-
- [Webjars](http://www.webjars.org/) - A client-side web libraries packaged into JAR files. A easy way to manage JavaScript and CSS vendors in Gradle.
2221
- [Redis](http://redis.io/) - A very powerful in-memory data cache server.
2322

2423
## Development
@@ -84,8 +83,6 @@ I recommend you import the source code into Intellij IDE to edit the code.
8483
> Reference: https://github.com/mplushnikov/lombok-intellij-plugin
8584
8685

87-
## Deployment
88-
8986
- Build application jar `./gradlew build`, then upload the distribution jar (e.g. `build/libs/SpringBlog-0.1.jar`) to your remote server.
9087
- Upload `application-production.yml` to your server and change it according to your server settings.
9188
- Run it (Java8 is a must)
@@ -96,5 +93,14 @@ I recommend you import the source code into Intellij IDE to edit the code.
9693
java -jar SpringBlog-0.1.jar --spring.config.location=application-production.yml
9794
```
9895

96+
## TODO
97+
98+
- [] Upgrade frontend framework to Bootstrap4
99+
- [] Replace Jade with Thymeleaf(HTML)
100+
- [] Frontend building tools, e.g. webpack
101+
- [] Use hibernate 2nd level cache (EHCache?)
102+
- [] Markdown preview while editing
103+
- [] Html editor
104+
99105
## License
100106
Modified BSD license. Copyright (c) 2015 - 2018, Jiankun LEI (Raysmond).

bower.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
"appPath": "src/main/resources/static",
55
"testPath": "src/test/javascript/spec",
66
"dependencies": {
7-
"jquery": "2.1.4",
8-
"bootstrap": "3.3.7",
7+
"jquery": "3.2.1",
8+
"bootstrap": "4.0.0",
99
"fontawesome": "4.7.0",
1010
"marked": "0.3.5",
11-
"simple-module": "2.0.6",
12-
"simple-hotkeys": "1.0.3",
13-
"simditor": "2.3.5",
14-
"simditor-markdown": "1.1.2",
1511
"to-markdown": "1.3.0",
1612
"adminlte": "2.3.6",
13+
"highlightjs": "9.12.0",
1714
"ace-builds": "1.2.9"
1815
},
1916
"devDependencies": {}

build.gradle

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,43 @@ repositories {
1111
mavenLocal()
1212
jcenter()
1313
mavenCentral()
14-
14+
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
1515
maven { url 'http://repo.spring.io/libs-release' }
16-
maven { url "http://repo.springsource.org/repo" }
16+
maven { url 'http://repo.springsource.org/repo' }
1717
}
1818

1919
bootRun {
2020
systemProperties = System.properties
2121
}
22-
2322
buildscript {
2423
ext {
25-
springBootVersion = '1.5.9.RELEASE'
24+
springBootVersion = '1.5.10.RELEASE'
2625
}
2726
repositories {
2827
mavenLocal()
2928
jcenter()
3029
mavenCentral()
30+
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
3131
}
3232
dependencies {
33-
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
33+
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE')
3434
}
3535
}
3636

3737
dependencies {
3838
// spring boot
39-
compile "org.springframework.boot:spring-boot-starter-web"
40-
compile "org.springframework.boot:spring-boot-starter-thymeleaf"
41-
compile "com.domingosuarez.boot:spring-boot-starter-jade4j:0.3.1"
42-
compile "org.springframework.boot:spring-boot-starter-redis:1.4.7.RELEASE"
39+
compile 'org.springframework.boot:spring-boot-starter-web'
40+
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
41+
compile 'com.domingosuarez.boot:spring-boot-starter-jade4j:0.3.1'
42+
compile 'org.springframework.boot:spring-boot-starter-redis:1.4.7.RELEASE'
4343
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
4444
compile 'org.springframework.boot:spring-boot-starter-security'
4545
compile 'org.springframework.boot:spring-boot-starter-logging'
46+
compile 'org.springframework.boot:spring-boot-devtools'
4647

4748
// view
49+
compile 'net.sourceforge.nekohtml:nekohtml:1.9.22'
50+
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.2.RELEASE'
4851
compile 'de.neuland-bfi:spring-jade4j:0.4.2'
4952
compile 'org.pegdown:pegdown:1.6.0'
5053

@@ -54,11 +57,10 @@ dependencies {
5457

5558
// mysql/hibernate
5659
compile 'mysql:mysql-connector-java:+'
57-
compile "org.hibernate:hibernate-core:5.2.12.Final"
58-
compile "org.hibernate:hibernate-entitymanager:5.2.12.Final"
59-
compile "org.hibernate:hibernate-validator"
60-
compile "com.zaxxer:HikariCP:2.7.6"
61-
60+
compile 'org.hibernate:hibernate-core:5.2.12.Final'
61+
compile 'org.hibernate:hibernate-entitymanager:5.2.12.Final'
62+
compile 'org.hibernate:hibernate-validator'
63+
compile 'com.zaxxer:HikariCP:2.7.6'
6264

6365
// JSON
6466
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.1.3'
@@ -69,7 +71,6 @@ dependencies {
6971
compile 'org.modelmapper:modelmapper:+'
7072
compile 'org.projectlombok:lombok:+'
7173
compile 'org.apache.commons:commons-lang3:+'
72-
//compile 'com.qiniu:qiniu-java-sdk:7.0.+'
7374

7475
// test
7576
testCompile 'junit:junit:+'

src/main/java/com/raysmond/blog/SpringBlogApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@SpringBootApplication
10-
@EnableCaching
10+
//@EnableCaching
1111
public class SpringBlogApplication {
1212

1313
public static void main(String[] args) {

src/main/java/com/raysmond/blog/controllers/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public String index(@RequestParam(defaultValue = "1") int page, Model model) {
3131
model.addAttribute("posts", posts);
3232
model.addAttribute("page", page + 1);
3333

34-
return "home/index";
34+
return "home/home";
3535
}
3636

3737
@RequestMapping(value = "about", method = GET)

src/main/java/com/raysmond/blog/controllers/PostController.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.raysmond.blog.controllers;
22

3+
import com.google.common.collect.Lists;
4+
import com.google.common.collect.Maps;
35
import com.raysmond.blog.error.NotFoundException;
46
import com.raysmond.blog.models.Post;
57
import com.raysmond.blog.services.PostService;
8+
69
import org.springframework.beans.factory.annotation.Autowired;
710
import org.springframework.stereotype.Controller;
811
import org.springframework.ui.Model;
@@ -11,6 +14,8 @@
1114

1215
import static org.springframework.web.bind.annotation.RequestMethod.GET;
1316

17+
import java.util.List;
18+
import java.util.Map;
1419

1520
/**
1621
* @author Raysmond
@@ -23,8 +28,14 @@ public class PostController {
2328

2429
@RequestMapping(value = "archive", method = GET)
2530
public String archive(Model model) {
26-
model.addAttribute("posts", postService.getArchivePosts());
27-
31+
Map<Integer, List<Post>> posts = Maps.newHashMap();
32+
postService.getArchivePosts().forEach(post -> {
33+
if (!posts.containsKey(post.getCreatedAt().getYear())) {
34+
posts.put(post.getCreatedAt().getYear(), Lists.newArrayList());
35+
}
36+
posts.get(post.getCreatedAt().getYear()).add(post);
37+
});
38+
model.addAttribute("posts", posts);
2839
return "posts/archive";
2940
}
3041

@@ -35,17 +46,19 @@ public String show(@PathVariable String permalink, Model model) {
3546
try {
3647
post = postService.getPublishedPostByPermalink(permalink);
3748
} catch (NotFoundException ex) {
38-
if (permalink.matches("\\d+"))
49+
if (permalink.matches("\\d+")) {
3950
post = postService.getPost(Long.valueOf(permalink));
51+
}
4052
}
4153

42-
if (post == null)
54+
if (post == null) {
4355
throw new NotFoundException("Post with permalink " + permalink + " is not found");
56+
}
4457

4558
model.addAttribute("post", post);
4659
model.addAttribute("tags", postService.getPostTags(post));
4760

48-
return "posts/show";
61+
return "posts/post";
4962
}
5063

5164
}

src/main/java/com/raysmond/blog/controllers/UserController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public class UserController {
1616

1717
@RequestMapping("login")
1818
public String signin(Principal principal, RedirectAttributes ra) {
19-
return principal == null ? "users/signin" : "redirect:/";
19+
return principal == null ? "users/login" : "redirect:/";
2020
}
2121
}

src/main/java/com/raysmond/blog/models/BaseModel.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import org.apache.commons.lang3.builder.HashCodeBuilder;
44

55
import javax.persistence.*;
6+
67
import java.io.Serializable;
8+
import java.time.ZonedDateTime;
79
import java.util.Date;
810

911
/**
@@ -20,19 +22,19 @@ public abstract class BaseModel implements Comparable<BaseModel>, Serializable {
2022
private Long id;
2123

2224
@Column(nullable = false)
23-
private Date createdAt;
25+
private ZonedDateTime createdAt;
2426

2527
@Column(nullable = false)
26-
private Date updatedAt;
28+
private ZonedDateTime updatedAt;
2729

2830
@PrePersist
2931
public void prePersist() {
30-
createdAt = updatedAt = new Date();
32+
createdAt = updatedAt = ZonedDateTime.now();
3133
}
3234

3335
@PreUpdate
3436
public void preUpdate() {
35-
updatedAt = new Date();
37+
updatedAt = ZonedDateTime.now();
3638
}
3739

3840
@Override
@@ -41,18 +43,17 @@ public int compareTo(BaseModel o) {
4143
}
4244

4345
public boolean equals(Object other) {
44-
if (other == null || other.getClass() != this.getClass())
46+
if (other == null || other.getClass() != this.getClass()) {
4547
return false;
48+
}
4649

4750
return this.getId().equals(((BaseModel) other).getId());
4851
}
4952

50-
5153
public int hashCode() {
5254
return new HashCodeBuilder().append(getId()).toHashCode();
5355
}
5456

55-
5657
public Long getId() {
5758
return id;
5859
}
@@ -61,20 +62,19 @@ public void setId(Long _id) {
6162
id = _id;
6263
}
6364

64-
public Date getCreatedAt() {
65+
public ZonedDateTime getCreatedAt() {
6566
return createdAt;
6667
}
6768

68-
public void setCreatedAt(Date createdAt) {
69+
public void setCreatedAt(ZonedDateTime createdAt) {
6970
this.createdAt = createdAt;
7071
}
7172

72-
public Date getUpdatedAt() {
73+
public ZonedDateTime getUpdatedAt() {
7374
return updatedAt;
7475
}
7576

76-
public void setUpdatedAt(Date updatedAt) {
77+
public void setUpdatedAt(ZonedDateTime updatedAt) {
7778
this.updatedAt = updatedAt;
7879
}
79-
8080
}

src/main/java/com/raysmond/blog/services/PostService.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@
99
import com.raysmond.blog.models.support.PostType;
1010
import com.raysmond.blog.repositories.PostRepository;
1111
import com.raysmond.blog.utils.Markdown;
12+
1213
import lombok.extern.slf4j.Slf4j;
14+
1315
import org.springframework.beans.factory.annotation.Autowired;
1416
import org.springframework.cache.annotation.CacheEvict;
1517
import org.springframework.cache.annotation.Cacheable;
1618
import org.springframework.cache.annotation.Caching;
1719
import org.springframework.data.domain.Page;
1820
import org.springframework.data.domain.PageRequest;
21+
import org.springframework.data.domain.Pageable;
1922
import org.springframework.data.domain.Sort;
2023
import org.springframework.stereotype.Service;
2124

2225
import java.util.ArrayList;
2326
import java.util.HashSet;
2427
import java.util.List;
2528
import java.util.Set;
29+
import java.util.stream.Collectors;
2630

2731
/**
2832
* @author Raysmond
@@ -122,15 +126,12 @@ public void deletePost(Post post) {
122126
public List<Post> getArchivePosts() {
123127
log.debug("Get all archive posts from database.");
124128

125-
Iterable<Post> posts = postRepository.findAllByPostTypeAndPostStatus(
126-
PostType.POST,
127-
PostStatus.PUBLISHED,
128-
new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.DESC, "createdAt"));
129-
130-
List<Post> cachedPosts = new ArrayList<>();
131-
posts.forEach(post -> cachedPosts.add(extractPostMeta(post)));
132-
133-
return cachedPosts;
129+
Pageable page = new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.DESC, "createdAt");
130+
return postRepository.findAllByPostTypeAndPostStatus(PostType.POST, PostStatus.PUBLISHED, page)
131+
.getContent()
132+
.stream()
133+
.map(this::extractPostMeta)
134+
.collect(Collectors.toList());
134135
}
135136

136137
@Cacheable(value = CACHE_NAME_TAGS, key = "#post.id.toString().concat('-tags')")
@@ -146,7 +147,6 @@ public List<Tag> getPostTags(Post post) {
146147
return tags;
147148
}
148149

149-
150150
private Post extractPostMeta(Post post) {
151151
Post archivePost = new Post();
152152
archivePost.setId(post.getId());
@@ -195,8 +195,9 @@ public Set<Tag> parseTagNames(String tagNames) {
195195
}
196196

197197
public String getTagNames(Set<Tag> tags) {
198-
if (tags == null || tags.isEmpty())
198+
if (tags == null || tags.isEmpty()) {
199199
return "";
200+
}
200201

201202
StringBuilder names = new StringBuilder();
202203
tags.forEach(tag -> names.append(tag.getName()).append(","));

src/main/java/com/raysmond/blog/support/web/MarkdownService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* @author Raysmond
55
*/
66
public interface MarkdownService {
7-
public String renderToHtml(String content);
7+
String renderToHtml(String content);
88
}

0 commit comments

Comments
 (0)