forked from atjiu/pybbs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加freemarker自定义标签,修复生成头像跟上传文件不存在的bug
- Loading branch information
Showing
18 changed files
with
349 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ VALUES (1, 7), (2, 7), (1, 8), (2, 8), (1, 9), (2, 9), (1, 10), (2, 10), (1, 11) | |
INSERT INTO `pybbs_section` VALUES (1, '分享'), (4, '博客'), (5, '招聘'), (3, '新闻'), (2, '问答'); | ||
|
||
INSERT INTO `pybbs_user` VALUES | ||
(1, '5', null, 'http://localhost:8080/static/images/upload/avatar/default.png', '\0', '[email protected]', '2016-09-09 09:50:14', | ||
(1, '0', null, 'http://localhost:8080/static/images/upload/avatar/default.png', '\0', '[email protected]', '2016-09-09 09:50:14', | ||
'$2a$10$KkUG107R3ASTHfAHei.bweXWXgCa4cE1KhK.F0odzfE0r97aeeTXC', 'hello world', | ||
'd20b9a5c-8693-41a6-8943-ddb2cb78eebd', 'https://tomoya92.github.io', 'tomoya'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/cn/tomoya/common/config/freemarker/UserCollectDirective.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cn.tomoya.common.config.freemarker; | ||
|
||
import cn.tomoya.module.collect.entity.Collect; | ||
import cn.tomoya.module.collect.service.CollectService; | ||
import cn.tomoya.module.user.entity.User; | ||
import cn.tomoya.module.user.service.UserService; | ||
import freemarker.core.Environment; | ||
import freemarker.template.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by tomoya on 17-6-6. | ||
*/ | ||
@Component | ||
public class UserCollectDirective implements TemplateDirectiveModel { | ||
|
||
@Autowired | ||
private UserService userService; | ||
@Autowired | ||
private CollectService collectService; | ||
|
||
@Override | ||
public void execute(Environment environment, Map map, TemplateModel[] templateModels, | ||
TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { | ||
Page<Collect> page = new PageImpl<>(new ArrayList<>()); | ||
if (map.containsKey("username") && map.get("username") != null) { | ||
String username = map.get("username").toString(); | ||
if (map.containsKey("p")) { | ||
int p = map.get("p") == null ? 1 : Integer.parseInt(map.get("p").toString()); | ||
int limit = Integer.parseInt(map.get("limit").toString()); | ||
User currentUser = userService.findByUsername(username); | ||
if (currentUser != null) { | ||
page = collectService.findByUser(p, limit, currentUser); | ||
} | ||
} | ||
} | ||
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); | ||
environment.setVariable("page", builder.build().wrap(page)); | ||
templateDirectiveBody.render(environment.getOut()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/cn/tomoya/common/config/freemarker/UserReplyDirective.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cn.tomoya.common.config.freemarker; | ||
|
||
import cn.tomoya.module.reply.entity.Reply; | ||
import cn.tomoya.module.reply.service.ReplyService; | ||
import cn.tomoya.module.user.entity.User; | ||
import cn.tomoya.module.user.service.UserService; | ||
import freemarker.core.Environment; | ||
import freemarker.template.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by tomoya on 17-6-6. | ||
*/ | ||
@Component | ||
public class UserReplyDirective implements TemplateDirectiveModel { | ||
|
||
@Autowired | ||
private UserService userService; | ||
@Autowired | ||
private ReplyService replyService; | ||
|
||
@Override | ||
public void execute(Environment environment, Map map, TemplateModel[] templateModels, | ||
TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { | ||
Page<Reply> page = new PageImpl<>(new ArrayList<>()); | ||
if (map.containsKey("username") && map.get("username") != null) { | ||
String username = map.get("username").toString(); | ||
if (map.containsKey("p")) { | ||
int p = map.get("p") == null ? 1 : Integer.parseInt(map.get("p").toString()); | ||
int limit = Integer.parseInt(map.get("limit").toString()); | ||
User currentUser = userService.findByUsername(username); | ||
if (currentUser != null) { | ||
page = replyService.findByUser(p, limit, currentUser); | ||
} | ||
} | ||
} | ||
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); | ||
environment.setVariable("page", builder.build().wrap(page)); | ||
templateDirectiveBody.render(environment.getOut()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/cn/tomoya/common/config/freemarker/UserTopicDirective.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cn.tomoya.common.config.freemarker; | ||
|
||
import cn.tomoya.module.topic.entity.Topic; | ||
import cn.tomoya.module.topic.service.TopicService; | ||
import cn.tomoya.module.user.entity.User; | ||
import cn.tomoya.module.user.service.UserService; | ||
import freemarker.core.Environment; | ||
import freemarker.template.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by tomoya on 17-6-6. | ||
*/ | ||
@Component | ||
public class UserTopicDirective implements TemplateDirectiveModel { | ||
|
||
@Autowired | ||
private UserService userService; | ||
@Autowired | ||
private TopicService topicService; | ||
|
||
@Override | ||
public void execute(Environment environment, Map map, TemplateModel[] templateModels, | ||
TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { | ||
Page<Topic> page = new PageImpl<>(new ArrayList<>()); | ||
if (map.containsKey("username") && map.get("username") != null) { | ||
String username = map.get("username").toString(); | ||
if (map.containsKey("p")) { | ||
int p = map.get("p") == null ? 1 : Integer.parseInt(map.get("p").toString()); | ||
int limit = Integer.parseInt(map.get("limit").toString()); | ||
User currentUser = userService.findByUsername(username); | ||
if (currentUser != null) { | ||
page = topicService.findByUser(p, limit, currentUser); | ||
} | ||
} | ||
} | ||
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); | ||
environment.setVariable("page", builder.build().wrap(page)); | ||
templateDirectiveBody.render(environment.getOut()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../config/freemarker/SpringSecurityTag.java → ...on/config/security/SpringSecurityTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.