SpringMVC中JSONP的基本使用

 @RequestMapping("/check/{param}/{type}")
@ResponseBody
public Object checkData(@PathVariable String param, @PathVariable Integer type, String callback) { TaotaoResult result = null; // 参数有效性校验
if (StringUtils.isBlank(param)) {
result = TaotaoResult.build(400, "校验内容不能为空");
}
if (type == null) {
result = TaotaoResult.build(400, "校验内容类型不能为空");
}
if (type != 1 && type != 2 && type != 3) {
result = TaotaoResult.build(400, "校验内容类型错误");
}
// 校验出错
if (null != result) {
if (null != callback) {
JSONPObject jsonpObject = new JSONPObject(callback, result);
return jsonpObject;
} else {
return result;
}
}
// 调用服务
try {
result = userService.checkData(param, type); } catch (Exception e) {
result = TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
} if (null != callback) {
JSONPObject jsonpObject = new JSONPObject(callback, result);
return jsonpObject;
// MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(result);
// mappingJacksonValue.setJsonpFunction(callback);
// mappingJacksonValue.setValue(callback);
// return mappingJacksonValue;
} else {
return result;
}
}
上一篇:Tamper Data 安装与使用


下一篇:CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25