<feat>将项目升级至SpringBoot 3.0.4

This commit is contained in:
Yean 2023-03-17 10:15:04 +08:00
parent de3fab92f8
commit 0f7ccb81dd
6 changed files with 27 additions and 20 deletions

View File

@ -5,20 +5,21 @@
<parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-boot-parent</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-boot</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<name>magic-boot</name>
<description>magic-boot</description>
<properties>
<java.version>1.8</java.version>
<java.version>17</java.version>
<magic-api.version>2.0.2</magic-api.version>
<druid.version>1.1.10</druid.version>
<hutool-all.version>5.7.22</hutool-all.version>
<sa-token.version>1.26.0</sa-token.version>
<sa-token.version>1.34.0</sa-token.version>
<poi.version>4.1.2</poi.version>
<mysql.connector.version>8.0.32</mysql.connector.version>
</properties>
<dependencies>
<dependency>
@ -37,6 +38,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
@ -50,7 +52,7 @@
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<artifactId>sa-token-spring-boot3-starter</artifactId>
<version>${sa-token.version}</version>
</dependency>
<dependency>

View File

@ -1,17 +1,17 @@
package org.ssssssss.magicboot.extension;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.ssssssss.magicapi.core.context.RequestContext;
import org.ssssssss.magicapi.core.servlet.MagicHttpServletRequest;
import org.ssssssss.magicapi.modules.servlet.ResponseModule;
import org.ssssssss.script.annotation.Comment;
import org.ssssssss.script.functions.ExtensionMethod;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
@ -32,8 +32,8 @@ public class ResponseFunctionExtension implements ExtensionMethod {
@Comment("转发")
public ResponseModule.NullValue dispatcher(ResponseModule responseModule, String url) throws ServletException, IOException {
HttpServletRequest request = RequestContext.getHttpServletRequest();
request.getRequestDispatcher(url).forward(request, getResponse());
MagicHttpServletRequest request = RequestContext.getHttpServletRequest();
// request.getRequestDispatcher(url).forward(request, getResponse());
return responseModule.end();
}

View File

@ -1,7 +1,10 @@
package org.ssssssss.magicboot.interceptor;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.extra.servlet.ServletUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
@ -14,12 +17,12 @@ import org.ssssssss.magicapi.core.model.ApiInfo;
import org.ssssssss.magicapi.core.model.Options;
import org.ssssssss.magicapi.core.service.MagicAPIService;
import org.ssssssss.magicapi.core.service.MagicResourceService;
import org.ssssssss.magicapi.core.servlet.MagicHttpServletRequest;
import org.ssssssss.magicapi.core.servlet.MagicHttpServletResponse;
import org.ssssssss.magicapi.utils.PathUtils;
import org.ssssssss.magicboot.model.StatusCode;
import org.ssssssss.script.MagicScriptContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -38,11 +41,12 @@ public class PermissionInterceptor implements RequestInterceptor, HandlerInterce
@Autowired
private JdbcTemplate template;
/*
* 当返回对象时直接将此对象返回到页面返回null时继续执行后续操作
*/
@Override
public Object preHandle(ApiInfo info, MagicScriptContext context, HttpServletRequest request, HttpServletResponse response) {
public Object preHandle(ApiInfo info, MagicScriptContext context, MagicHttpServletRequest request, MagicHttpServletResponse response) throws Exception {
String requireLogin = Objects.toString(info.getOptionValue(Options.REQUIRE_LOGIN), "");
if(requireLogin.equals("false")){
return null;
@ -60,11 +64,12 @@ public class PermissionInterceptor implements RequestInterceptor, HandlerInterce
return null;
}
@Override
public Object postHandle(RequestEntity requestEntity, Object returnValue) throws Exception {
if(StpUtil.isLogin()){
try {
HttpServletRequest request = requestEntity.getRequest();
MagicHttpServletRequest request = requestEntity.getRequest();
ApiInfo info = requestEntity.getApiInfo();
template.update("insert into sys_oper_log(api_name, api_path, api_method, cost_time, create_by, create_date, user_agent, user_ip) values(?,?,?,?,?,?,?,?)",
// PathUtils.replaceSlash(groupServiceProvider.getFullName(info.getGroupId()) + "/" + info.getName()).replace("/","-"),
@ -75,7 +80,7 @@ public class PermissionInterceptor implements RequestInterceptor, HandlerInterce
StpUtil.getLoginId(),
new Date(requestEntity.getRequestTime()),
request.getHeader("User-Agent"),
ServletUtil.getClientIP(request));
request.getRemoteAddr());
} catch (Exception ignored){
ignored.printStackTrace();
}

View File

@ -1,6 +1,6 @@
package org.ssssssss.magicboot.provider;
import cn.dev33.satoken.exception.DisableLoginException;
import cn.dev33.satoken.exception.DisableServiceException;
import org.springframework.stereotype.Component;
import org.ssssssss.magicapi.core.context.RequestEntity;
import org.ssssssss.magicapi.core.interceptor.ResultProvider;
@ -17,7 +17,7 @@ public class ExceptionResultProvider implements ResultProvider {
@Override
public Object buildException(RequestEntity requestEntity, Throwable throwable) {
if(throwable.getCause() instanceof DisableLoginException){
if(throwable.getCause() instanceof DisableServiceException){
return buildResult(requestEntity, 500, "此账号已被临时封禁,请联系管理员");
}
return buildResult(requestEntity, 500, "系统内部出现错误");

View File

@ -1,10 +1,10 @@
package org.ssssssss.magicboot.utils;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.ssssssss.magicboot.model.Global;
import javax.servlet.http.HttpServletRequest;
public class WebUtils {

View File

@ -11,13 +11,13 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<version>3.0.4</version>
<relativePath/>
</parent>
<groupId>org.ssssssss</groupId>
<artifactId>magic-boot-parent</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<name>magic-boot-parent</name>
<description>magic-boot-parent</description>