Skip to content

Commit b050afa

Browse files
committed
配置了Slf4j日志
添加实例的喜爱功能
1 parent d1df125 commit b050afa

File tree

9 files changed

+218
-17
lines changed

9 files changed

+218
-17
lines changed

springboot-dubbo-api/src/main/java/com/lzq/api/pojo/Favorites.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.annotation.JsonProperty;
88
import lombok.Data;
99

10+
import java.io.Serializable;
1011
import java.util.Date;
1112

1213
/**
@@ -16,7 +17,9 @@
1617
*/
1718
@Data
1819
@TableName("favorites")
19-
public class Favorites {
20+
public class Favorites implements Serializable {
21+
22+
private static final long serialVersionUID = -5315062089881708528L;
2023

2124
/**
2225
* 用户名

springboot-dubbo-service/src/main/java/com/lzq/dubboservice/service/FavoritesServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @date :2021/8/25 10:48
2525
*/
2626
@Component
27-
@Service(interfaceClass = FollowService.class)
27+
@Service(interfaceClass = FavoritesService.class)
2828
public class FavoritesServiceImpl extends ServiceImpl<FavoritesMapper, Favorites> implements FavoritesService {
2929

3030
@Resource
@@ -39,7 +39,7 @@ public Boolean addFavorites(Favorites favorites) {
3939
do {
4040
//用来查询关注人
4141
QueryWrapper<Example> wrapper = new QueryWrapper<>();
42-
wrapper.eq("exampleId", favorites.getExampleId());
42+
wrapper.eq("example_id", favorites.getExampleId());
4343
//获取喜爱的用例
4444
Example example = exampleMapper.selectOne(wrapper);
4545
example.setFavorites(example.getFavorites() + 1);

springboot-dubbo-service/src/main/resources/application.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ dubbo:
3434
registry:
3535
protocol: zookeeper
3636
address: zookeeper://49.235.126.19:2181
37-
timeout: 60000
37+
timeout: 600000
3838
protocol:
3939
name: dubbo
4040
port: 20880
4141
consumer:
4242
retries: 0
43-
timeout: 60000
43+
timeout: 600000
4444

4545
#扫描包的位置
4646
scan:
@@ -63,4 +63,7 @@ jasypt:
6363
mybatis-plus:
6464
configuration:
6565
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
66-
mapper-locations: classpath:mapper/*xml
66+
mapper-locations: classpath:mapper/*xml
67+
68+
logging:
69+
config: classpath:logback.xml
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration debug="true">
3+
4+
5+
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{50} - %msg%n"/>
6+
7+
<property name="LOG_HOME" value="F:/项目/MyDemo/data/logService"/>
8+
9+
10+
<!--输出到控制台-->
11+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
12+
<encoder>
13+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
14+
<!--<charset>utf8</charset>-->
15+
</encoder>
16+
</appender>
17+
18+
19+
<!--info 级别的日志-->
20+
<!-- 按照每天生成日志文件 -->
21+
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
22+
<filter class="ch.qos.logback.classic.filter.LevelFilter">
23+
<level>INFO</level>
24+
<onMatch>ACCEPT</onMatch>
25+
<onMismatch>DENY</onMismatch>
26+
</filter>
27+
<encoder>
28+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
29+
</encoder>
30+
<file>${LOG_HOME}/info.log</file>
31+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
32+
<!--日志文件输出的文件名-->
33+
<fileNamePattern>${LOG_HOME}/achiveLog/info-%d{yyyy-MM-dd}_%i.log</fileNamePattern>
34+
<maxFileSize>50MB</maxFileSize>
35+
<!--日志文件保留天数-->
36+
<MaxHistory>180</MaxHistory>
37+
</rollingPolicy>
38+
</appender>
39+
40+
41+
<!--WARN 级别的日志-->
42+
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
43+
<filter class="ch.qos.logback.classic.filter.LevelFilter">
44+
<level>WARN</level>
45+
<onMatch>ACCEPT</onMatch>
46+
<onMismatch>DENY</onMismatch>
47+
</filter>
48+
<encoder>
49+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
50+
</encoder>
51+
<file>${LOG_HOME}/warn.log</file>
52+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
53+
<fileNamePattern>${LOG_HOME}/achiveLog/warn-%d{yyyy-MM-dd}_%i.log</fileNamePattern>
54+
<maxFileSize>50MB</maxFileSize>
55+
<MaxHistory>180</MaxHistory>
56+
</rollingPolicy>
57+
</appender>
58+
59+
<!--ERROR 级别的日志-->
60+
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
61+
<filter class="ch.qos.logback.classic.filter.LevelFilter">
62+
<level>ERROR</level>
63+
<onMatch>ACCEPT</onMatch>
64+
<onMismatch>DENY</onMismatch>
65+
</filter>
66+
<encoder>
67+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
68+
</encoder>
69+
<file>${LOG_HOME}/error.log</file>
70+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
71+
<fileNamePattern>${LOG_HOME}/achiveLog/error-%d{yyyy-MM-dd}_%i.log</fileNamePattern>
72+
<maxFileSize>50MB</maxFileSize>
73+
<MaxHistory>180</MaxHistory>
74+
</rollingPolicy>
75+
</appender>
76+
77+
<!-- 日志输出级别 -->
78+
<root level="INFO">
79+
<appender-ref ref="CONSOLE"/>
80+
<appender-ref ref="INFO"/>
81+
<appender-ref ref="WARN"/>
82+
<appender-ref ref="ERROR"/>
83+
</root>
84+
</configuration>

springboot-dubbo-web/src/main/java/com/lzq/web/config/UserDetailConfig.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.lzq.api.pojo.Account;
55
import com.lzq.api.service.AccountService;
66
import com.lzq.api.service.RoleService;
7+
import lombok.extern.slf4j.Slf4j;
78
import org.apache.dubbo.config.annotation.Reference;
89
import org.springframework.beans.factory.annotation.Autowired;
910
import org.springframework.security.core.userdetails.UserDetails;
@@ -12,6 +13,7 @@
1213
import org.springframework.security.crypto.password.PasswordEncoder;
1314
import org.springframework.stereotype.Service;
1415

16+
@Slf4j
1517
@Service
1618
public class UserDetailConfig implements UserDetailsService {
1719

@@ -27,18 +29,18 @@ public class UserDetailConfig implements UserDetailsService {
2729

2830
@Override
2931
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
30-
System.out.println(s);
32+
log.info(s);
3133
//生产用户
3234
Account account = null;
3335
//判断用户所用账号为邮箱还是用户名
3436
if (s.split("\\.").length > 1) {
3537
//根据邮箱查询用户
3638
account = accountService.queryByEmail(s);
37-
System.out.println(account);
39+
log.info(account.toString());
3840
} else {
3941
//根据用户名查询用户
4042
account = accountService.queryByUsername(s);
41-
System.out.println(account);
43+
log.info(account.toString());
4244
}
4345
if (account == null) {
4446
throw new UsernameNotFoundException("账号或密码错误");

springboot-dubbo-web/src/main/java/com/lzq/web/controller/ExampleController.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
import com.lzq.api.pojo.Example;
55
import com.lzq.api.pojo.Content;
6+
import com.lzq.api.pojo.Favorites;
67
import com.lzq.api.service.ContentService;
78
import com.lzq.api.service.ExampleService;
9+
import com.lzq.api.service.FavoritesService;
810
import com.lzq.web.utils.ExampleUtils;
911
import com.lzq.web.utils.JWTUtils;
1012
import com.lzq.web.utils.QiniuyunUtils;
@@ -37,10 +39,11 @@ public class ExampleController {
3739
@Reference
3840
private ExampleService exampleService;
3941

40-
4142
@Reference
4243
private ContentService contentService;
4344

45+
@Reference
46+
private FavoritesService favoritesService;
4447

4548
/**
4649
* 创建一个实例
@@ -79,7 +82,6 @@ public Map<String, Object> CreateFile(Example example) {
7982
}
8083
}
8184

82-
8385
/**
8486
* 保存实例内容和编译后的html代码
8587
*
@@ -134,7 +136,6 @@ public Map<String, Object> SaveExample(Example example, Content exampleContent,
134136
}
135137
}
136138

137-
138139
/**
139140
* 根据用户名查询全部实例
140141
* @return
@@ -161,5 +162,22 @@ public Map<String,Object> getPublicExample(String username){
161162
return ResultMapUtils.ResultMap(true,0,list);
162163
}
163164

165+
/**
166+
* 添加喜爱
167+
* @param favorites
168+
* @return
169+
*/
170+
@PostMapping("/addFavorites")
171+
@ApiOperation("添加喜爱")
172+
public Map<String,Object> addFavorites(Favorites favorites){
173+
//判断是否用户已登录,登录则进行数据插入,否则则不做任何操作
174+
if (!StringUtils.isNullOrEmpty(favorites.getUsername())){
175+
Boolean bol = favoritesService.addFavorites(favorites);
176+
return ResultMapUtils.ResultMap(bol,0,null);
177+
}else {
178+
return ResultMapUtils.ResultMap(false,1,null);
179+
}
180+
}
181+
164182

165183
}

springboot-dubbo-web/src/main/java/com/lzq/web/controller/IndexController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import com.qiniu.util.Auth;
1717
import io.swagger.annotations.Api;
1818
import io.swagger.annotations.ApiOperation;
19+
import lombok.extern.slf4j.Slf4j;
1920
import org.apache.commons.lang.StringUtils;
2021
import org.apache.dubbo.config.annotation.Reference;
22+
import org.slf4j.ILoggerFactory;
2123
import org.springframework.dao.DuplicateKeyException;
2224
import org.springframework.data.redis.core.StringRedisTemplate;
2325
import org.springframework.web.bind.annotation.*;
@@ -34,6 +36,7 @@
3436
* @description:主页面接口
3537
* @date :2021/8/23 15:40
3638
*/
39+
@Slf4j
3740
@RestController
3841
@RequestMapping({"/index"})
3942
@Api(value = "主页面接口",description = "主页面接口")
@@ -162,7 +165,7 @@ public Map<String, Object> register(Account account, String code) {
162165
String s = stringRedisTemplate.opsForValue().get(account.getEmail());
163166
if (code.equals(s)) {
164167
try {
165-
System.out.println("我到了");
168+
log.info("我到了");
166169
accountService.insert(account);
167170
//注册成功
168171
return ResultMapUtils.ResultMap(true,0,null);

springboot-dubbo-web/src/main/resources/application.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ dubbo:
3131
registry:
3232
protocol: zookeeper
3333
address: zookeeper://49.235.126.19:2181
34-
# consumer:
35-
# retries: 0
36-
# timeout: 60000
34+
timeout: 600000
35+
consumer:
36+
retries: 0
37+
timeout: 600000
3738

3839
#数据加密
3940
jasypt:
@@ -46,4 +47,7 @@ jasypt:
4647

4748
server:
4849
#服务器接口
49-
port: 8090
50+
port: 8090
51+
52+
logging:
53+
config: classpath:logback.xml
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration debug="true">
3+
4+
5+
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{50} - %msg%n"/>
6+
7+
<property name="LOG_HOME" value="F:/项目/MyDemo/data/logWeb"/>
8+
9+
10+
<!--输出到控制台-->
11+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
12+
<encoder>
13+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
14+
<!--<charset>utf8</charset>-->
15+
</encoder>
16+
</appender>
17+
18+
19+
<!--info 级别的日志-->
20+
<!-- 按照每天生成日志文件 -->
21+
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
22+
<filter class="ch.qos.logback.classic.filter.LevelFilter">
23+
<level>INFO</level>
24+
<onMatch>ACCEPT</onMatch>
25+
<onMismatch>DENY</onMismatch>
26+
</filter>
27+
<encoder>
28+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
29+
</encoder>
30+
<file>${LOG_HOME}/info.log</file>
31+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
32+
<!--日志文件输出的文件名-->
33+
<fileNamePattern>${LOG_HOME}/achiveLog/info-%d{yyyy-MM-dd}_%i.log</fileNamePattern>
34+
<maxFileSize>50MB</maxFileSize>
35+
<!--日志文件保留天数-->
36+
<MaxHistory>30</MaxHistory>
37+
</rollingPolicy>
38+
</appender>
39+
40+
41+
<!--WARN 级别的日志-->
42+
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
43+
<filter class="ch.qos.logback.classic.filter.LevelFilter">
44+
<level>WARN</level>
45+
<onMatch>ACCEPT</onMatch>
46+
<onMismatch>DENY</onMismatch>
47+
</filter>
48+
<encoder>
49+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
50+
</encoder>
51+
<file>${LOG_HOME}/warn.log</file>
52+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
53+
<fileNamePattern>${LOG_HOME}/achiveLog/warn-%d{yyyy-MM-dd}_%i.log</fileNamePattern>
54+
<maxFileSize>50MB</maxFileSize>
55+
<MaxHistory>30</MaxHistory>
56+
</rollingPolicy>
57+
</appender>
58+
59+
<!--ERROR 级别的日志-->
60+
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
61+
<filter class="ch.qos.logback.classic.filter.LevelFilter">
62+
<level>ERROR</level>
63+
<onMatch>ACCEPT</onMatch>
64+
<onMismatch>DENY</onMismatch>
65+
</filter>
66+
<encoder>
67+
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
68+
</encoder>
69+
<file>${LOG_HOME}/error.log</file>
70+
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
71+
<fileNamePattern>${LOG_HOME}/achiveLog/error-%d{yyyy-MM-dd}_%i.log</fileNamePattern>
72+
<maxFileSize>50MB</maxFileSize>
73+
<MaxHistory>30</MaxHistory>
74+
</rollingPolicy>
75+
</appender>
76+
77+
<!-- 日志输出级别 -->
78+
<root level="INFO">
79+
<appender-ref ref="CONSOLE"/>
80+
<appender-ref ref="INFO"/>
81+
<appender-ref ref="WARN"/>
82+
<appender-ref ref="ERROR"/>
83+
</root>
84+
</configuration>

0 commit comments

Comments
 (0)