springboot查询全部部门流程分析,
分享于 点击 20017 次 点评:172
springboot查询全部部门流程分析,
前端发送请求后,会请求DeptController
的方法list()
。
package com.intelligent_learning_aid_system.controller; import com.intelligent_learning_aid_system.pojo.Dept; import com.intelligent_learning_aid_system.pojo.Result; import com.intelligent_learning_aid_system.service.DeptService; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; /** * 部门管理Controller */ @Slf4j @RestController public class DeptController { @Autowired private DeptService deptService; // @RequestMapping(value = "/depts", method = RequestMethod.GET) // 指定请求参数为 GET @GetMapping("/depts") // 等同于上面的写法 public Result list() { // System.out.println("查询全部部门数据"); log.info("查询全部部门数据"); // 调用service查询部门数据 List<Dept> deptList = deptService.list(); return Result.success(deptList); } }
在list()
中调用DeptService
获取数据。
在DeptService
中调用DeptMapper
接口中的方法来查询全部的部门信息。
package com.intelligent_learning_aid_system.service; import com.intelligent_learning_aid_system.pojo.Dept; import java.util.List; /** * 部门管理 */ public interface DeptService { /** * 查询全部部门 * @return */ List<Dept> list(); }
package com.intelligent_learning_aid_system.service.impl; import com.intelligent_learning_aid_system.mapper.DeptMapper; import com.intelligent_learning_aid_system.pojo.Dept; import com.intelligent_learning_aid_system.service.DeptService; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.Select; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Slf4j @Service public class DeptServiceImpl implements DeptService { @Autowired private DeptMapper deptMapper; /** * 查询全部部门 */ public List<Dept> list() { return deptMapper.list(); } }
DeptMapper
接口会往数据库发送SQL语句,查询全部的部门,并且把查询的信息封装到List<Dept>
集合中。
package com.intelligent_learning_aid_system.mapper; import com.intelligent_learning_aid_system.pojo.Dept; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import org.springframework.web.bind.annotation.GetMapping; import java.util.List; /** * 部门管理 */ @Mapper public interface DeptMapper { /** * 查询全部部门 * @return */ @Select("select * from dept") List<Dept> list(); }
最终将集合数据返回给DeptService
,DeptService
又返回给DeptController
。DeptController
拿到数据再返回给前端。
到此这篇关于springboot查询全部部门流程的文章就介绍到这了,更多相关springboot查询全部部门内容请搜索3672js教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持3672js教程!
您可能感兴趣的文章:- SpringBoot整合ES多个精确值查询 terms功能实现
- SpringBoot实现联表查询的代码详解
- Springboot Mybatis使用pageHelper如何实现分页查询
- SpringBoot中的MongoTemplate的各种条件查询示例详解
- Mybatisplus集成springboot完成分页查询功能(示例代码)
用户点评