refactor: 优化代码结构和配置
- 在PageDto中添加toString方法以便调试 - 关闭开发环境的SQL日志输出以减少日志噪音 - 允许匿名用户发表评论 - 调整安全配置,仅允许POST方法访问认证端点 - 修改文章状态分页接口,使用查询参数替代路径参数
This commit is contained in:
@@ -62,7 +62,7 @@ public class SecurityConfig {
|
||||
.authorizeRequests()
|
||||
// 允许公开访问的路径
|
||||
// 登录和认证相关端点应该全部公开
|
||||
.antMatchers("/api/auth/**").permitAll()
|
||||
.antMatchers(HttpMethod.POST,"/api/auth/**").permitAll()
|
||||
// 文章浏览量增加接口公开
|
||||
.antMatchers(HttpMethod.POST,"/api/articles/view/**").permitAll()
|
||||
// 所有GET请求公开
|
||||
|
||||
@@ -63,8 +63,11 @@ public class ArticleController {
|
||||
* @param size 每页大小(可选,默认为10,最大为100)
|
||||
* @return 返回包含分页文章列表的ResponseMessage对象
|
||||
*/
|
||||
@GetMapping("/status/page/{status}")
|
||||
public ResponseMessage<Page<Article>> getArticlesByStatusWithPagination(@PathVariable PageDto pageDto) {
|
||||
// api/articles/status/page?status=1&page=1&size=2
|
||||
// get 只能这样不能传递json
|
||||
@GetMapping("/status/page")
|
||||
public ResponseMessage<Page<Article>> getArticlesByStatusWithPagination(PageDto pageDto) {
|
||||
System.out.println(pageDto);
|
||||
return articleService.getArticlesByStatusWithPagination(pageDto.getStatus(), pageDto.getPage(), pageDto.getSize());
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public class MessageController {
|
||||
* 创建新消息
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
// 允许匿名用户发表评论
|
||||
public ResponseMessage<Message> createMessage(@RequestBody MessageDto message) {
|
||||
logger.info("接收创建消息的请求: {}", message != null ? message.getNickname() : "null");
|
||||
return messageService.saveMessage(message);
|
||||
|
||||
@@ -34,4 +34,12 @@ public class PageDto {
|
||||
public void setSize(Integer size) {
|
||||
this.size = size;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PageDto{" +
|
||||
"status=" + status +
|
||||
", page=" + page +
|
||||
", size=" + size +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user