Module代码
@At("/upd")
@Ok("json")
@Fail("json")
@AdaptBy(type = UploadAdaptor.class, args = {"${app.root}/WEB-INF/tmp"})
public Object upd(@Param("..") Sku sc, @Param("inputFile") File img,
@Param("more") String more, HttpServletRequest req) throws IOException {
log.debug("Input params - sc: \n" + sc);
log.debug("Input params - image file is uploaded: " + Boolean.valueOf(null != img));
log.debug("Input params - more: " + more);
NutMap re = new NutMap();
if (sc.getId() <= 0) {
throw new AppRuntimeException("木有找到你要更新的产品。。。");
}
sc.setGimg(img);
sc.setMoreList(SkuMoreHelper.convert2ListWhenUpdate(more));
String path = req.getSession().getServletContext().getRealPath(GIMG_RELATIVE_PATH);
try {
skuService.updateWithMore(sc, path);
} catch (AppRuntimeException e) {
return re.setv("ok", false).setv("msg", e.getMessage());
}
return re.setv("ok", false).setv("msg", "lalalalld");
// return re.setv("ok", true);
}
上传文件时页面正常,chrome console打印返回内容如下
Object {ok: false, msg: "lalalalld"}
上传文件时页面异常,chrome console打印返回内容如下
Resource interpreted as Document but transferred with MIME type application/json: "http://localhost:8080/g/stock/sku/upd.io".
<pre style="word-wrap: break-word; white-space: pre-wrap;">{"ok":false,"msg":"lalalalld"}</pre>