JSONP与JSONPObject结合解决ajax跨域

package com.jeeplus.modules.app.tjcclz.com.sales.performance.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jeeplus.common.json.ResultBean;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.app.tjcclz.com.sales.performance.entity.Performance;
import com.jeeplus.modules.app.tjcclz.com.sales.performance.service.PerformanceService;

/**
 * @JSONPObject使用例子
 *  注释里的为前台调用例子
 *  function jsonpCallBack(){
 *      
 *  }
 * 
 *  $.ajax({  
 *      url:'http://192.168.11.43:8080/BI/a/sales/performance/getDirectConsultNewByWkNo',  
 *      type: "get",  
 *      dataType: "jsonp",  
 *      data:{"wkNo":userid,"callback":"jsonCallBack"},
 *      success: function(json) {  
 *          console.log(json);
 *      },  
 *      error: function(){
 *          console.log('Error');
 *      }  
 *  });  
 * @注意 JSONPObject 引用的是com.fasterxml.jackson.databind.util.JSONPObject包
 * 
 * @author liuxudong
 * @version 2018-01-15
 */
@Controller
@RequestMapping(value = "${adminPath}/sales/performance")
public class PerformanceController extends BaseController {

    @Autowired
    private PerformanceService performanceService;

    /**
     * 当月直接新开
     * @param performance
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getDirectConsultNewByWkNo")
    public JSONPObject getDirectConsultNewByWkNo(Performance performance, String callback) {
        ResultBean<Performance> entity = null;
        try {
            entity = new ResultBean<Performance>(performanceService.getDirectConsultNewByWkNo(performance));
        } catch (Throwable e) {
            entity = new ResultBean<Performance>(e);
        }
        entity.setInfo("当月自动或手动入BOSS的、创建人和收费人一样的、账务明细当前状态在0到199之间的新开咨询单");//公式解释
        return new JSONPObject(callback, entity);
    }   
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值