用户在开发或者调试网络程序或者是网页B/S模式的程序的时候是需要一些方法来跟踪网页请求的,用户可以使用一些网络的监视工具比如著名的Firebug等网页调试工具。今天给大家介绍的这款网页调试工具不仅可以调试简单的css、html、脚本等简单的网页基本信息,它还可以发送几乎所有类型的HTTP请求!Postman在发送网络HTTP请求方面可以说是Chrome插件类产品中的代表产品之一。
postman适用于不同的操作系统,Postman Mac、Windows X32、Windows X64、Linux系统,还支持postman 浏览器扩展程序、postman chrome应用程序等。
在这里postman的安装就不说了
IrrBSRouterController
我这里将浏览地址注解掉了这样就不用去页面登录才可以测试了,我们直接跑下后台让后去postman测就ok了
// @RequiresPermissions("/router/updRouter")
package com.heidou.irrigated.manage.api.controller.irrbs;
import com.heidou.irrigated.annotation.WebLog;
import com.heidou.irrigated.pojo.irrbs.IrrBSRouter;
import com.heidou.irrigated.resultvo.JSONResultVo;
import com.heidou.irrigated.resultvo.ListInfoResult;
import com.heidou.irrigated.service.irrbs.IrrBSRouterService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName: IrrBSRouterController
* @Author: lzx
* @Date: 2020/4/27 15:07
*/
@RestController
@RequestMapping("/router")
public class IrrBSRouterController {
@Autowired
IrrBSRouterService irrBSRouterService;
@GetMapping("/getIrrBSRouter")
public ListInfoResult getIrrBSRouter(){
ListInfoResult list = new ListInfoResult();
list.setInfo(irrBSRouterService.getIrrBSRouter());
return list;
}
/**
* 修改路由
*/
@PostMapping("updRouter")
@WebLog(description = "修改路由")
// @RequiresPermissions("/router/updRouter")
public JSONResultVo updRouter(IrrBSRouter router) {
JSONResultVo vo = JSONResultVo.ok();
irrBSRouterService.updateById(router);
List<IrrBSRouter> list = new ArrayList<>();
if (list!=router){
System.out.print("修改成功");
}
else{
System.out.print("修改失败");
}
return vo;
}
/**
* 增加路由
*
* @param router
* @return
*/
@PostMapping("addRouter")
@WebLog(description = "添加路由")
// @RequiresPermissions("/router/addRouter")
public JSONResultVo addRouter(IrrBSRouter router) {
return irrBSRouterService.addRouter(router);
}
/**
* 删除路由
*/
@PostMapping("delRouter")
@WebLog(description = "删除路由")
// @RequiresPermissions("/router/delRouter")
public JSONResultVo delRouter(@RequestParam Integer id) {
return irrBSRouterService.delRouter(id);
}
}
IrrBSRouterService
package com.heidou.irrigated.service.irrbs;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heidou.irrigated.enums.ResultEnum;
import com.heidou.irrigated.mapper.irrbs.IrrBSResourcesMapper;
import com.heidou.irrigated.pojo.irrbs.IrrBSResources;
import com.heidou.irrigated.pojo.irrbs.IrrBSRouter;
import com.heidou.irrigated.mapper.irrbs.IrrBSRouterMapper;
import com.heidou.irrigated.resultvo.JSONResultVo;
import com.heidou.irrigated.service.BaseServiceImpl;
import com.heidou.irrigated.utils.DateUtils;
import com.heidou.irrigated.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;
import java.util.stream.Collectors;
/**
*
* 前端路由配置表 服务实现类
*
*
* @author zrh,IP:192.168.198.1、192.168.68.1、192.168.8.101
* @since 2020-04-26
*/
@Service
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class IrrBSRouterService extends BaseServiceImpl<IrrBSRouterMapper, IrrBSRouter> {
@Autowired
IrrBSRouterMapper irrBSRouterMapper;
@Autowired
IrrBSResourcesMapper irrBSResourcesMapper;
/**
* 增加路由
*/
@Transactional(rollbackFor = Exception.class)
public JSONResultVo addRouter(IrrBSRouter Router) {
//参数校验
if(Router == null) {
JSONResultVo.setErrorMsg(ResultEnum.PARAM_NULL);
}
if(StringUtil.isBlank(Router.getName())) {
JSONResultVo.setErrorMsg(ResultEnum.PARAM_NULL);
}
Router.setCreateTime(DateUtils.getDate());
irrBSRouterMapper.insert(Router);
return JSONResultVo.ok();
}
/**
* 删除路由
*/
@Transactional(rollbackFor = Exception.class)
public JSONResultVo delRouter(Integer id) {
//此集合存储所有节点的ID
List<Integer> ids = new ArrayList<>();
ids.add(id);
getIds(ids, id);
QueryWrapper<IrrBSResources> qw = new QueryWrapper();
qw.in("router_id", ids);
List<IrrBSResources> irrBSResources = irrBSResourcesMapper.selectList(qw);
//判断所有的节点是否已被关联
if(irrBSResources.size() > 0) {
return JSONResultVo.setErrorMsg(ResultEnum.DATA_ERROR.getValue(),"该节点已被关联");
}
irrBSRouterMapper.deleteBatchIds(ids);
return JSONResultVo.ok();
}
/**
* 递归查询需要删除的路由树
*/
public void getIds(List<Integer> ids, Integer id) {
QueryWrapper<IrrBSRouter> qw = new QueryWrapper();
qw.eq("parent_id", id);
//查询该节点下所有的子节点
List<IrrBSRouter> list = irrBSRouterMapper.selectList(qw);
if(list.size() > 0) {
list.forEach(e -> {
ids.add(e.getId());
getIds(ids, e.getId());
}
);
}
}
/**
* 获取路由树
*
* @return
*/
public List<IrrBSRouter> getIrrBSRouter() {
List<IrrBSRouter> allList = irrBSRouterMapper.selectList(null);
List<IrrBSRouter> rootList = allList.stream().filter(e -> e.getParentId() == 0).collect(Collectors.toList());
setChildrens(rootList, allList, null);
return rootList;
}
/**
* 递归路由树
*
* @param rootList
* @param allList
* @param roleResIdList
*/
public void setChildrens(List<IrrBSRouter> rootList, List<IrrBSRouter> allList, List<Integer> roleResIdList) {
if(rootList != null) {
rootList.forEach(e -> {
List<IrrBSRouter> children = new ArrayList<>();
allList.forEach(c -> {
if(Objects.equals(e.getId(), c.getParentId())) {
// 如果
if(!ObjectUtils.isEmpty(roleResIdList)) {
if(roleResIdList.contains(c.getId())) {
children.add(c);
}
} else {
children.add(c);
}
}
});
if(!ObjectUtils.isEmpty(children)) {
e.setChildren(children);
setChildrens(children, allList, roleResIdList);
}
});
}
}
}
当返回我们需要的JSON格式数据说明这个接口是成功的。后面的修改删除是一样的测试方法,这里就不多说了