• SpringMVC中JSONP的基本使用


     1 @RequestMapping("/check/{param}/{type}")
     2     @ResponseBody
     3     public Object checkData(@PathVariable String param, @PathVariable Integer type, String callback) {
     4 
     5         TaotaoResult result = null;
     6 
     7         // 参数有效性校验
     8         if (StringUtils.isBlank(param)) {
     9             result = TaotaoResult.build(400, "校验内容不能为空");
    10         }
    11         if (type == null) {
    12             result = TaotaoResult.build(400, "校验内容类型不能为空");
    13         }
    14         if (type != 1 && type != 2 && type != 3) {
    15             result = TaotaoResult.build(400, "校验内容类型错误");
    16         }
    17         // 校验出错
    18         if (null != result) {
    19             if (null != callback) {
    20                 JSONPObject jsonpObject = new JSONPObject(callback, result);
    21                 return jsonpObject;
    22             } else {
    23                 return result;
    24             }
    25         }
    26         // 调用服务
    27         try {
    28             result = userService.checkData(param, type);
    29 
    30         } catch (Exception e) {
    31             result = TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
    32         }
    33 
    34         if (null != callback) {
    35             JSONPObject jsonpObject = new JSONPObject(callback, result);
    36             return jsonpObject;
    37 //            MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(result);
    38         //    mappingJacksonValue.setJsonpFunction(callback);
    39 //            mappingJacksonValue.setValue(callback);
    40 //            return mappingJacksonValue;
    41         } else {
    42             return result;
    43         }
    44     }
  • 相关阅读:
    ubuntu: no module named _sqlite
    mysql慢查询分析工具 pt-query-digest
    vue中的时间修饰符stop,self
    面试题 —— Ajax的基本原理总结
    es6笔记 day6-Symbol & generator
    类(class)和继承
    es6笔记 day4---模块化
    es6笔记 day3---Promise
    es6笔记 day3---对象简介语法以及对象新增
    es6笔记 day3---数组新增东西
  • 原文地址:https://www.cnblogs.com/116970u/p/10425346.html
Copyright © 2020-2023  润新知