当我试图从我的thymeleaf html表单中保存一个Date输入到控制器时,我收到一条错误消息。它似乎是作为字符串从表单中发送的,但我希望它作为Date发送。我设置了输入类型=date,所以我不确定它为什么出错。这是错误:
Validation failed for object='card'. Error count: 1
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'card' on field 'expirationDate': rejected value [2021-12-12]; codes [typeMismatch.card.expirationDate,typeMismatch.expirationDate,typeMismatch.java.util.Date,typeMismatch];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [card.expirationDate,expirationDate];
arguments []; default message [expirationDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'expirationDate';
nested exception is org.springframework.core.convert.ConversionFailedException:
Failed to convert from type [java.lang.String] to type [@javax.persistence.Temporal @javax.persistence.Column java.util.Date] for value '2021-12-12'; nested exception is java.lang.IllegalArgumentException]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:170)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:170)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
下面是该部分的html代码,expirationDate是我发送回控制器的卡对象的一个属性:
<div class="col-12 mb-2">
<label for="exp" id="expLabel"><strong>Expiration date:</strong></label>
<input type="date" class="form-control" id="exp"
name="exp" value="2022-01-01" th:field="*{expirationDate}">
</div>
这是控制器。获取日期值并在表单中预先填写可以很好地工作,但由于某种原因,当我提交表单时,它抛出了该错误:
@PostMapping(value={"/editprofile", "editprofile.html"})
public String editUser(@ModelAttribute("user") User user,
@ModelAttribute("card") PaymentCard card,
@ModelAttribute("address") Address address) {
// process and validate form data -- similar to createAccount process
userRepo.save(user);
//cardRepo.save(card); // even with this line commented, there is the error.
addressRepo.save(address);
return "redirect:/editprofile";
}
以下是POJO定义的第一部分:
@Entity
@Table(name = "payment_card", catalog = "bookstore")
public class PaymentCard implements java.io.Serializable {
@Id
@Column(name = "PaymentCardID", unique = true, nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int paymentCardId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "UserID")
private User user;
@Column(name = "cardNumber", nullable = false)
private String cardNumber; // int and long aren't big enough to hold 16 digits
@Column(name = "cardType", nullable = false, length = 20)
private String cardType;
@Temporal(TemporalType.DATE)
@Column(name = "expirationDate", nullable = false, length = 10)
private Date expirationDate;
我有以下标签,它们工作得很好 它们位于form:form标签中。页面加载良好。 有什么想法吗?谢谢
我有 PS:即使我在表单标记中使用modelattribute=“fivt”也是一样的
我试图从数据库表中获取在字段创建的
我试图通过一个表单向数据库添加一个表。正在创建的实体称为相册,它有2个字段,艺术家和流派。这两者都是独立的实体。这两个字段用@ManyToOne进行了注释 当我提交表单时,这是我得到的错误: 以下代码是我的控制器的一部分: 下面的代码是百里香模板的一部分: 是什么导致了这个错误?
我转换我的日期从服务器yyyyy-mm-dd hh: mm: ss到dd-mm-yyyy hh: mm: ss am/pm 我写了以下代码来做这件事... 除了控制台日志06:21:48 am、06:09:44 am和其他几个显示am而不是PM之外,其他一切都正常工作。 我的代码错了吗?或者有什么虫子?
我试图在配置单元中执行select*from db.abc操作,此配置单元表是使用spark加载的 “它不工作”显示错误: 错误:java.io.IOException:java.lang.IllegalArgumentException:bucketId超出范围:-1(状态=,代码=0) 我需要在spark-submit或shell中添加任何属性吗?或者使用spark读取此hiv e表的另一种方