我定义了以下实体:
@Entity
@Table(name = "EmailTemplate")
public class EmailTemplate {
Run Code Online (Sandbox Code Playgroud)
尽管有表格注释,但我收到了java.sql.SQLException: Invalid object name 'email_template'
.如何防止将诸如EmailTemplate之类的实体类转换为email_template表名?
编辑:
我正在使用Spring Boot:启动JPA.从我的build.gradle文件,
compile("org.springframework.boot:spring-boot-starter-data-jpa")
Run Code Online (Sandbox Code Playgroud) 我遇到了与此处报道的相同问题:
我有一个Java项目A,它依赖于项目B(模块),而项目B依赖于项目C(另一个模块).对于项目AI,我想设置"includeBuild ../projectB",而项目BI也想设置"includeBuild ../projectC",以便我可以在Eclipse + Buildship 2.0中开发所有内容,而无需为每一个小变化运行Gradle在每个项目A,B和C.
但如果我设置了这个,我得到:"包含的构建'%s'不能包含构建."
预期的行为
递归"includeBuild"将递归地包含依赖项目.
当前行为
我得到"包含的构建'%s'不能包含构建."
你的环境
Gradle 3.5,Buildship 2.0,Eclipse 3.6
我该如何解决/解决这个问题?在我的实例中,我有包含电子邮件功能的实用程序项目(使用JavaMail).数据项目和UI项目中需要电子邮件功能.UI项目还取决于数据项目.
我有一个kendoNumericTextBox.我有代码设置与kendoNumericTextBox关联的input元素的值.例如,代码调用:
$('#myId').val('test');
Run Code Online (Sandbox Code Playgroud)
不幸的是,kendo数字文本框不会自动反映该值.如何告诉kendoNumericTextBox更新其值?我知道kendoNumericTextBox上有一个方法如下:
$('#myId').data('kendoNumericTextBox').value('test');
Run Code Online (Sandbox Code Playgroud)
但是,我填充了很多字段,并不确定哪些字段是kendoNumericTextBox字段.因此,我更愿意使用所选插件来调用基于底层组件刷新值的内容.例如,使用所选的插件,我可以调用:
$('.chosen').trigger('liszt:updated');
Run Code Online (Sandbox Code Playgroud)
根据基础选择组件的值更新所有值.
我有一个kendo窗口,里面有一个表单.表单包含输入元素,其中填充了记录的数据.用户可以关闭窗口并选择要查看的其他记录.当用户执行此操作时,我需要使用相同的表单但使用不同的记录数据再次显示kendo窗口.这就是我目前正在做的事情
if (!$("#winContainer").data("kendoWindow")) {
$("#winContainer").kendoWindow({
modal: true,
width: "969px",
height: "646px",
title: "View Record",
content: "record.jsp"
});
} else {
$("#winContainer").data("kendoWindow").refresh({url: 'record.jsp'});
}
$("#winContainer").data("kendoWindow").center().open();
Run Code Online (Sandbox Code Playgroud)
表单包含在record.jsp中,我使用之前从服务器收到的JSON数据(通过record.jsp中引用的JavaScript)填充它.我需要确保在窗体中填充新记录数据之前不显示窗口.这是正确的方法吗?还是有更好的方法?
我需要确定一个实体是否已被持久化.不幸的是,我没有id,但是如果实体的其他六个字段的值与持久化实体匹配,我可以确定该实体已经被持久化.我正在使用Spring JPA存储库并知道我可以执行以下操作:
Test findByField1AndField2And...(String field1, String field2,...)
Run Code Online (Sandbox Code Playgroud)
有没有办法做类似的事情:
@Query("SELECT t "
+ "FROM Test t "
+ "WHERE "
+ "t.field1 = :testWithSomeFieldsPopulated.field1 and "
+ "t.field2 = :testWithSomeFieldsPopulated.field2 and ..." )
Test findByTest(@Param("testWithSomeFieldsPopulated") Test testWithSomeFieldsPopulated)
Run Code Online (Sandbox Code Playgroud) 我有一个数据项目和UI项目.这两个项目都是Spring Boot应用程序.两个项目都具有相同的根包(com.myorg),其中主类具有注释@SpringBootApplication
.
数据项目的主要类是:
package com.myorg;
@SpringBootApplication
public class DataApplication {
public static void main(String[] args) {
SpringApplication.run(DataApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
UI项目的主要类是:
package com.myorg;
@SpringBootApplication
public class UiApplication {
public static void main(String[] args) {
SpringApplication.run(UiApplication .class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
UI项目通过以下Gradle依赖项依赖于数据项目:
dependencies {
compile('com.myorg:data:1.0')
}
Run Code Online (Sandbox Code Playgroud)
如果我运行UI应用程序,它运行没有问题.但是,如果我在UI应用程序中运行集成测试,如下所示:
package com.myorg
@RunWith(SpringRunner.class)
@SpringBootTest
public class UiIntTest {
@Test
public void contextLoads() {
}
}
Run Code Online (Sandbox Code Playgroud)
发生以下初始化错误:
java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes
在数据项目的主类中,如果我替换@SpringBootApplication
为
@Configuration
@EnableAutoConfiguration
@ComponentScan({ "com.myorg" })
Run Code Online (Sandbox Code Playgroud)
尝试运行其集成测试时,我收到以下初始化错误:
java.lang.IllegalStateException: Unable …
Run Code Online (Sandbox Code Playgroud) 我有来自客户端的参数,例如
ids[] = 11
ids[] = 12
ids[] = 21
Run Code Online (Sandbox Code Playgroud)
在服务器端,我有一个Spring控制器,使用以下方法:
@RequestMapping("/delete.x")
public @ResponseBody Map<String, Object> delete(HttpServletRequest request, @RequestParam("ids[]") List<Integer> ids) {
Run Code Online (Sandbox Code Playgroud)
当我尝试迭代id的集合时,如下所示:
for (Integer id : ids) {
Run Code Online (Sandbox Code Playgroud)
我得到如下例外:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
Run Code Online (Sandbox Code Playgroud)
Spring是否将ID的类型更改为List <String>?无论我想如何,我如何避免这个问题并将ID作为整数存储在List中?
我有一个(Java)类,有许多实例字段(其中许多是可选的).我希望所有字段(因此类)都是不可变的.所以,我想使用Builder Pattern来构造类的实例.
我可以使用Builder模式配置myBatis来创建类的实例吗?我知道我可以让myBatis返回一张地图并使用该地图在我的代码中构建实例.但是,我正在寻找一种方法来配置这种映射(或使用一些约定),类似于如何通过使用Java Bean和构造函数来创建实例.
编辑(包括一个例子)
这是一个例子:
package com.example.model;
// domain model class with builder
public final class CarFacts {
private final double price;
private final double numDoors;
private final String make;
private final String model;
private final String previousOwner;
private final String description;
public static class Builder {
// required params
private final double price;
private final String make;
private final String model;
// optional params
private final String previousOwner;
private final String description;
private final double numDoors;
public Builder(double …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot 并具有以下组件类:
@Component
@ConfigurationProperties(prefix="file")
public class FileManager {
private Path localDirectory;
public void setLocalDirectory(File localDirectory) {
this.localDirectory = localDirectory.toPath();
}
...
}
Run Code Online (Sandbox Code Playgroud)
以及以下 yaml 属性文件:
file:
localDirectory: /var/data/test
Run Code Online (Sandbox Code Playgroud)
我想通过替换为 java.nio.file.Path 来删除 java.io.File(setLocalDirectory)的引用。但是,执行此操作时收到绑定错误。有没有办法将属性绑定到路径(例如,通过使用注释)?
我有写入数据库的 Spring Batch 作业(它有一个带有 的步骤JpaItemWriter
)。我有一个集成测试,如下所示:
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("integrationTest")
public class LoadApplicationTests {
@Autowired
private Job job;
@Autowired
private JobRepository jobRepository;
@Autowired
private JobLauncher jobLauncher;
private JobLauncherTestUtils jobLauncherTestUtils;
@Before
public void setUp() throws IOException, java.text.ParseException, Exception {
jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(job);
jobRepository = new MapJobRepositoryFactoryBean(new ResourcelessTransactionManager()).getObject();
jobLauncherTestUtils.setJobRepository(jobRepository);
jobLauncherTestUtils.setJobLauncher(jobLauncher);
}
@Test
public void testJob() throws Exception {
JobParametersBuilder j = new JobParametersBuilder();
JobParameters jobParameters = j.addDate("runDate", new Date())
.addString("file", testFile.getAbsolutePath())
.addString("override", "false")
.addString("weekly", "false")
.toJobParameters();
JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobParameters); …
Run Code Online (Sandbox Code Playgroud) spring ×4
spring-boot ×4
kendo-ui ×2
buildship ×1
eclipse ×1
gradle ×1
java ×1
jpa ×1
modal-dialog ×1
mybatis ×1
spring-batch ×1
spring-test ×1
windows ×1