完成基本配置
This commit is contained in:
84
.gitignore
vendored
Normal file
84
.gitignore
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
.idea/**/aws.xml
|
||||
.idea/**/contentModel.xml
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
cmake-build-*/
|
||||
.idea/**/mongoSettings.xml
|
||||
*.iws
|
||||
out/
|
||||
.idea_modules/
|
||||
atlassian-ide-plugin.xml
|
||||
.idea/replstate.xml
|
||||
.idea/sonarlint/
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.idea/httpRequests
|
||||
.idea/caches/build_file_checksums.ser
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.project
|
||||
.classpath
|
||||
*~
|
||||
.fuse_hidden*
|
||||
.directory
|
||||
.Trash-*
|
||||
.nfs*
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
gradle-app.setting
|
||||
!gradle-wrapper.jar
|
||||
!gradle-wrapper.properties
|
||||
.gradletasknamecache
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
*.stackdump
|
||||
[Dd]esktop.ini
|
||||
$RECYCLE.BIN/
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
*.lnk
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Icon
|
||||
._*
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
14
.idea/compiler.xml
generated
Normal file
14
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="spring-boot-apijson-server" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
17
.idea/dataSources.xml
generated
Normal file
17
.idea/dataSources.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="main@192.168.100.140" uuid="3927a7af-9ef1-4d08-b8e2-e95f881ee2f4">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://192.168.100.140:3307/main?useSSL=false&allowPublicKeyRetrieval=true</jdbc-url>
|
||||
<jdbc-additional-properties>
|
||||
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
30
.idea/jarRepositories.xml
generated
Normal file
30
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jitpack.io" />
|
||||
<option name="name" value="jitpack.io" />
|
||||
<option name="url" value="https://jitpack.io" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="central" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="temurin-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
4
.idea/vcs.xml
generated
Normal file
4
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
</project>
|
||||
94
pom.xml
Normal file
94
pom.xml
Normal file
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>spring-boot-apijson-server</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<spring-boot.version>3.4.0</spring-boot.version>
|
||||
<spring-cloud.version>2024.0.0</spring-cloud.version>
|
||||
<hutool.version>5.8.32</hutool.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.Tencent</groupId>
|
||||
<artifactId>APIJSON</artifactId>
|
||||
<version>7.7.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-build</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
@@ -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