springboot查詢?nèi)坎块T流程分析
前端發(fā)送請求后,會請求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) // 指定請求參數(shù)為 GET @GetMapping("/depts") // 等同于上面的寫法 public Result list() { // System.out.println("查詢?nèi)坎块T數(shù)據(jù)"); log.info("查詢?nèi)坎块T數(shù)據(jù)"); // 調(diào)用service查詢部門數(shù)據(jù) List<Dept> deptList = deptService.list(); return Result.success(deptList); } }
在list()
中調(diào)用DeptService
獲取數(shù)據(jù)。
在DeptService
中調(diào)用DeptMapper
接口中的方法來查詢?nèi)康牟块T信息。
package com.intelligent_learning_aid_system.service; import com.intelligent_learning_aid_system.pojo.Dept; import java.util.List; /** * 部門管理 */ public interface DeptService { /** * 查詢?nèi)坎块T * @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; /** * 查詢?nèi)坎块T */ public List<Dept> list() { return deptMapper.list(); } }
DeptMapper
接口會往數(shù)據(jù)庫發(fā)送SQL語句,查詢?nèi)康牟块T,并且把查詢的信息封裝到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 { /** * 查詢?nèi)坎块T * @return */ @Select("select * from dept") List<Dept> list(); }
最終將集合數(shù)據(jù)返回給DeptService
,DeptService
又返回給DeptController
。DeptController
拿到數(shù)據(jù)再返回給前端。
到此這篇關(guān)于springboot查詢?nèi)坎块T流程的文章就介紹到這了,更多相關(guān)springboot查詢?nèi)坎块T內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java Mybatis框架增刪查改與核心配置詳解流程與用法
MyBatis 是一款優(yōu)秀的持久層框架,它支持自定義 SQL、存儲過程以及高級映射。MyBatis 免除了幾乎所有的 JDBC 代碼以及設(shè)置參數(shù)和獲取結(jié)果集的工作。MyBatis 可以通過簡單的 XML 或注解來配置和映射原始類型、接口和 Java POJO為數(shù)據(jù)庫中的記錄2021-10-10Spring中的注解@Value("#{}")與@Value("${}")的區(qū)別
這篇文章主要介紹了Spring中的注解@Value(“#{}“)與@Value(“${}“)的區(qū)別到底是什么,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-06-06java8新特性 stream流的方式遍歷集合和數(shù)組操作
這篇文章主要介紹了java8新特性 stream流的方式遍歷集合和數(shù)組操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08StringUtils中的isEmpty、isNotEmpty、isBlank和isNotBlank的區(qū)別詳解
這篇文章主要介紹了StringUtils中的isEmpty、isNotEmpty、isBlank和isNotBlank的區(qū)別詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06關(guān)于Tomcat出現(xiàn)The origin server did not find a current represent
這篇文章主要介紹了關(guān)于Tomcat出現(xiàn)The origin server did not find a current representation for the target resourc...的問題,感興趣的小伙伴們可以參考一下2020-08-08詳解Android系統(tǒng)中的root權(quán)限獲得原理
這篇文章主要介紹了詳解Android系統(tǒng)中的Root權(quán)限獲得原理,安卓基于Linux,所以原理也相當(dāng)于Linux中的root用戶,需要的朋友可以參考下2015-08-08