我只使用JavaConfig.
我有以下声明:
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
Run Code Online (Sandbox Code Playgroud)
根据以下帖子,JavaConfig是必需的: 使用纯Java配置的Spring 3.2 @value注释不起作用,但Environment.getProperty可以正常工作
以下代码完美(许多@Values通过测试目的):
@Configuration
public class ActiveMQServerConfiguration {
@Value("${localhost.address}")
private String localHost;
@Value("${remotehost.address}")
private String remoteHost;
@Value("${localhost.port}")
private Integer localPort;
@Value("${remotehost.port}")
private Integer remotePort;
@Bean(name="connectionFactory")
@Conditional(LocalHostStatusCondition.class)
public ActiveMQConnectionFactory localConnectionFactory(
@Value("${localhost.protocol}") String protocol,
@Value("${localhost.address}") String host,
@Value("${localhost.port}") String port ){
System.out.println("protocol: "+protocol);
System.out.println("host: "+host);
System.out.println("port: "+port);
System.out.println("localHost: "+localHost);
System.out.println("localPort: "+localPort);
System.out.println("remoteHost: "+remoteHost);
System.out.println("remotePort: "+remotePort);
Run Code Online (Sandbox Code Playgroud)
我可以在控制台/终端中看到
Α
protocol: tcp
host: 127.0.0.1
port: 61616
localHost: 127.0.0.1
localPort: 61616
remoteHost: …Run Code Online (Sandbox Code Playgroud) 我在Using The INSERT INTO ... SET Syntax In MySQL博客中读到,您可以使用以下SET语法来插入记录。
例子:
INSERT INTO mytable SET col1= 'val1', col6= 'val6', col10='val10';
INSERT INTO mytable SET col3= 'val3', col5= 'val5', col10='val10';
INSERT INTO mytable SET col4= 'val4', col5= 'val5', col6='val6';
Run Code Online (Sandbox Code Playgroud)
是否可以仅用 1 条语句插入多行?
我有一个小问题。我有一个Spring Boot应用程序,我将H2用数据填充我的数据库。但我无法从data-h2.sql文件加载初始数据库数据。
模型:
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "mood")
public class Mood {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "mood_id")
private int id;
@Column(name = "name")
private String name;
public Mood(String name) {
this.name = name;
}
public Mood(int id, String name) {
this.id = id;
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
data-h2.sql文件:
INSERT INTO mood (name) VALUES ('Good');
Run Code Online (Sandbox Code Playgroud)
application.properties文件:
spring.datasource.url=jdbc:h2:mem:mooddb;
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=a
spring.datasource.password=a
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create
spring.h2.console.enabled=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.defer-datasource-initialization=true
spring.h2.console.path=/h2-console
spring.h2.console.settings.trace=false …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Data2.0.6.RELEASE。
我正在为性能和演示目的进行分页。这里关于性能我说的是如果我们有很多记录最好通过页面显示它们
我有以下内容并且工作正常:
interface PersonaDataJpaCrudRepository extends PagingAndSortingRepository<Persona, String> {
}
Run Code Online (Sandbox Code Playgroud)
在@Controller与正常工作:
@GetMapping(produces=MediaType.TEXT_HTML_VALUE)
public String findAll(Pageable pageable, Model model){
Run Code Online (Sandbox Code Playgroud)
通过Thymeleaf我能够应用分页。因此,直到这里目标已经完成。
注:本Persona类都被注解JPA(@Entity,Id,等)
现在我关心以下问题:即使分页工作Spring Data的记录数量大约是多少,每条记录的内容呢?。
我的意思是:让我们假设Persona类包含20场(考虑为您的应用程序,你想要的任何实体),从而为基于视图中的html其中一个报告只使用4个领域(ID,名字,姓氏,日期),因此,我们有16个不必要的字段对于内存中的每个实体
我尝试了以下方法:
interface PersonaDataJpaCrudRepository extends PagingAndSortingRepository<Persona, String> {
@Query("SELECT p.id, id.nombre, id.apellido, id.fecha FROM Persona p")
@Override
Page<Persona> findAll(Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)
如果我在里面做一个简单的打印,@Controller它会失败关于以下内容:
java.lang.ClassCastException:
[Ljava.lang.Object; cannot be …Run Code Online (Sandbox Code Playgroud) 我正在与:
我有一个 Gradle 多模块
sonarqube-03
sonarqube-03-domain
sonarqube-03-repository
sonarqube-03-repository-impl
Run Code Online (Sandbox Code Playgroud)
我在根项目中只有一个 sonar-project.properties文件sonarqube-03,其内容如下:
# must be unique in a given SonarQube instance
sonar.projectKey=manolito-labs:sonarqube-03
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=sonarqube-03
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=src
sonar.tests=src
# Encoding of the source code. Default …Run Code Online (Sandbox Code Playgroud)