@wendal
function loadMosaicImages() {
$.ajax({
type: "GET",
url: "../dataprocess/loadimages/" + encodeURI(JSON.stringify({basepath: $("#mosaicPath").val()})),
dataType: "text",
processData: true,
beforeSend: function () {
//异步请求时spinner出现
$("#loadlabel").text("");
var target = $("#loadsp").get(0);
spinner.spin(target);
$("#loadImagesBtn").attr("disabled", true);
},
error: function (req, status, error) {
spinner.stop();
$("#loadImagesBtn").removeAttr("disabled");
if (status === "timeout") {
alert("请求超时,请稍后再试!!");
return;
} else if (status === "error") {
alert("数据请求失败,请稍后再试!如果还未解决,请联系管理员!");
return;
}
return;
},
success: function (obj) {
spinner.stop();
$("#loadImagesBtn").removeAttr("disabled");
if (obj.code === 0) {
$("#loadlabel").text("创建成功!");
$("#loadlabel").addClass("label label-success");
var data = obj.data;
$.each(data, function (i, res) {
$("#selList").append("<option id='" + i + "'>" + res + "</option>");
});
} else {
$("#loadlabel").text(obj.message);
$("#loadlabel").addClass("label label-danger");
}
}
});
后台代码
@At("/loadimages/?")
@GET
@POST
@AdaptBy(type = JsonAdaptor.class)
public Object loadImages(MosaicParam param, AdaptorErrorContext errCtx) {
if (errCtx != null || param.getBasepath().isEmpty()) {
MessageWrap<String> messge = new MessageWrap<String>(1, "传入的影像基址参数初始化出错");
return messge;
}
//获取所有影像文件
List<File> files = fileIndexService.indexImageFiles(param.getBasepath());
List<String> filenames = new ArrayList<String>();
for (int i = 0; i < files.size(); i++) {
File image = files.get(i);
filenames.add(image.getName());
}
if (filenames.size() > 0) {
MessageWrap<List<String>> messge = new ResultWrap<List<String>>(filenames, 0, "成功加载影像文件!");
return messge;
}
MessageWrap<List<String>> messge = new ResultWrap<List<String>>(filenames, 1, "加载影像文件数为0!");
return messge;
}