使用axios发请求
接口
package com.niu.sxs.controller;
import com.niu.config.Code;
import com.niu.config.Result;
import com.niu.sxs.domain.LeeSxsBasic;
import com.niu.sxs.domain.LeeYqsbBasic;
import com.niu.sxs.domain.vo.LeeYqsbBasicVo;
import com.niu.sxs.domain.vo.SxsAndSblb;
import com.niu.sxs.service.LeeSxsBasicService;
import com.niu.sxs.service.LeeYqsbBasicService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* 仪器设备controller
*/
@CrossOrigin
@RestController
@RequestMapping("/leeYqsbBasic")
public class LeeYqsbBasicController {
@Autowired
private LeeYqsbBasicService leeYqsbBasicService;
@Autowired
private LeeSxsBasicService leeSxsBasicService;
private static final Logger logger = LoggerFactory.getLogger(LeeSxsDjController.class);
/**
* 查询所有仪器设备
*
* @return
*/
@GetMapping
public Result getAll() {
List<LeeYqsbBasic> leeYqsbBasicList = leeYqsbBasicService.getAll();
Integer code = leeYqsbBasicList != null ? Code.GET_OK : Code.GET_ERR;
String msg = leeYqsbBasicList != null ? "" : "数据查询失败,请重试!";
return new Result(code, leeYqsbBasicList, msg);
}
/**
* 根据条件查询仪器设备
*
* @param leeYqsbBasicVo
* @return
*/
@PostMapping("/getByCondition")
public Result getByCondition(@RequestBody LeeYqsbBasicVo leeYqsbBasicVo) {
List<LeeYqsbBasic> leeYqsbBasicList = leeYqsbBasicService.getByCondition(leeYqsbBasicVo);
Integer code = leeYqsbBasicList != null ? Code.GET_OK : Code.GET_ERR;
String msg = leeYqsbBasicList != null ? "" : "数据查询失败,请重试!";
return new Result(code, leeYqsbBasicList, msg);
}
/**
* 根据条件查询仪器设备
*
* @param leeYqsbBasicVo
* @return
*/
@PostMapping("/getByCondition2")
public Result getByCondition2(@RequestBody LeeYqsbBasicVo leeYqsbBasicVo) {
logger.info("接收到请求leeYqsbBasicVo = {}", leeYqsbBasicVo.toString());
List<SxsAndSblb> sxsAndSblbList = new ArrayList<SxsAndSblb>();
List<LeeSxsBasic> leeSxsBasicList = leeSxsBasicService.getAll();//查询所有存在大型仪器的实训室
for (LeeSxsBasic sxs : leeSxsBasicList) {//遍历实训室
SxsAndSblb sxsAndSblb = new SxsAndSblb();
sxsAndSblb.setSxsdd(sxs.getFdd());//设置实训室地点
sxsAndSblb.setSxsid(sxs.getFsid());//设置实训室id
leeYqsbBasicVo.setLccb_szsxsid(sxs.getFsid());
List<LeeYqsbBasic> sbList = leeYqsbBasicService.getByCondition(leeYqsbBasicVo);//查询该实训室仪器
sbList = leeYqsbBasicService.getSbList(sbList);//加使用情况
sxsAndSblb.setSbList(sbList);//设置实训室仪器
sxsAndSblbList.add(sxsAndSblb);
}
Integer code = sxsAndSblbList != null ? Code.GET_OK : Code.GET_ERR;
String msg = sxsAndSblbList != null ? "" : "数据查询失败,请重试!";
return new Result(code, sxsAndSblbList, msg);
}
/**
* 根据id查询仪器设备
*/
@GetMapping("/getById")
public Result getById(@RequestParam String fsid) {
LeeYqsbBasic leeYqsbBasic = leeYqsbBasicService.getById(fsid);
Integer code = leeYqsbBasic != null ? Code.GET_OK : Code.GET_ERR;
String msg = leeYqsbBasic != null ? "" : "数据查询失败,请重试!";
return new Result(code, leeYqsbBasic, msg);
}
}
vue2项目使用axios发请求
get(){
var that = this;//保存this的引用
axios({
method: 'get',
url: baseUrl+'/leeYqsbBasic/getById',
params: {fsid: "0025ee620b1b4aa6b60514a33719dc1f"},
}).then(function (resp) {
that.form = resp.data.data;
});
}