Apifox 是 API 文档、API 调试、API Mock、API 自动化测试一体化协作平台,定位 Postman + Swagger + Mock + JMeter,由此可见apifox集功能于一身,极大的提升了我们开发的效率,不用再为postman网络连接失败而发愁,更不用为swagger各种依赖冲突二苦恼
Apifox - API 文档、调试、Mock、测试一体化协作平台 - 接口文档工具,接口自动化测试工具,接口Mock工具,API文档工具,API Mock工具,API自动化测试工具
如:java-wtl-single:3398260,月木学途
java-wtl-single是项目的模块,一般就是分布式模块,如:
3398260就是你的id
月木学途对应你的apifox的接口目录
代码站位
- package jkw.controller.back;
-
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import jkw.pojo.Admin;
- import jkw.service.AdminService;
- import jkw.vo.BaseResult;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.security.core.Authentication;
- import org.springframework.security.core.context.SecurityContext;
- import org.springframework.security.core.context.SecurityContextHolder;
- import org.springframework.security.core.userdetails.UserDetails;
- import org.springframework.security.crypto.password.PasswordEncoder;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.*;
-
- /**
- * back后台用户
- */
- @RestController
- @RequestMapping("/sys/admin")
- @CrossOrigin
- public class AdminController {
- @Autowired
- private AdminService adminService;
- @Autowired
- private PasswordEncoder encoder;
-
- /**
- * 新增管理员
- *
- * @param admin 管理员
- * @return
- */
- @PostMapping("/add")
- @PreAuthorize("hasAnyAuthority('/sys/admin')")
- public BaseResult add(Admin admin) {
- String password = admin.getPassword();
- password = encoder.encode(password);
- admin.setPassword(password);
- adminService.add(admin);
- return BaseResult.ok();
- }
-
- /**
- * 修改管理员(设置空密码则还是原来密码)
- *
- * @param admin 管理员
- * @return
- */
- @PostMapping("/update")
- public BaseResult update(Admin admin) {
- String password = admin.getPassword();
- if (StringUtils.hasText(password)) { // 密码不为空加密
- password = encoder.encode(password);
- admin.setPassword(password);
- }
- adminService.update(admin);
- return BaseResult.ok();
- }
-
- /**
- * 删除管理员(附带对应的角色)
- *
- * @param aid 管理员id
- * @return
- */
- @DeleteMapping("/delete")
- public BaseResult delete(Integer aid) {
- adminService.delete(aid);
- return BaseResult.ok();
- }
-
- /**
- * 修改管理员的状态
- *
- * @param aid 管理员id
- * @return
- */
- @PostMapping("/updateStatus")
- public BaseResult updateStatus(Integer aid) {
- adminService.updateStatus(aid);
- return BaseResult.ok();
- }
-
- /**
- * 根据id查询管理员(详情)
- *
- * @param aid 管理员id
- * @return
- */
- @GetMapping("/findById")
- public BaseResult<Admin> findById(Integer aid) {
- Admin admin = adminService.findById(aid);
- return BaseResult.ok(admin);
- }
-
- /**
- * 分页查询管理员
- *
- * @param page 当前页
- * @param size 每页条数
- * @return
- */
- @PreAuthorize("hasAnyAuthority('/sys/admin')")
- @GetMapping("/search")
- public BaseResult<Page<Admin>> search(int page, int size) {
- Page<Admin> adminPage = adminService.search(page, size);
- return BaseResult.ok(adminPage);
- }
-
- /**
- * 修改管理员角色
- *
- * @param aid 管理员id
- * @param rids 角色id
- * @return
- */
- @PostMapping("/updateRoleToAdmin")
- public BaseResult updateRoleToAdmin(Integer aid, Integer[] rids) {
- adminService.updateRoleToAdmin(aid, rids);
- return BaseResult.ok();
- }
-
- /**
- * 获取登录管理员名
- *
- * @return 管理员名
- */
- @GetMapping("/getUsername")
- public BaseResult<String> getUsername() {
- // 1.获取会话对象
- SecurityContext context = SecurityContextHolder.getContext();
- // 2.获取认证对象
- Authentication authentication = context.getAuthentication();
- // 3.获取登录用户信息
- UserDetails userDetails = (UserDetails) authentication.getPrincipal();
- String username = userDetails.getUsername();
- return BaseResult.ok(username);
- }
-
- @GetMapping("/findByUsername")
- public BaseResult findByUsername(String username) {
- Admin admin = adminService.findByName(username);
- return BaseResult.ok(admin);
- }
- }
- package jkw.service.impl;
-
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import jkw.mapper.GoodsSpecificationMapper;
- import jkw.mapper.GoodsSpecificationOptionMapper;
- import jkw.mapper.GoodsSpecificationOptionsMapper;
- import jkw.pojo.GoodsSpecification;
- import jkw.pojo.GoodsSpecificationOption;
- import jkw.pojo.GoodsSpecificationOptions;
- import jkw.service.GoodsSpecificationService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
-
- import java.util.List;
-
- @Service
- @Transactional
- public class GoodsSpecificationServiceImpl implements GoodsSpecificationService {
- @Autowired
- private GoodsSpecificationMapper goodsSpecificationMapper;
-
- @Autowired
- private GoodsSpecificationOptionMapper goodsSpecificationOptionMapper;
- @Autowired
- private GoodsSpecificationOptionsMapper goodsSpecificationOptionsMapper;
-
- @Override
- public void add(GoodsSpecification goodsSpecification) {
- goodsSpecificationMapper.insert(goodsSpecification);
- }
-
- @Override
- public void update(GoodsSpecification goodsSpecification) {
- goodsSpecificationMapper.updateById(goodsSpecification);
- }
-
- @Override
- public void delete(Integer id) {
- //删除商品规格的所有规格项
- QueryWrapper<GoodsSpecificationOption> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("goodsSpecificationId", id);
- goodsSpecificationOptionMapper.delete(queryWrapper);
- //删除商品-规格项的数据
- List<GoodsSpecificationOption> goodsSpecificationOptionList = goodsSpecificationOptionMapper.selectList(queryWrapper);
- for (GoodsSpecificationOption goodsSpecificationOption : goodsSpecificationOptionList) {
- QueryWrapper<GoodsSpecificationOptions> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("goodsSpecificationOptionId", goodsSpecificationOption.getGoodsSpecificationId());
- goodsSpecificationOptionsMapper.delete(queryWrapper1);
- }
-
- //删除商品规格
- goodsSpecificationMapper.deleteById(id);
- }
-
- @Override
- public GoodsSpecification findById(Integer id) {
- return goodsSpecificationMapper.selectById(id);
- }
-
- @Override
- public Page<GoodsSpecification> search(int page, int size) {
- return goodsSpecificationMapper.selectPage(new Page<>(page, size), null);
- }
-
- @Override
- public List<GoodsSpecification> findAll() {
- return goodsSpecificationMapper.selectList(null);
- }
-
- @Override
- public List<GoodsSpecification> findAllByGoodsTypeId(Integer id) {
- QueryWrapper<GoodsSpecification> queryWrapper=new QueryWrapper<>();
- queryWrapper.eq("goodsTypeId",id);
- return goodsSpecificationMapper.selectList(queryWrapper);
- }
- }