springboot查詢?nèi)坎块T流程分析
前端發(fā)送請(qǐng)求后,會(huì)請(qǐng)求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) // 指定請(qǐng)求參數(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接口會(huì)往數(shù)據(jù)庫(kù)發(fā)送SQL語(yǔ)句,查詢?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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Spring 處理 HTTP 請(qǐng)求參數(shù)注解的操作方法
這篇文章主要介紹了Spring 處理 HTTP 請(qǐng)求參數(shù)注解的操作方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友參考下吧2024-04-04
Java實(shí)現(xiàn)在word中指定位置插入圖片
Poi-tl?是基于?Apache?POI?的?Java?開源文檔處理庫(kù),專注于高效操作?Word?文檔,本文小編就來和大家詳細(xì)講講Java如何使用Poi-tl實(shí)現(xiàn)在word中指定位置插入圖片吧2025-06-06
Java死鎖代碼實(shí)例及產(chǎn)生死鎖必備的四個(gè)條件
這篇文章主要介紹了Java死鎖代碼實(shí)例及產(chǎn)生死鎖必備的四個(gè)條件,Java 發(fā)生死鎖的根本原因是,在申請(qǐng)鎖時(shí)發(fā)生了交叉閉環(huán)申請(qǐng),synchronized在開發(fā)中最好不要嵌套使用,容易導(dǎo)致死鎖,需要的朋友可以參考下2024-01-01
SpringBoot實(shí)現(xiàn)讀取YML,yaml,properties文件
yml,yaml,properties三種文件都是用來存放配置的文件,一些靜態(tài)數(shù)據(jù),配置的數(shù)據(jù)都會(huì)存放到里邊。本文主要為大家整理了SpringBoot實(shí)現(xiàn)讀取YML,yaml,properties文件的方法,需要的可以參考一下2023-04-04
Eclipse Debug模式的開啟與關(guān)閉問題簡(jiǎn)析
這篇文章主要介紹了Eclipse Debug模式的開啟與關(guān)閉問題簡(jiǎn)析,同時(shí)向大家介紹了一個(gè)簡(jiǎn)單的debug模式啟動(dòng)不起來的解決方法,希望對(duì)大家有所幫助。2017-10-10
Java反射機(jī)制如何解決數(shù)據(jù)傳值為空的問題
這篇文章主要介紹了Java反射機(jī)制如何解決數(shù)據(jù)傳值為空的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
從Myeclipse 導(dǎo)入到eclipse中無法識(shí)別為 web項(xiàng)目 問題的解決步驟
這篇文章主要介紹了從Myeclipse 導(dǎo)入到eclipse中無法識(shí)別為 web項(xiàng)目 問題的解決步驟,需要的朋友可以參考下2018-05-05
SprigBoot整合rocketmq-v5-client-spring-boot的示例詳解
這篇文章主要介紹了SprigBoot整合rocketmq-v5-client-spring-boot的詳細(xì)過程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2010-07-07

