Skip to content

Commit 044c0b8

Browse files
author
shiminghui
committed
增加文章滑动分页 文章归档 后台日志记录
1 parent 1e00d9a commit 044c0b8

File tree

108 files changed

+5570
-4128
lines changed

Some content is hidden

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

108 files changed

+5570
-4128
lines changed

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Vue + SpringBoot实现的博客系统
55

66
## 首页
77

8-
![image](https://github.com/shimh-develop/blog-vue-springboot/blob/master/document/index.png)
8+
![image](https://github.com/shimh-develop/blog-vue-springboot/blob/master/document/index2.png)
99

1010
## 登录页
1111
![image](https://github.com/shimh-develop/blog-vue-springboot/blob/master/document/login.png)
@@ -18,6 +18,9 @@ Vue + SpringBoot实现的博客系统
1818

1919
![image](https://github.com/shimh-develop/blog-vue-springboot/blob/master/document/ct-detail.png)
2020

21+
## 文章归档
22+
![image](https://github.com/shimh-develop/blog-vue-springboot/blob/master/document/archive.png)
23+
2124
## 写文章
2225
![image](https://github.com/shimh-develop/blog-vue-springboot/blob/master/document/write.png)
2326

@@ -53,25 +56,28 @@ Vue + SpringBoot实现的博客系统
5356

5457
# 实现功能
5558

56-
## 整体
59+
## 整体
5760

5861
- 用户:登录 注册 退出
5962
- 首页:文章列表、最热标签、最新文章、最热文章
6063
- 文章分类-标签:列表、详情
64+
- 文章归档
6165
- 文章:写文章、文章详情
6266
- 评论:文章添加评论
67+
- 文章列表滑动分页
6368

6469
## 后端
6570
- 用户、文章、文章分类、标签和评论 增删改查api接口
6671
- 基于token权限控制
6772
- Redis存储Session
6873
- 全局异常处理
74+
- 操作日志记录
6975

7076
# 待实现功能
71-
- 文章、评论等的分页
77+
- 评论的分页
7278
- 评论回复、点赞
7379
- 留言板
74-
- 后端日志记录
80+
- 第三方登录
7581
- ......
7682

7783
# 运行
@@ -87,13 +93,13 @@ Vue + SpringBoot实现的博客系统
8793

8894
## 方式二 前后分离(开发方式)
8995
1. 按方式一运行blog-api,提供api数据接口
90-
2. 打开命令行
91-
> cd blog-app
92-
93-
> npm install
94-
95-
> npm run dev
96-
96+
2. 打开命令行
97+
> cd blog-app
98+
99+
> npm install
100+
101+
> npm run dev
102+
97103
3. 访问:http://localhost:8080
98104
4. 修改blog-app/src 下的文件进行开发
99105
5. npm run build 生成最终静态文件

blog-api/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@
2727
```
2828

2929
## 2018-01-26
30-
30+
3131
```
3232
# Category Tag 后台接口
3333
3434
3535
```
36+
## 2018-04-20
37+
38+
```
39+
# 增加日志功能
40+
41+
# 格式化代码
42+
43+
```
3644

3745

3846

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.shimh.common.annotation;
2+
3+
import java.lang.annotation.*;
4+
5+
/**
6+
* 日志注解
7+
*
8+
* @author shimh
9+
* <p>
10+
* 2018年4月18日
11+
*/
12+
@Target(ElementType.METHOD)
13+
@Retention(RetentionPolicy.RUNTIME)
14+
@Documented
15+
public @interface LogAnnotation {
16+
17+
String module() default "";
18+
19+
String operation() default "";
20+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.shimh.common.aspect;
2+
3+
import com.alibaba.druid.support.json.JSONUtils;
4+
import com.alibaba.fastjson.JSON;
5+
import com.shimh.common.annotation.LogAnnotation;
6+
import com.shimh.common.util.HttpContextUtils;
7+
import com.shimh.common.util.IpUtils;
8+
import com.shimh.common.util.UserUtils;
9+
import com.shimh.entity.Log;
10+
import com.shimh.entity.User;
11+
import com.shimh.service.LogService;
12+
import org.aspectj.lang.ProceedingJoinPoint;
13+
import org.aspectj.lang.annotation.Around;
14+
import org.aspectj.lang.annotation.Aspect;
15+
import org.aspectj.lang.annotation.Pointcut;
16+
import org.aspectj.lang.reflect.MethodSignature;
17+
import org.springframework.beans.factory.annotation.Autowired;
18+
import org.springframework.stereotype.Component;
19+
20+
import javax.servlet.http.HttpServletRequest;
21+
import java.lang.reflect.Method;
22+
import java.util.Date;
23+
24+
/**
25+
* 日志切面
26+
*
27+
* @author shimh
28+
* <p>
29+
* 2018年4月18日
30+
*/
31+
@Aspect
32+
@Component
33+
public class LogAspect {
34+
35+
@Autowired
36+
private LogService logService;
37+
38+
@Pointcut("@annotation(com.shimh.common.annotation.LogAnnotation)")
39+
public void logPointCut() {
40+
}
41+
42+
@Around("logPointCut()")
43+
public Object around(ProceedingJoinPoint point) throws Throwable {
44+
long beginTime = System.currentTimeMillis();
45+
//执行方法
46+
Object result = point.proceed();
47+
//执行时长(毫秒)
48+
long time = System.currentTimeMillis() - beginTime;
49+
//保存日志
50+
saveLog(point, time);
51+
return result;
52+
}
53+
54+
private void saveLog(ProceedingJoinPoint joinPoint, long time) {
55+
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
56+
Method method = signature.getMethod();
57+
Log log = new Log();
58+
LogAnnotation logAnnotation = method.getAnnotation(LogAnnotation.class);
59+
60+
if (log != null) {
61+
log.setModule(logAnnotation.module());
62+
log.setOperation(logAnnotation.operation());
63+
}
64+
65+
//请求的方法名
66+
String className = joinPoint.getTarget().getClass().getName();
67+
String methodName = signature.getName();
68+
log.setMethod(className + "." + methodName + "()");
69+
70+
//请求的参数
71+
Object[] args = joinPoint.getArgs();
72+
String params = JSON.toJSONString(args[0]);
73+
log.setParams(params);
74+
75+
//获取request 设置IP地址
76+
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
77+
log.setIp(IpUtils.getIpAddr(request));
78+
79+
//用户名
80+
User user = UserUtils.getCurrentUser();
81+
82+
if (null != user) {
83+
log.setUserId(user.getId());
84+
log.setNickname(user.getNickname());
85+
} else {
86+
log.setUserId(-1L);
87+
log.setNickname("获取用户信息为空");
88+
}
89+
90+
log.setTime(time);
91+
log.setCreateDate(new Date());
92+
93+
logService.saveLog(log);
94+
}
95+
96+
}

blog-api/src/main/java/com/shimh/common/cache/RedisManager.java

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,65 @@
44

55
import org.springframework.data.redis.core.RedisTemplate;
66
import org.springframework.data.redis.core.ValueOperations;
7+
78
/**
8-
* RedisManager
9-
*
10-
* @author shimh
9+
* RedisManager
1110
*
11+
* @author shimh
12+
* <p>
1213
* 2018年1月23日
13-
*
1414
*/
1515
public class RedisManager {
16-
17-
/** 默认过期时长,单位:秒 */
16+
17+
/**
18+
* 默认过期时长,单位:秒
19+
*/
1820
public final static long DEFAULT_EXPIRE = 60 * 30 * 1;
19-
/** 不设置过期时长 */
21+
/**
22+
* 不设置过期时长
23+
*/
2024
public final static long NOT_EXPIRE = -1;
21-
25+
2226
private RedisTemplate redisTemplate;
23-
24-
25-
public void set(String key, Object value, long expire){
26-
try {
27-
if(expire == NOT_EXPIRE){
28-
redisTemplate.opsForValue().set(key, value);
29-
}else {
30-
redisTemplate.opsForValue().set(key, value, expire,TimeUnit.SECONDS);
31-
}
32-
} catch (Exception e) {
33-
e.printStackTrace();
34-
}
35-
27+
28+
29+
public void set(String key, Object value, long expire) {
30+
try {
31+
if (expire == NOT_EXPIRE) {
32+
redisTemplate.opsForValue().set(key, value);
33+
} else {
34+
redisTemplate.opsForValue().set(key, value, expire, TimeUnit.SECONDS);
35+
}
36+
} catch (Exception e) {
37+
e.printStackTrace();
38+
}
39+
3640
}
3741

38-
public void set(String key, Object value){
42+
public void set(String key, Object value) {
3943
set(key, value, DEFAULT_EXPIRE);
4044
}
4145

4246
public <T> T get(String key, Class<T> clazz) {
43-
ValueOperations<String,T> operations = redisTemplate.opsForValue();
44-
return operations.get(key);
45-
47+
ValueOperations<String, T> operations = redisTemplate.opsForValue();
48+
return operations.get(key);
49+
4650
}
47-
51+
4852
public Object get(String key) {
49-
return redisTemplate.opsForValue().get(key);
53+
return redisTemplate.opsForValue().get(key);
5054
}
5155

5256
public void delete(String key) {
53-
redisTemplate.delete(key);
57+
redisTemplate.delete(key);
5458
}
5559

56-
public RedisTemplate<String,Object> getRedisTemplate() {
57-
return redisTemplate;
58-
}
60+
public RedisTemplate<String, Object> getRedisTemplate() {
61+
return redisTemplate;
62+
}
63+
64+
public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
65+
this.redisTemplate = redisTemplate;
66+
}
5967

60-
public void setRedisTemplate(RedisTemplate<String,Object> redisTemplate) {
61-
this.redisTemplate = redisTemplate;
62-
}
63-
6468
}

blog-api/src/main/java/com/shimh/common/constant/Base.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
/**
44
* 系统基础常量
5-
*
6-
* @author shimh
75
*
6+
* @author shimh
7+
* <p>
88
* 2018年1月23日
9-
*
109
*/
1110
public class Base {
1211

13-
public static final String ROLE_ADMIN = "admin";
14-
15-
public static final String CURRENT_USER = "current_user";
12+
public static final String ROLE_ADMIN = "admin";
13+
14+
public static final String CURRENT_USER = "current_user";
1615
}

blog-api/src/main/java/com/shimh/common/constant/ResultCode.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
/**
44
* api接口返回 code和message
5-
*
6-
* @author shimh
75
*
6+
* @author shimh
7+
* <p>
88
* 2018年1月23日
9-
*
109
*/
1110
public enum ResultCode {
1211

@@ -19,8 +18,8 @@ public enum ResultCode {
1918
PARAM_IS_BLANK(10002, "参数为空"),
2019
PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
2120
PARAM_NOT_COMPLETE(10004, "参数缺失"),
22-
23-
21+
22+
2423
/* 用户错误:20001-29999*/
2524
USER_NOT_LOGGED_IN(20001, "用户未登录"),
2625
USER_LOGIN_ERROR(20002, "账号或密码错误"),
@@ -50,11 +49,11 @@ public enum ResultCode {
5049

5150
/* 权限错误:70001-79999 */
5251
PERMISSION_NO_ACCESS(70001, "无访问权限"),
53-
52+
5453
/* 文件上传 */
55-
UPLOAD_ERROR(80001, "上传失败"),
56-
57-
SESSION_TIME_OUT(90001, "Session超时");
54+
UPLOAD_ERROR(80001, "上传失败"),
55+
56+
SESSION_TIME_OUT(90001, "Session超时");
5857

5958
private Integer code;
6059

0 commit comments

Comments
 (0)