完成基本配置
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.lanyuanxiaoyao.server;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class ServerApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServerApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOriginPatterns("*")
|
||||
.allowedMethods("*")
|
||||
.allowCredentials(true)
|
||||
.maxAge(3600);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.lanyuanxiaoyao.server.api;
|
||||
|
||||
import apijson.RequestMethod;
|
||||
import apijson.StringUtil;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class ApiController {
|
||||
private String parse(RequestMethod method, String request) {
|
||||
return new ApiParser(method)
|
||||
.setNeedVerify(false)
|
||||
.parse(request);
|
||||
}
|
||||
|
||||
@RequestMapping("{method}")
|
||||
public String crud(@PathVariable("method") String method, @RequestBody String request) {
|
||||
return parse(RequestMethod.valueOf(StringUtil.toUpperCase(method)), request);
|
||||
}
|
||||
}
|
||||
168
src/main/java/com/lanyuanxiaoyao/server/api/ApiParser.java
Normal file
168
src/main/java/com/lanyuanxiaoyao/server/api/ApiParser.java
Normal file
@@ -0,0 +1,168 @@
|
||||
package com.lanyuanxiaoyao.server.api;
|
||||
|
||||
import apijson.NotNull;
|
||||
import apijson.RequestMethod;
|
||||
import apijson.orm.AbstractFunctionParser;
|
||||
import apijson.orm.AbstractObjectParser;
|
||||
import apijson.orm.AbstractParser;
|
||||
import apijson.orm.AbstractSQLConfig;
|
||||
import apijson.orm.AbstractSQLExecutor;
|
||||
import apijson.orm.AbstractVerifier;
|
||||
import apijson.orm.FunctionParser;
|
||||
import apijson.orm.Join;
|
||||
import apijson.orm.ObjectParser;
|
||||
import apijson.orm.Parser;
|
||||
import apijson.orm.SQLConfig;
|
||||
import apijson.orm.SQLExecutor;
|
||||
import apijson.orm.Verifier;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @since 2025-03-03
|
||||
*/
|
||||
@SuppressWarnings("LombokGetterMayBeUsed")
|
||||
@Slf4j
|
||||
public class ApiParser extends AbstractParser<Long> {
|
||||
@Getter
|
||||
private FunctionParser<Long> functionParser;
|
||||
|
||||
public ApiParser() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ApiParser(RequestMethod method) {
|
||||
super(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object onFunctionParse(String key, String function, String parentPath, String currentName, JSONObject currentObject, boolean containRaw) throws Exception {
|
||||
if (functionParser == null) {
|
||||
functionParser = createFunctionParser();
|
||||
functionParser.setMethod(getMethod());
|
||||
functionParser.setTag(getTag());
|
||||
functionParser.setVersion(getVersion());
|
||||
functionParser.setRequest(requestObject);
|
||||
}
|
||||
functionParser.setKey(key);
|
||||
functionParser.setParentPath(parentPath);
|
||||
functionParser.setCurrentName(currentName);
|
||||
functionParser.setCurrentObject(currentObject);
|
||||
|
||||
return functionParser.invoke(function, currentObject, containRaw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectParser<Long> createObjectParser(JSONObject request, String parentPath, SQLConfig<Long> arrayConfig, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
|
||||
return new ApiObjectParser(request, parentPath, arrayConfig, isSubquery, isTable, isArrayMainTable).setParser(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parser<Long> createParser() {
|
||||
return new ApiParser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionParser<Long> createFunctionParser() {
|
||||
return new ApiFunctionParser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLConfig<Long> createSQLConfig() {
|
||||
return new ApiSQLConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLExecutor<Long> createSQLExecutor() {
|
||||
return new ApiSQLExecutor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Verifier<Long> createVerifier() {
|
||||
return new ApiVerifier();
|
||||
}
|
||||
|
||||
public static final class ApiVerifier extends AbstractVerifier<Long> {
|
||||
@Override
|
||||
public Parser<Long> createParser() {
|
||||
return new ApiParser();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ApiSQLConfig extends AbstractSQLConfig<Long> {
|
||||
static {
|
||||
DEFAULT_DATABASE = DATABASE_MYSQL;
|
||||
DEFAULT_SCHEMA = "main";
|
||||
|
||||
TABLE_KEY_MAP.put("HostAssets", "host_assets");
|
||||
}
|
||||
|
||||
public ApiSQLConfig() {
|
||||
super(RequestMethod.GET);
|
||||
}
|
||||
|
||||
public ApiSQLConfig(RequestMethod method) {
|
||||
super(method);
|
||||
}
|
||||
|
||||
public ApiSQLConfig(RequestMethod method, String table) {
|
||||
super(method, table);
|
||||
}
|
||||
|
||||
public static SQLConfig<Long> newSQLConfig(RequestMethod method, String table, String alias, com.alibaba.fastjson.JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
|
||||
return AbstractSQLConfig.newSQLConfig(method, table, alias, request, joinList, isProcedure, new SimpleCallback<>() {
|
||||
@Override
|
||||
public SQLConfig<Long> getSQLConfig(RequestMethod method, String database, String schema, String datasource, String table) {
|
||||
return new ApiSQLConfig(method, table);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDBVersion() {
|
||||
return "8.4.4";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDBUri() {
|
||||
return "jdbc:mysql://192.168.100.140:3307/main?useSSL=false&allowPublicKeyRetrieval=true";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDBAccount() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDBPassword() {
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ApiFunctionParser extends AbstractFunctionParser<Long> {
|
||||
}
|
||||
|
||||
public static final class ApiSQLExecutor extends AbstractSQLExecutor<Long> {
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ApiObjectParser extends AbstractObjectParser<Long> {
|
||||
public ApiObjectParser(@NotNull JSONObject request, String parentPath, SQLConfig arrayConfig, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
|
||||
super(request, parentPath, arrayConfig, isSubquery, isTable, isArrayMainTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLConfig<Long> newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
|
||||
return ApiSQLConfig.newSQLConfig(method, table, alias, request, joinList, isProcedure);
|
||||
}
|
||||
}
|
||||
}
|
||||
0
src/main/resources/application.yml
Normal file
0
src/main/resources/application.yml
Normal file
Reference in New Issue
Block a user