В моем приложении Spring я должен предоставить функцию Сохранить как черновик.Но я не могу сделать частичное представление формы из-за правил проверки сущности.Я хочу проверять форму только тогда, когда нажата кнопка Сохранить окончание, а не при нажатии кнопки Сохранить черновик.Я попытался удалить аннотацию @Valid, но все еще получаю ошибку javax.validation.ConstraintViolationException.
Контроллер:
@PostMapping("/saveSalesDetails")
public String saveSales(Sales sales, @RequestParam("action") String formAction, BindingResult result, Model model) {
if(formAction.equalsIgnoreCase("Save Draft")) {
}
else if (formAction.equalsIgnoreCase("Save Final") {
}
Вот трассировка стека:
Caused by: javax.validation.ConstraintViolationException: Validation failed for classes [mip.salesproj.model.Sales] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='Target Of Sale should be between 5-20 characters', propertyPath=targetSale, rootBeanClass=class mip.salesproj.model.Sales, messageTemplate='Target Of Sale should be between 5-20 characters'}
ConstraintViolationImpl{interpolatedMessage='Target Of Sale field should not be blank', propertyPath=targetSale, rootBeanClass=class mip.salesproj.model.Sales, messageTemplate='Target Of Sale field should not be blank'}
]
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:140)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:80)
at org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:205)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:82)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:600)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:474)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1437)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:494)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3245)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2451)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:473)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:156)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
... 107 common frames omitted