我正在尝试参考另一个表使用复合主键。我看到了很多主题,但没有答案适合我。
在我的数据库中,owner_id未添加由外键正确创建的列。因此,即使员工不存在,我也可以添加新记录。我SQLLite用作数据库
A类:
@Column(name = "filename", unique = true)
private String filename;
@EmbeddedId
private TimeSheetID id;
@MapsId("owner_id")
@JoinColumn(name = "owner_id", referencedColumnName = "employee_id")
@ManyToOne
private EmployeeeEntity employee;
Run Code Online (Sandbox Code Playgroud)
B级
public class TimeSheetID implements Serializable{
private static final long serialVersionUID = 7469844076039968866L;
@Column(nullable = false, name = "period")
private String period;
@Column(nullable = false, name = "owner_id")
private String ownerId;
// …
}
Run Code Online (Sandbox Code Playgroud)
C级
@Column(nullable = false)
public String getName() {
return name;
}
@Id
@Column(name = "employee_id") …Run Code Online (Sandbox Code Playgroud) 我正在实施 2 个 ControllersAdvice。处理异常 CommonAdvice 和 UserAdvice
常见建议
@ControllerAdvice(annotations = RestController.class)
public class CommonAdvice {
@ExceptionHandler(Exception.class)
public ResponseEntity<ExceptionBean> handleException(Exception e) {
ExceptionBean exception = new ExceptionBean(Causes.ANOTHER_CAUSE);
return new ResponseEntity<ExceptionBean>(exception, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Run Code Online (Sandbox Code Playgroud)
用户建议
@ControllerAdvice(assignableTypes = { requestUserMapper.class })
public class UserAdvice {
@ExceptionHandler(NotUniqueUserLoginException.class)
public ResponseEntity<ExceptionBean> handleAlreadyFound(NotUniqueUserLoginException e) {
System.out.println("this is me : " + Causes.USER_ALREADY_EXIST.toString());
ExceptionBean exception = new ExceptionBean(Causes.USER_ALREADY_EXIST);
return new ResponseEntity<ExceptionBean>(exception, HttpStatus.INTERNAL_SERVER_ERROR);
}
Run Code Online (Sandbox Code Playgroud)
现在,当我抛出 NotUniqueUserException 时,这是一个处理异常的 CommonAdvice。
我测试过,UserAdvice 工作正常。有办法设置这个类的优先级吗?
@Edit - 添加控制映射
@RequestMapping(value = "add", method = RequestMethod.POST) …Run Code Online (Sandbox Code Playgroud) 我无法在IntelliJ中使用thymeleaf启动基于Spring Boot的应用程序.我在maven中有我的项目,当我从命令行启动时:
java -jar myProject.war
一切正常.但是当我在IDE中配置运行应用程序时,我有以下错误:
[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-25 19:00:24.881 WARN 4663 --- [ main] org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][main] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.
2017-02-25 19:00:25.017 WARN 4663 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewResolver' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$Thymeleaf3Configuration$Thymeleaf3ViewResolverConfiguration': Unsatisfied dependency expressed through constructor parameter 1; …Run Code Online (Sandbox Code Playgroud) 有可能从Node获取Controller实例吗?例如Tab上的AnchorPane?
我有一些AnchorPanes,我加载不同的控制器,我想验证哪个控制器已经加载
我想将此材料添加到我在 Springboot +thymeleaf https://getmdl.io 的项目中 我已将 material.min.css 复制到 resources/static/css 和 material.min.js 到 /resources/static 脚本。
在administration.html 中添加:
<link rel="stylesheet" th:href="@{css/material.min.css}"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript" />
<script src="scripts/material.min.js" th:src="@{scripts/material.min.js}" type="text/javascript"/>
Run Code Online (Sandbox Code Playgroud)
但是当我使用输入类型 par 示例时,UI 没有动画。我该怎么做才有效。或者有另一种与百里香一起使用的好材料?