前端代码:
function generateReport() { var params = {}; var temp = $('#transaction_statistics_market').combobox('getValue').trim(); if(temp != -1){ params.marketId = temp; } params.type = $('#transaction_stats_type').combobox('getValue').trim(); params.startTime = $('#transaction-stats-datefrom').datebox('getValue').trim(); params.endTime = $('#transaction-stats-dateto').datebox('getValue').trim(); $.ajax({ 'url': 'api/generate_report?' + $.param(params),//发送参数 method: "get", dataType: "json", success: function (res) { if (res.data != null) { window.location = "/CSV/" + res.data; } } }); }
后台代码:@Controller @RequestMapping(value = "/api") public class OrderStatisticsByDayController extends BaseController { @Autowired private OrderStatisticsByDayService orderStatisticsByDayService; @RequestMapping(value = "/generate_report", method = RequestMethod.GET) @ResponseBody public ResponseTO generateReport(@RequestParam(required = false) Long marketId, //接收参数 @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) Integer type) { return success(orderStatisticsByDayService.generateReport( marketId, startTime, endTime, type)); } }