ssm 返回json格式文件_ssm返回jsonp数据格式

packageshopping.controller;importjava.io.File;importjava.io.FileNotFoundException;importjava.io.IOException;importjava.util.List;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.springframework.stereotype.Controller;importorg.springframework.util.ResourceUtils;importorg.springframework.web.bind.annotation.CrossOrigin;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.ResponseBody;importcom.fasterxml.jackson.databind.util.JSONPObject;importshopping.template.ResponseTemplate;importshopping.utils.ReadExcel;

@Controller

@CrossOrigin

@RequestMapping("/shopping")public classMyShopping {@RequestMapping("/get") //通过http响应解决调用public void get(HttpServletRequest req,HttpServletResponse res) throwsFileNotFoundException {

ReadExcel obj= newReadExcel();//此处为我创建Excel路径:E:/zhanhj/studysrc/jxl下//File file = new File(this.getClass().getResource("/")+"test.xlsx");

File file= ResourceUtils.getFile("classpath:test1.xls");

List excelList=obj.readExcel(file);

res.setContentType("text/plain");

String callbackFunName=req.getParameter("callback");//得到js函数名称

try{

res.getWriter().write(callbackFunName+ "([ { data:\"excelList\"}])"); //返回jsonp数据

} catch(IOException e) {

e.printStackTrace();

}

}

@RequestMapping("/getJsonp")

@ResponseBodypublic JSONPObject getJsonp(String callback) throwsFileNotFoundException{

ReadExcel obj= newReadExcel();//此处为我创建Excel路径:E:/zhanhj/studysrc/jxl下//File file = new File(this.getClass().getResource("/")+"test.xlsx");

File file= ResourceUtils.getFile("classpath:test1.xls");

List excelList=obj.readExcel(file);

ResponseTemplate response=new ResponseTemplate(0, "成功", excelList);return newJSONPObject(callback, response);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值