我无法@ControllerAdvice上班.我更新了我的命名空间位置,在我的xml文件中是3.1.我将带有控制器的类移动到与控制器相同的包中.我正在使用3.2.0版本的jar.如果我将@ExceptionHandler注释放在控制器代码中,它可以工作,但不能在一个单独的类中使用@ControllerAdvice.当@ControllerAdvice类失败时,我得到未被捕获的异常处理程序视图.任何人都有关于如何解决这个问题的想法?
我使用相同的表单来添加和编辑值.在添加项目期间,我希望它强制对服务器执行名称检查.但是,在编辑模式期间,我希望它不进行验证,因为名称可能不会更改.我试图根据下面的文档链接将验证器中的ignore属性设置为"ignore"类.我在名称输入中使用相同的类名,但这不起作用.它一直在验证服务器.有什么想法吗?
我正在使用的代码的URL,主要是验证功能.http://jqueryvalidation.org/validate/
根据ignore属性的文档,它指出:
验证时要忽略的元素,只需将其过滤掉即可.使用了jQuery的not-method,因此not()接受的所有内容都可以作为此选项传递.始终忽略提交和重置类型的输入,因此禁用的元素也是如此.
我查看了代码,只能看到它在调用期间影响清理错误validator.resetForm().这部分代码正常工作.
我正在尝试使用Mockito ArgumentCaptor在我的方法中获取mime消息。当我返回捕获对象时,其值为null。我想调试它,但是Mockito用增强器包装了它,所以我看不到内容。这适用于我的方法中的对象。有人有主意吗?
这是我的样本测试。msg不为null,但此后调用该方法将返回null。
@Test
public void testSendTemplatedMail() throws MessagingException, IOException {
Context ctx = new Context();
ctx.setVariable("name", "John Doe");
ctx.setVariable("subscriptionDate", new Date());
ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));
String templateName = "testEmailTemplateWithoutImage";
when(mailSenderMock.createMimeMessage()).thenReturn(mock(MimeMessage.class));
try {
mailUtils.sendTemplatedMail("John Doe", "john.doe@bbc.com",
"no-reply@leanvelocitylabs.com", "Hello",
templateName, ctx);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
ArgumentCaptor<MimeMessage> msg = ArgumentCaptor.forClass(MimeMessage.class);
verify(mailSenderMock, times(1)).createMimeMessage();
verify(mailSenderMock, times(1)).send(msg.capture());
verifyNoMoreInteractions(mailSenderMock);
System.out.println("Sample msg subject = " + msg);
System.out.println("Sample msg ctype = " + msg.getValue().getContentType());
System.out.println("Sample msg to = " + msg.getValue().getAllRecipients());
System.out.println("Sample …Run Code Online (Sandbox Code Playgroud) 我正在使用Hibernate和MySQL在Spring MVC中开发一个应用程序,我遇到了一个问题.我试图使用@PrePersist注释在我的Java实体中填充我最后修改的字段.我调试了代码,方法被调用,值得设置.但是,数据库抛出了null违规,因为它没有写出@PrePersist方法添加的值.有谁知道如何修复此问题将数据写入数据库?
仅供参考,除了更改日期之外,我还想使用这些JPA注释来执行某些业务逻辑或使用类似于注释的内容.
代码:
@Entity
@Table(name = "account")
public class Account {
@Column(name = "modified_on")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(style = "MM")
@NotNull()
private Calendar modifiedOn;
... getters, setter and other stuff
@PrePersist
public void prePersist() {
Calendar now = Calendar.getInstance();
this.createdOn = now;
this.modifiedOn = now;
}
@PreUpdate
public void preUpdate() {
Calendar now = Calendar.getInstance();
this.modifiedOn = now;
}
Run Code Online (Sandbox Code Playgroud)
的applicationContext-的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> …Run Code Online (Sandbox Code Playgroud) spring-mvc ×2
hibernate ×1
java ×1
jquery ×1
junit ×1
mime ×1
mockito ×1
mysql ×1
spring ×1
unit-testing ×1