项目说明:本项目是前后端分离项目,后端使用springBoot框架,前端使用vue.js框架
一、后端
1.controller层接口
@ApiImplicitParams({
@ApiImplicitParam(name = "map",
value = "",
required = true, dataType = "map", paramType = "body"),
@ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "Integer", paramType = "query",defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "页大小", required = true, dataType = "Integer", paramType = "query",defaultValue = "5")
})
@PostMapping("/findAllDeviceAndMainBoard")
public RespPageBean findAllDeviceAndMainBoard(@RequestBody Map<String,String> map,Integer page, Integer rows) {
try {
return otherService.findAllDeviceAndMainBoard(map,page,rows);
}catch (Exception ex){
ex.printStackTrace();
}
return null;
}
说明:
RespPageBean是封装好返回前端接收对象,接收参数也是map对象
2.server层
接口:
/** 根据主板编号和机构编号获取所有设备和主板信息 */
RespPageBean findAllDeviceAndMainBoard(Map<String,String> map,Integer page, Integer rows);
实现类:
/** 根据主板编号和机构编号获取所有设备和主板信息 */
@Override
public RespPageBean findAllDeviceAndMainBoard(Map<String,String> map,Integer page, Integer rows) {
try {
PageInfo<Map<String, Object>> pageInfo = PageHelper.startPage(page,rows)
.doSelectPageInfo(new ISelect() {
@Override
public void doSelect() {
otherMapper.findAllDeviceAndMainBoard(map);
}
});
RespPageBean respPageBean = new RespPageBean();
respPageBean.setData(pageInfo.getList());
respPageBean.setTotal(pageInfo.getTotal());
return respPageBean;
}catch (Exception e){
e.printStackTrace();
log.error(e.getMessage());
}
return null;
}
3.Mapper层:
/** 根据主板编号和机构编号获取所有设备和主板信息 */
List<Map<String,Object>> findAllDeviceAndMainBoard(Map<String,String> map);
4.mybatis xml
<!-- 获取所有设备和主板信息 -->
<select id="findAllDeviceAndMainBoard" resultType="java.util.Map" parameterType="java.util.Map">
select d.`id` deviceId, d.`name`,d.`ip`,d.`port`,d.`status`,d.`organize` deviceOrganize,d.`motherboard` deviceHardwareSN,d.`threadId`,d.`lastDeviceJson`,d.`remarks`,
m.*,
(select b.`name` from tb_brand b where id = m.`brand`) brandName ,
(select dept_name from sys_dept where dept_id = d.`organize`) orgName ,
(select count(id) from tb_nozzle n where n.`motherboard` = m.`motherboard` and n.`organize` = m.`organize`) nozzleCount,
(select count(id) from tb_meter me where me.`motherboard` = m.`motherboard` and me.`organize` = m.`organize`) meterCount,
(select count(id) from tb_display dis where dis.`motherboard` = m.`motherboard` and dis.`organize` = m.`organize`) displayCount,
(select count(id) from tb_fuelingpoint fue where fue.`hardwareSN` = m.`motherboard` and fue.`organize` = m.`organize`) fuelingPointCount
from tb_device d left join tb_mainboard m
on d.`motherboard` = m.`motherboard` and d.`organize` = m.`organize`
<where>
1 = 1
<!-- 设备id -->
<if test="motherboard!= null and motherboard!=''">
and m.`motherboard` = #{motherboard}
</if>
<!-- 所属机构 -->
<if test="organize != null and organize !=''">
and m.`organize` = #{organize}
</if>
<!-- 厂家品牌 -->
<if test="brand != null and brand !=''">
and m.`brand` = #{brand}
</if>
</where>
order by id asc
</select>
注意:返回结果是resultType而不是填resultMap,parameterType是参数类型。
二、前端:
async getDeviceList(motherboard,deptId,brand){
//先判断deptId是否为空,如果为空则设置其默认值为查看当前站id
if (deptId == '' || deptId == null || deptId == undefined){
deptId = ''
}
let url = '/other/findAllDeviceAndMainBoard?page=' + this.page + '&rows=' + this.size;
const params = {"motherboard":motherboard,"organize":deptId,"brand":brand};
this.postRequest(url,params).then(res =>{
this.deviceList = res.data;
this.total = res.total;
})
},