Class.java.LocalDateTime非public或不允许实例化
Class.java.LocalDateTime non public or does not allow instantiation
我有这个 DTO:
@XmlAccessorType(XmlAccessType.FIELD)
public class dateDTO{
private LocalDateTime date;
public LocalDateTime getDate() {
return date;
}
public void setDate(LocalDateTime date) {
this.date = date;
}
}
我在这个请求中使用它class:
@XmlAccessorType(XmlAccessType.FIELD)
public class testRequest {
private dateDTO dDTO;
public dateDTO getdDTO() {
return dDTO;
}
public void setdDTO(dateDTO dDTO) {
this.dDTO = dDTO;
}
}
所以我尝试实现一个使用请求 class:
的网络方法
public testResponse testMethod(testRequest theRequest) {
return null;
}
testMethod 有这个接口:
@WebMethod(operationName="test")
@WebResult(name="testResponse")
testResponse testMethod(@WebParam(name = "testRequest") testRequest req);
但我在设计时已经收到此消息:
Web method problem:Class.java.LocalDateTime non public or does not allow instantiation
有什么建议吗?
提前致谢。
也许你可以试试适配器。像这样:
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
public String marshal(LocalDateTime val) throws Exception {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return val.format(formatter);
}
public LocalDateTime unmarshal(String val) throws Exception {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return LocalDateTime.parse(val, formatter);
}
}
然后声明在你的DTO中使用它:
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
private LocalDateTime date;
在此示例中,我假设您使用模式 "yyyy-MM-dd HH:mm"
作为参考,但显然您可以更改模式以满足您的需要。
我有这个 DTO:
@XmlAccessorType(XmlAccessType.FIELD)
public class dateDTO{
private LocalDateTime date;
public LocalDateTime getDate() {
return date;
}
public void setDate(LocalDateTime date) {
this.date = date;
}
}
我在这个请求中使用它class:
@XmlAccessorType(XmlAccessType.FIELD)
public class testRequest {
private dateDTO dDTO;
public dateDTO getdDTO() {
return dDTO;
}
public void setdDTO(dateDTO dDTO) {
this.dDTO = dDTO;
}
}
所以我尝试实现一个使用请求 class:
的网络方法 public testResponse testMethod(testRequest theRequest) {
return null;
}
testMethod 有这个接口:
@WebMethod(operationName="test")
@WebResult(name="testResponse")
testResponse testMethod(@WebParam(name = "testRequest") testRequest req);
但我在设计时已经收到此消息:
Web method problem:Class.java.LocalDateTime non public or does not allow instantiation
有什么建议吗?
提前致谢。
也许你可以试试适配器。像这样:
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
public String marshal(LocalDateTime val) throws Exception {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return val.format(formatter);
}
public LocalDateTime unmarshal(String val) throws Exception {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return LocalDateTime.parse(val, formatter);
}
}
然后声明在你的DTO中使用它:
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
private LocalDateTime date;
在此示例中,我假设您使用模式 "yyyy-MM-dd HH:mm"
作为参考,但显然您可以更改模式以满足您的需要。