Skip to content

Commit

Permalink
chore: Spring Boot 2.7.8 => 3.0.3
Browse files Browse the repository at this point in the history
1.Spring Boot 2.7.8 => 3.0.3
2.Knife4j 适配 Spring Boot 3.x
3.ServletUtil => JakartaServletUtil
4.javax.* => jakarta.*
  • Loading branch information
Tonysj authored and Charles7c committed Mar 30, 2023
1 parent 9bbff7f commit dea160a
Show file tree
Hide file tree
Showing 44 changed files with 146 additions and 105 deletions.
7 changes: 1 addition & 6 deletions continew-admin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ limitations under the License.
<!-- Knife4j(前身是 swagger-bootstrap-ui,集 Swagger2 和 OpenAPI3 为一体的增强解决方案) -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
</dependency>
<!-- Spring Doc OpenAPI(可以结合 Spring Boot 使用的,基于 OpenAPI3 的 API 文档生成工具) -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
</dependency>

<!-- Redisson(不仅仅是一个 Redis Java 客户端) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.List;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -75,7 +75,7 @@ public abstract class BaseController<S extends BaseService<V, D, Q, C>, V, D, Q,
@Operation(summary = "分页查询列表")
@ResponseBody
@GetMapping
protected R<PageDataVO<V>> page(@Validated Q query, @Validated PageQuery pageQuery) {
public R<PageDataVO<V>> page(@Validated Q query, @Validated PageQuery pageQuery) {
this.checkPermission("list");
PageDataVO<V> pageDataVO = baseService.page(query, pageQuery);
return R.ok(pageDataVO);
Expand All @@ -93,7 +93,7 @@ protected R<PageDataVO<V>> page(@Validated Q query, @Validated PageQuery pageQue
@Operation(summary = "查询树列表")
@ResponseBody
@GetMapping("/tree")
protected R<List<Tree<Long>>> tree(@Validated Q query, @Validated SortQuery sortQuery) {
public R<List<Tree<Long>>> tree(@Validated Q query, @Validated SortQuery sortQuery) {
this.checkPermission("list");
List<Tree<Long>> list = baseService.tree(query, sortQuery, false);
return R.ok(list);
Expand All @@ -111,7 +111,7 @@ protected R<List<Tree<Long>>> tree(@Validated Q query, @Validated SortQuery sort
@Operation(summary = "查询列表")
@ResponseBody
@GetMapping("/list")
protected R<List<V>> list(@Validated Q query, @Validated SortQuery sortQuery) {
public R<List<V>> list(@Validated Q query, @Validated SortQuery sortQuery) {
this.checkPermission("list");
List<V> list = baseService.list(query, sortQuery);
return R.ok(list);
Expand All @@ -128,7 +128,7 @@ protected R<List<V>> list(@Validated Q query, @Validated SortQuery sortQuery) {
@Parameter(name = "id", description = "ID", in = ParameterIn.PATH)
@ResponseBody
@GetMapping("/{id}")
protected R<D> get(@PathVariable Long id) {
public R<D> get(@PathVariable Long id) {
this.checkPermission("list");
D detail = baseService.get(id);
return R.ok(detail);
Expand All @@ -144,7 +144,7 @@ protected R<D> get(@PathVariable Long id) {
@Operation(summary = "新增数据")
@ResponseBody
@PostMapping
protected R<Long> add(@Validated @RequestBody C request) {
public R<Long> add(@Validated @RequestBody C request) {
this.checkPermission("add");
Long id = baseService.add(request);
return R.ok("新增成功", id);
Expand All @@ -162,7 +162,7 @@ protected R<Long> add(@Validated @RequestBody C request) {
@Operation(summary = "修改数据")
@ResponseBody
@PutMapping("/{id}")
protected R update(@Validated @RequestBody C request, @PathVariable Long id) {
public R update(@Validated @RequestBody C request, @PathVariable Long id) {
this.checkPermission("update");
baseService.update(request, id);
return R.ok("修改成功");
Expand All @@ -179,7 +179,7 @@ protected R update(@Validated @RequestBody C request, @PathVariable Long id) {
@Parameter(name = "ids", description = "ID 列表", in = ParameterIn.PATH)
@ResponseBody
@DeleteMapping("/{ids}")
protected R delete(@PathVariable List<Long> ids) {
public R delete(@PathVariable List<Long> ids) {
this.checkPermission("delete");
baseService.delete(ids);
return R.ok("删除成功");
Expand All @@ -197,7 +197,7 @@ protected R delete(@PathVariable List<Long> ids) {
*/
@Operation(summary = "导出数据")
@GetMapping("/export")
protected void export(@Validated Q query, @Validated SortQuery sortQuery, HttpServletResponse response) {
public void export(@Validated Q query, @Validated SortQuery sortQuery, HttpServletResponse response) {
this.checkPermission("export");
baseService.export(query, sortQuery, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.Serializable;

import javax.validation.groups.Default;
import jakarta.validation.groups.Default;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.List;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import cn.hutool.core.lang.tree.Tree;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.util.pattern.PathPatternParser;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
Expand Down Expand Up @@ -55,7 +56,14 @@ protected RequestMappingInfo getMappingForMethod(@NonNull Method method, @NonNul
// 拼接路径前缀(合并了 @RequestMapping 的部分能力)
String pathPrefix = crudRequestMapping.value();
if (StrUtil.isNotBlank(pathPrefix)) {
requestMappingInfo = RequestMappingInfo.paths(pathPrefix).build().combine(requestMappingInfo);
/**
* 问题:RequestMappingInfo.paths(pathPrefix)返回的RequestMappingInfo对象里pathPatternsCondition = null
* 导致combine()方法抛出断言异常!
* 修复: 创建options对象, 并设置PatternParser
*/
RequestMappingInfo.BuilderConfiguration options = new RequestMappingInfo.BuilderConfiguration();
options.setPatternParser(PathPatternParser.defaultInstance);
requestMappingInfo = RequestMappingInfo.paths(pathPrefix).options(options).build().combine(requestMappingInfo);
}

// 过滤 API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import java.util.Objects;

import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;

import lombok.extern.slf4j.Slf4j;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package top.charles7c.cnadmin.common.model.query;

import javax.validation.constraints.Min;
import jakarta.validation.constraints.Min;

import lombok.Data;
import lombok.NoArgsConstructor;

import io.swagger.v3.oas.annotations.media.Schema;

import org.hibernate.validator.constraints.Range;
import org.springdoc.api.annotations.ParameterObject;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Sort;

import com.baomidou.mybatisplus.core.metadata.IPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

import org.springdoc.api.annotations.ParameterObject;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Sort;

import cn.hutool.core.util.ArrayUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.Serializable;

import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Collection;
import java.util.List;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;

import lombok.AccessLevel;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

import java.time.LocalDateTime;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.extra.servlet.JakartaServletUtil;

import top.charles7c.cnadmin.common.constant.CacheConsts;
import top.charles7c.cnadmin.common.model.dto.LogContext;
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void login(LoginUser loginUser) {

// 记录登录信息
HttpServletRequest request = ServletUtils.getRequest();
loginUser.setClientIp(ServletUtil.getClientIP(request));
loginUser.setClientIp(JakartaServletUtil.getClientIP(request));
loginUser.setLocation(IpUtils.getCityInfo(loginUser.getClientIp()));
loginUser.setBrowser(ServletUtils.getBrowser(request));
LogContext logContext = LogContextHolder.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static <Q, R> QueryWrapper<R> build(Q query) {
* 查询数据类型
*/
private static <Q, R> void buildQuery(Q query, Field field, QueryWrapper<R> queryWrapper) {
boolean accessible = field.isAccessible();
boolean accessible = field.canAccess(null);
try {
field.setAccessible(true);
// 没有 @Query,直接返回
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import java.io.IOException;
import java.util.Objects;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.core.Ordered;
import org.springframework.lang.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.time.LocalDateTime;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -41,7 +41,7 @@
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.extra.servlet.JakartaServletUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil;
Expand Down Expand Up @@ -215,13 +215,13 @@ private void logRequest(LogDO logDO, HttpServletRequest request) {
logDO.setRequestUrl(StrUtil.isBlank(request.getQueryString()) ? request.getRequestURL().toString()
: request.getRequestURL().append("?").append(request.getQueryString()).toString());
logDO.setRequestMethod(request.getMethod());
logDO.setRequestHeaders(this.desensitize(ServletUtil.getHeaderMap(request)));
logDO.setRequestHeaders(this.desensitize(JakartaServletUtil.getHeaderMap(request)));
String requestBody = this.getRequestBody(request);
if (StrUtil.isNotBlank(requestBody)) {
logDO.setRequestBody(this.desensitize(
JSONUtil.isTypeJSON(requestBody) ? JSONUtil.parseObj(requestBody) : ServletUtil.getParamMap(request)));
JSONUtil.isTypeJSON(requestBody) ? JSONUtil.parseObj(requestBody) : JakartaServletUtil.getParamMap(request)));
}
logDO.setClientIp(ServletUtil.getClientIP(request));
logDO.setClientIp(JakartaServletUtil.getClientIP(request));
logDO.setLocation(IpUtils.getCityInfo(logDO.getClientIp()));
logDO.setBrowser(ServletUtils.getBrowser(request));
logDO.setCreateUser(ObjectUtil.defaultIfNull(logDO.getCreateUser(), LoginHelper.getUserId()));
Expand All @@ -243,7 +243,7 @@ private void logRequest(LogDO logDO, HttpServletRequest request) {
private void logResponse(LogDO logDO, HttpServletResponse response) {
int status = response.getStatus();
logDO.setStatusCode(status);
logDO.setResponseHeaders(this.desensitize(ServletUtil.getHeadersMap(response)));
logDO.setResponseHeaders(this.desensitize(JakartaServletUtil.getHeadersMap(response)));
// 响应体(不记录非 JSON 响应数据)
String responseBody = this.getResponseBody(response);
if (StrUtil.isNotBlank(responseBody) && JSONUtil.isTypeJSON(responseBody)) {
Expand Down Expand Up @@ -328,7 +328,7 @@ private boolean checkIsNeedRecord(Object handler, HttpServletRequest request) {
}

// 2、检查是否需要记录内网 IP 操作
boolean isInnerIp = IpUtils.isInnerIp(ServletUtil.getClientIP(request));
boolean isInnerIp = IpUtils.isInnerIp(JakartaServletUtil.getClientIP(request));
if (isInnerIp && Boolean.FALSE.equals(operationLogProperties.getIncludeInnerIp())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

import org.springdoc.api.annotations.ParameterObject;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.format.annotation.DateTimeFormat;

import top.charles7c.cnadmin.common.annotation.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

import org.springdoc.api.annotations.ParameterObject;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.format.annotation.DateTimeFormat;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

import org.springdoc.api.annotations.ParameterObject;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.format.annotation.DateTimeFormat;

import top.charles7c.cnadmin.common.annotation.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import io.swagger.v3.oas.annotations.media.Schema;

import org.springdoc.api.annotations.ParameterObject;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.format.annotation.DateTimeFormat;

import top.charles7c.cnadmin.common.annotation.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
import top.charles7c.cnadmin.auth.config.satoken.properties.SecurityProperties;

/**
* Sa-Token 配置
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package top.charles7c.cnadmin.auth.config.satoken;
package top.charles7c.cnadmin.auth.config.satoken.properties;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.Serializable;

import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;

import lombok.Data;

Expand Down
Loading

0 comments on commit dea160a

Please sign in to comment.