@Entity
public class Person {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private int salary;
@Version
private long version;
// ...getters and setters
}
Run Code Online (Sandbox Code Playgroud)
version?hibernateTemplate.saveOrUpdate什么?是否支持所有数据库?hibernateTemplate.saveOrUpdate每次增加版本值吗?我有这个应用程序使用配置文件"默认"它连接到PostgreSQL数据库并使用Flyway进行迁移.
我想创建另一个名为"devEmbeddedCreate"的配置文件,我需要使用嵌入式数据库服务器(h2),spring.jpa.hibernate.ddl-auto=create-drop在application.properties文件中创建数据库并执行一个不同的"data.sql"脚本来初始化一些表.
如果我将脚本保留为"data.sql"文件名,则每次应用程序启动时都会执行该文件.这是我不想发生的事情,我需要它只在某个特定的配置文件中执行.
我试过的事情:
文档提到可以有一个schema-${platform}.sql文件,您可以spring.datasource.platform在配置中定义平台.它不适用于data-${platform}.sql文件的问题.(这里)
创建了一个EmbeddedDatabaseBuilder.问题是当我使用它时,它不会自动创建数据库并仅应用指定的脚本.无法找到自动创建数据库的方法spring.jpa.hibernate.ddl-auto=create-drop.(这里和这里)
寻找一种将XML配置转换为基于Java的配置的方法,找到了一种创建数据库的方法.经过大量的调整和更改在内存中工作后,它看起来很有前景,但是在启动时(这里)无法找出数据库为什么关闭(并擦除其所有结构)
必须有一种更简单的方法来说出"嘿春天...... data-devEmbeddedCreate.sql当我的个人资料出现时,运行strartup这个脚本devEmbeddedCreate,对吗?
我正在使用Springboot和Flyway.迁移工作正常,但我希望能够clean在应用程序上下文加载test配置文件时执行flyway命令.
是否可以配置SpringBoot clean,然后migrate如果活动配置文件是test?
在我的Java类中,我们刚刚了解了以下每种原始数据类型:
byteshortintlong由于long数据类型包含的位数最多,因此专门使用long数据类型以避免限制是否有意义?
问题
long数据类型是否有特殊的缺点?int数据类型而不是数据类型是否有意义long?我有一个变量类,我不希望它为null或空.有没有办法使用Lombok构建器来设置属性?我可以使用,@NonNull但我无法验证它是否为空.显然,另一种选择是编写我自己的构建器来执行所有这些检查.例如:
class Person {
@NonNull
private String firstName;
@NonNull
private String lastName;
public static class PersonBuilder() {
// .
// .
// .
public Person build() {
//do checks for empty etc and return object
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要发送一个HTTP cookie,我正在使用RestTemplate:
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Cookie", "SERVERID=c52");
HttpEntity requestEntity = new HttpEntity(null, requestHeaders);
ResponseEntity responses = restTemplate.exchange(webService.getValidateUserUrl(),
HttpMethod.POST, requestEntity, String.class, mapValidateUser);
Run Code Online (Sandbox Code Playgroud)
但是,接收服务器看不到cookie.
我在Objective C项目上使用OCLint来获取SonarQube配置文件.
现在我的IOS Objective C项目包含一个带有多个子src目录的src目录.在我的sonar-project.properties文件中有以下条目
sonar.sources=MySrcFolder/
Run Code Online (Sandbox Code Playgroud)
现在在这个src文件夹中我想在多个子文件夹上运行声纳配置文件并排除一些第三方src文件夹.谁能帮我这个 ?现在,声纳在上述任何文件夹子文件夹中的所有src上运行配置文件?
我正在使用Spring Boot,我有一个用例,用户可以上传一个应该重启应用程序的文件(因为在创建多个bean时会使用用户的上传).我知道我可以避免重启应用程序,但此刻 - 这就是我想要的.
我在Spring-Cloud项目中找到了RestartEndpoint,但似乎并没有 ApplicationPreparedEvent被解雇.有没有其他方法可以编程重启Spring Boot应用程序?
Spring BeanUtils.copyProperties()提供了在复制bean时忽略特定属性的选项:
public static void copyProperties(Object source,
Object target,
String[] ignoreProperties) throws BeansException
Run Code Online (Sandbox Code Playgroud)
Apache Commons BeanUtils是否提供类似的功能?
使用Spring时也可以忽略空值BeanUtils.copyProperties(),我在Commons BeanUtils中看到这个功能:
Date defaultValue = null;
DateConverter converter = new DateConverter(defaultValue);
ConvertUtils.register(converter, Date.class);
Run Code Online (Sandbox Code Playgroud)
我可以用Spring的BeanUtils实现同样的目标吗?
java ×5
spring ×5
spring-boot ×3
hibernate ×2
jpa ×2
builder ×1
dao ×1
flyway ×1
html5 ×1
integer ×1
lombok ×1
long-integer ×1
mapping ×1
resttemplate ×1
sonarqube ×1