feat: 升级核心依赖版本并适配新API
- 将Spring Boot升级至4.0.0,Hibernate升级至7.1.8 - 迁移Hibernate命名策略至PhysicalNamingStrategySnakeCaseImpl - 移除废弃的StandardGenerator接口引用 - 更新Jackson导入路径至tools.jackson包
This commit is contained in:
@@ -8,11 +8,11 @@ import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.PhysicalNamingStrategySnakeCaseImpl;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||
import org.hibernate.tool.schema.TargetType;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
|
||||
import org.springframework.boot.hibernate.SpringImplicitNamingStrategy;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -54,7 +54,7 @@ public class Helper {
|
||||
var metadataSources = new MetadataSources(
|
||||
new StandardServiceRegistryBuilder()
|
||||
.applySetting("hibernate.dialect", dialect.getName())
|
||||
.applySetting("hibernate.physical_naming_strategy", CamelCaseToUnderscoresNamingStrategy.class.getName())
|
||||
.applySetting("hibernate.physical_naming_strategy", PhysicalNamingStrategySnakeCaseImpl.class.getName())
|
||||
.applySetting("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName())
|
||||
.applySetting("hibernate.connection.url", jdbc)
|
||||
.applySetting("hibernate.connection.username", username)
|
||||
@@ -231,7 +231,7 @@ public class Helper {
|
||||
// 2. 前一个字符是数字
|
||||
// 3. 当前大写字母不是最后一个字符,且下一个字符是小写(处理连续大写字母如"XMLParser" -> "xml_parser")
|
||||
char previousChar = camelCase.charAt(i - 1);
|
||||
if (Character.isLowerCase(previousChar)
|
||||
if (Character.isLowerCase(previousChar)
|
||||
|| Character.isDigit(previousChar)
|
||||
|| (i < camelCase.length() - 1 && Character.isLowerCase(camelCase.charAt(i + 1)))) {
|
||||
result.append('_');
|
||||
|
||||
@@ -5,10 +5,9 @@ import java.time.Instant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
|
||||
@Slf4j
|
||||
public class SnowflakeIdGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
public class SnowflakeIdGenerator implements IdentifierGenerator {
|
||||
@Override
|
||||
public Serializable generate(SharedSessionContractImplementor session, Object object) {
|
||||
try {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.lanyuanxiaoyao.service.template.jpa;
|
||||
|
||||
import com.blinkfox.fenix.EnableFenix;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.service.template.jpa.entity.Company;
|
||||
import com.lanyuanxiaoyao.service.template.jpa.entity.Company_;
|
||||
import com.lanyuanxiaoyao.service.template.jpa.entity.Employee;
|
||||
@@ -26,6 +23,8 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
@@ -47,7 +46,7 @@ public class TestApplication {
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void runTests() throws JsonProcessingException {
|
||||
public void runTests() {
|
||||
// 增
|
||||
var cid1 = saveItem("company", "{\"name\": \"Apple\",\"members\": 10}").get("data").asLong();
|
||||
var cid2 = saveItem("company", "{\"name\": \"Banana\",\"members\": 20}").get("data").asLong();
|
||||
@@ -150,7 +149,7 @@ public class TestApplication {
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void runSpecificationTests() throws JsonProcessingException {
|
||||
public void runSpecificationTests() {
|
||||
// 增
|
||||
var cid1 = saveItem("company", "{\"name\": \"Apple\",\"members\": 10}").get("data").asLong();
|
||||
var cid2 = saveItem("company", "{\"name\": \"Banana\",\"members\": 20}").get("data").asLong();
|
||||
@@ -232,7 +231,7 @@ public class TestApplication {
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void runNativeQueryTests() throws JsonProcessingException {
|
||||
public void runNativeQueryTests() {
|
||||
// 增
|
||||
var cid1 = saveItem("company", "{\"name\": \"Apple\",\"members\": 10}").get("data").asLong();
|
||||
var cid2 = saveItem("company", "{\"name\": \"Banana\",\"members\": 20}").get("data").asLong();
|
||||
@@ -255,7 +254,7 @@ public class TestApplication {
|
||||
return headers;
|
||||
}
|
||||
|
||||
private JsonNode saveItem(String path, String body) throws JsonProcessingException {
|
||||
private JsonNode saveItem(String path, String body) {
|
||||
var response = REST_CLIENT.postForEntity(
|
||||
"%s/%s/save".formatted(BASE_URL, path),
|
||||
new HttpEntity<>(body, headers()),
|
||||
@@ -266,7 +265,7 @@ public class TestApplication {
|
||||
return MAPPER.readTree(response.getBody());
|
||||
}
|
||||
|
||||
private JsonNode listItems(String path) throws JsonProcessingException {
|
||||
private JsonNode listItems(String path) {
|
||||
var response = REST_CLIENT.getForEntity(
|
||||
"%s/%s/list".formatted(BASE_URL, path),
|
||||
String.class
|
||||
@@ -276,7 +275,7 @@ public class TestApplication {
|
||||
return MAPPER.readTree(response.getBody());
|
||||
}
|
||||
|
||||
private JsonNode listItems(String path, String query) throws JsonProcessingException {
|
||||
private JsonNode listItems(String path, String query) {
|
||||
var response = REST_CLIENT.postForEntity(
|
||||
"%s/%s/list".formatted(BASE_URL, path),
|
||||
new HttpEntity<>(query, headers()),
|
||||
@@ -287,7 +286,7 @@ public class TestApplication {
|
||||
return MAPPER.readTree(response.getBody());
|
||||
}
|
||||
|
||||
private JsonNode detailItem(String path, Long id) throws JsonProcessingException {
|
||||
private JsonNode detailItem(String path, Long id) {
|
||||
var response = REST_CLIENT.getForEntity(
|
||||
"%s/%s/detail/%d".formatted(BASE_URL, path, id),
|
||||
String.class
|
||||
|
||||
Reference in New Issue
Block a user