【发布时间】:2014-02-14 08:41:58
【问题描述】:
我正在对我的 Spring 控制器进行 ajax 调用,以从 blob 对象获取数据。我将 blob 转换为字符串,并尝试返回它。如果我不使用@ResponseBody 注解,会出现404 错误,但使用注解解决了这个问题。我尝试在ajax 代码中指定不同的数据类型,但没有任何效果。 有人可以向我解释这种行为吗?还有关于以更好的方式传回 blob 数据的任何建议吗?
@RequestMapping(value = "/BlobData", method = RequestMethod.GET)
public @ResponseBody String genBlobData(int Id) throws SQLException {
Blob blob = daoImpl.getBlob(Id);
byte[] content = blob.getBytes(1, (int) blob.length());
String temp = new String(content);
return temp;
}
还有 ajax :
$.ajax({
type: 'GET',
dataType: "text",
url: 'BlobData',
data: {Id:Id},
success: function(data)
{
var newWindow = window.open();newWindow.document.write(data);
/* alert(data); */
}
});
谢谢
【问题讨论】:
标签: ajax spring spring-mvc