【发布时间】:2014-10-28 21:26:12
【问题描述】:
如果我将变量 firstDT 从 Timestamp 更改为 String,然后在 get 和 set 方法中从 Timestamp 转换为 String 或反之,我知道如何使下面的代码运行。我想知道是否可以使下面的模型与 Timestamp 变量一起使用。
//Client:
HttpPost postRequest = new HttpPost("http://localhost:8080/my_app/log/Mas60010");
ObjectMapper mapper = new ObjectMapper();
String json = "";
Map<String, String> map = new HashMap<String, String>();
map.put("subCd", "A");
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
map.put("firstDT", "/Date(" + format.format(new Date()) + ")/");
map.put("messageFormat", "AFMAMXAS2CAPCISIMFMDSQSTSTRVIS");
json = mapper.writeValueAsString(map);
StringEntity input = new StringEntity(json);
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
//Rest Web Service:
@RequestMapping(value="Mas60010", method=RequestMethod.POST)
@ResponseBody
public String getFirst(@RequestBody Mas60010 mas60010) {
return "I only reach here if firstDT is String ";
}
//Model
import java.sql.Timestamp;
public class Mas60010 {
private String subCd;
private Timestamp firstDT; // the doubt root is here
private String messageFormat;
public String getSubCd() {
return subCd;
}
public void setSubCd(String subCd) {
this.subCd = subCd;
}
public Timestamp getFirstDT() {
return firstDT;
}
public void setFirstDT(Timestamp firstDT) {
this.firstDT = firstDT;
}
public String getMessageFormat() {
return messageFormat;
}
public void setMessageFormat(String messageFormat) {
this.messageFormat = messageFormat;
}
@Override
public String toString() {
return "ok";
}
}
【问题讨论】:
-
嗨,我还在寻找这个问题的答案。
-
没人能帮我解决这个问题吗?
-
嗨..你找到解决方案了吗..我也面临同样的问题。你的解决方案会帮助我。请分享..