欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot查詢?nèi)坎块T流程分析

 更新時(shí)間:2024年10月14日 11:41:19   作者:golemon  
本文分析了在SpringBoot框架中前端如何請(qǐng)求DeptController的list()方法,并通過(guò)DeptService到DeptMapper接口查詢數(shù)據(jù)庫(kù)中的全部部門信息的流程,整個(gè)過(guò)程涉及前端到后端數(shù)據(jù)的獲取和返回,是SpringBoot應(yīng)用中常見(jiàn)的數(shù)據(jù)處理模式

前端發(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接口中的方法來(lái)查詢?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又返回給DeptControllerDeptController拿到數(shù)據(jù)再返回給前端。

到此這篇關(guān)于springboot查詢?nèi)坎块T流程的文章就介紹到這了,更多相關(guān)springboot查詢?nèi)坎块T內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java Mybatis框架增刪查改與核心配置詳解流程與用法

    Java Mybatis框架增刪查改與核心配置詳解流程與用法

    MyBatis 是一款優(yōu)秀的持久層框架,它支持自定義 SQL、存儲(chǔ)過(guò)程以及高級(jí)映射。MyBatis 免除了幾乎所有的 JDBC 代碼以及設(shè)置參數(shù)和獲取結(jié)果集的工作。MyBatis 可以通過(guò)簡(jiǎn)單的 XML 或注解來(lái)配置和映射原始類型、接口和 Java POJO為數(shù)據(jù)庫(kù)中的記錄
    2021-10-10
  • Spring中的注解@Value("#{}")與@Value("${}")的區(qū)別介紹

    Spring中的注解@Value("#{}")與@Value("${}")的區(qū)別

    這篇文章主要介紹了Spring中的注解@Value(“#{}“)與@Value(“${}“)的區(qū)別到底是什么,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-06-06
  • java8新特性 stream流的方式遍歷集合和數(shù)組操作

    java8新特性 stream流的方式遍歷集合和數(shù)組操作

    這篇文章主要介紹了java8新特性 stream流的方式遍歷集合和數(shù)組操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • SpringBoot測(cè)試junit遇到的坑及解決

    SpringBoot測(cè)試junit遇到的坑及解決

    這篇文章主要介紹了SpringBoot測(cè)試junit遇到的坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • Java多線程下載文件實(shí)現(xiàn)案例詳解

    Java多線程下載文件實(shí)現(xiàn)案例詳解

    這篇文章主要介紹了Java多線程下載文件實(shí)現(xiàn)案例詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-05-05
  • StringUtils中的isEmpty、isNotEmpty、isBlank和isNotBlank的區(qū)別詳解

    StringUtils中的isEmpty、isNotEmpty、isBlank和isNotBlank的區(qū)別詳解

    這篇文章主要介紹了StringUtils中的isEmpty、isNotEmpty、isBlank和isNotBlank的區(qū)別詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 關(guān)于Tomcat出現(xiàn)The origin server did not find a current representation for the target resourc...的問(wèn)題

    關(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...的問(wèn)題,感興趣的小伙伴們可以參考一下
    2020-08-08
  • 詳解Android系統(tǒng)中的root權(quán)限獲得原理

    詳解Android系統(tǒng)中的root權(quán)限獲得原理

    這篇文章主要介紹了詳解Android系統(tǒng)中的Root權(quán)限獲得原理,安卓基于Linux,所以原理也相當(dāng)于Linux中的root用戶,需要的朋友可以參考下
    2015-08-08
  • Java字符串如何轉(zhuǎn)化date

    Java字符串如何轉(zhuǎn)化date

    Java字符串轉(zhuǎn)換為Date對(duì)象,通常需要使用SimpleDateFormat類,該類提供了日期格式化和解析的方法,但需要注意日期格式模式的選擇、異常處理和線程安全性
    2025-02-02
  • Java過(guò)濾器@WebFilter用法詳解

    Java過(guò)濾器@WebFilter用法詳解

    @WebFilter用于將一個(gè)類聲明為過(guò)濾器,該注解將會(huì)在部署時(shí)被容器處理,容器將根據(jù)具體的屬性配置將相應(yīng)的類部署為過(guò)濾器,這篇文章主要給大家介紹了關(guān)于Java過(guò)濾器@WebFilter用法的相關(guān)資料,需要的朋友可以參考下
    2024-01-01

最新評(píng)論