切换框架为elide
This commit is contained in:
6
.idea/ApifoxUploaderProjectSetting.xml
generated
Normal file
6
.idea/ApifoxUploaderProjectSetting.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ApifoxUploaderProjectSetting">
|
||||
<option name="apiAccessToken" value="APS-0ZZaS4q0gUiFOlbBJMN8hAmS7viQNi4D" />
|
||||
</component>
|
||||
</project>
|
||||
28
.idea/codeStyles/Project.xml
generated
Normal file
28
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,28 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
|
||||
<value />
|
||||
</option>
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
</value>
|
||||
</option>
|
||||
</JavaCodeStyleSettings>
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
13
.idea/dataSources.xml
generated
13
.idea/dataSources.xml
generated
@@ -13,5 +13,18 @@
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="main@localhost" uuid="7b3a0e07-1655-4b6e-85e7-1767312c5ad5">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://localhost: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.resource.type" value="Deployment" />
|
||||
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||
</jdbc-additional-properties>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
27
pom.xml
27
pom.xml
@@ -16,19 +16,9 @@
|
||||
<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>
|
||||
<elide.version>7.1.4</elide.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>
|
||||
@@ -38,6 +28,15 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yahoo.elide</groupId>
|
||||
<artifactId>elide-spring-boot-starter</artifactId>
|
||||
<version>${elide.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
@@ -45,12 +44,6 @@
|
||||
<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>
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/main/java/com/lanyuanxiaoyao/server/entity/School.java
Normal file
36
src/main/java/com/lanyuanxiaoyao/server/entity/School.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.lanyuanxiaoyao.server.entity;
|
||||
|
||||
import com.yahoo.elide.annotation.Include;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250304
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@Include
|
||||
public class School {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
private String id;
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "school")
|
||||
@ToString.Exclude
|
||||
private List<User> users;
|
||||
}
|
||||
41
src/main/java/com/lanyuanxiaoyao/server/entity/User.java
Normal file
41
src/main/java/com/lanyuanxiaoyao/server/entity/User.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.lanyuanxiaoyao.server.entity;
|
||||
|
||||
import com.yahoo.elide.annotation.Include;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250304
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@Include
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
private String id;
|
||||
@Column(unique = true, nullable = false)
|
||||
private String username;
|
||||
@Column(nullable = false)
|
||||
private String password;
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private School school;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3307/main?useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: test
|
||||
password: test
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
jpa:
|
||||
show-sql: true
|
||||
generate-ddl: true
|
||||
elide:
|
||||
json-api:
|
||||
enabled: true
|
||||
path: /json
|
||||
logging:
|
||||
level:
|
||||
com:
|
||||
yahoo:
|
||||
elide:
|
||||
datastores:
|
||||
jpql:
|
||||
query:
|
||||
DefaultQueryLogger: debug
|
||||
33
src/test/resources/school.http
Normal file
33
src/test/resources/school.http
Normal file
@@ -0,0 +1,33 @@
|
||||
### Query
|
||||
GET http://localhost:8080/json/school
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
### Create
|
||||
POST http://localhost:8080/json/school
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"type": "school",
|
||||
"attributes": {
|
||||
"name": "school_1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Modify
|
||||
PATCH http://localhost:8080/json/school/f424701d-dc94-42be-b2e6-79221b18ee7d
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"type": "user",
|
||||
"id": "f424701d-dc94-42be-b2e6-79221b18ee7d",
|
||||
"attributes": {
|
||||
"password": "lonely"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Delete
|
||||
DELETE http://localhost:8080/json/school/f424701d-dc94-42be-b2e6-79221b18ee7d
|
||||
45
src/test/resources/user.http
Normal file
45
src/test/resources/user.http
Normal file
@@ -0,0 +1,45 @@
|
||||
### Query
|
||||
GET http://localhost:8080/json/user?sort=-username&page[number]=1&page[size]=10&filter[user]=username==lanyuan*
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
### Create
|
||||
POST http://localhost:8080/json/user
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"type": "user",
|
||||
"attributes": {
|
||||
"username": "tony",
|
||||
"password": "tony"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Modify
|
||||
PATCH http://localhost:8080/json/user/4a5668ef-52d7-4a46-a6f8-60d918f0562d
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"type": "user",
|
||||
"id": "4a5668ef-52d7-4a46-a6f8-60d918f0562d",
|
||||
"attributes": {
|
||||
"password": "lonely"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### Modify Relationship
|
||||
PATCH http://localhost:8080/json/user/4a5668ef-52d7-4a46-a6f8-60d918f0562d/relationships/school
|
||||
Content-Type: application/vnd.api+json
|
||||
|
||||
{
|
||||
"data": {
|
||||
"type": "school",
|
||||
"id": "bd80714e-7345-4d65-97ae-3339c16b0275"
|
||||
}
|
||||
}
|
||||
|
||||
### Delete
|
||||
DELETE http://localhost:8080/json/user/f424701d-dc94-42be-b2e6-79221b18ee7d
|
||||
Reference in New Issue
Block a user