解决方法:在形参上前添加注解@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
数据库中的DateTime类型被mybatis逆向工程创建的bean默认是LocalDateTime类型的,
这个时候我们就需要接受LocalDateTime类型的参数
例如下面的代码执行
public String postOurTime(String title ,LocalDateTime time) {
.......................
return "";
}
就会报下面的错误
......Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam java.time.LocalDateTime] for value '2021-11-03 20:53:15';.......
我们只需要在要形参中添加spring的注解@DateTimeFormat
public String postOurTime(String title,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime time) {
.......................
return "";
}