0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

SpringBoot基礎(chǔ)知識

jf_96884364 ? 來源:jf_96884364 ? 作者:jf_96884364 ? 2023-01-13 14:45 ? 次閱讀

1 SpringBoot分層

1.1 Controller

控制業(yè)務(wù)層Service的,它的作用主要是架起了外界與業(yè)務(wù)層溝通的橋梁,移動端,前端在調(diào)用接口訪問相關(guān)業(yè)務(wù)時,都會通過Controller,由Controller去調(diào)相關(guān)的業(yè)務(wù)層代碼并把數(shù)據(jù)返回給移動端和前端。

api接口可以直接寫在這一層。

1.2 Service

業(yè)務(wù)層,所有的內(nèi)部的業(yè)務(wù)邏輯都會放在這里處理,比如用戶的增刪改查,或者發(fā)送個驗證碼或郵件,或者做?個抽獎活動等,都會在Service中進行。

1.3 dao

數(shù)據(jù)持久化層,就是和數(shù)據(jù)庫打交道的,而實現(xiàn)持久化層的框架有很多,而常用的有兩種:JPA和MyBatis,JPA是SpringBoot官方的,前身就是著名的三大框架之一的Hibernate,好處是不用手寫SQL。MyBatis則在國內(nèi)比較流行,原因是它的靈活性非常高,但是需要手寫SQL語句。

2 POM文件

2.1 parent

<parent>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-parentartifactId>
    <version>2.2.6.RELEASEversion>
parent>
  • spring-boot-starter是一個場景啟動器。springboot將所有的功能場景抽取出來,做成一個個的啟動器starter,只需要在項目里引入這些starter,相關(guān)場景的所有依賴都會導(dǎo)入進來,要用什么功能就導(dǎo)入什么啟動器

這個parent為我們管理依賴的版本,是springboot的版本仲裁中心,以后我們導(dǎo)入的依賴中不需要寫版本。

2.2 starter-web

<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-webartifactId>
dependency>

spring-boot-starter-web是一個場景啟動器,啟動的是springboot的web場景,同上Ctrl+鼠標(biāo)左鍵,可以看到啟動web場景需要的依賴有:spring-boot-starter、spring-boot-starter-json、spring-boot-starter-tomcat等。

2.3 starter-test

<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-testartifactId>
    <scope>testscope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintagegroupId>
            <artifactId>junit-vintage-engineartifactId>
        exclusion>
    exclusions>
dependency>

測試場景的啟動器

2.4 maven-plugin

maven的插件,配置插件的依賴以后可以進行打jar包等操作

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
        plugin>
    plugins>
build>

2.5 hutool

在 pom 文件內(nèi)添加 hutool 依賴:

<dependency>
    <groupId>cn.hutoolgroupId>
    <artifactId>hutool-allartifactId>
    <version>5.0.6version>
dependency>

2.6 log

<dependency>
    <groupId>log4jgroupId>
    <artifactId>log4jartifactId>
    <version>1.2.17version>
dependency>

2.7 lang

<dependency>
    <groupId>commons-langgroupId>
    <artifactId>commons-langartifactId>
    <version>2.6version>
dependency>

2.8 lang3

<dependency>
    <groupId>org.apache.commonsgroupId>
    <artifactId>commons-lang3artifactId>
    <version>3.3.2version>
dependency>

3 注解

3.1 @controller 控制器

注入服務(wù)

用于標(biāo)注控制層,相當(dāng)于struts中的action層

3.2 @service 服務(wù)

注入dao

用于標(biāo)注服務(wù)層,主要用來進行業(yè)務(wù)的邏輯處理

3.3 @repository

實現(xiàn)dao訪問

用于標(biāo)注數(shù)據(jù)訪問層,也可以說用于標(biāo)注數(shù)據(jù)訪問組件,即DAO組件.

3.4 @component

把普通pojo實例化到spring容器中,相當(dāng)于配置文件中的

泛指各種組件,就是說當(dāng)我們的類不屬于各種歸類的時候(不屬于@Controller、@Services等的時候),我們就可以使用@Component來標(biāo)注這個類。

3.5 @Autowired

與component 相互配合,實現(xiàn)調(diào)用。

審核編輯:湯梓紅

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • JAVA
    +關(guān)注

    關(guān)注

    19

    文章

    2943

    瀏覽量

    104106
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4671

    瀏覽量

    67770
  • spring
    +關(guān)注

    關(guān)注

    0

    文章

    335

    瀏覽量

    14259
  • Boot
    +關(guān)注

    關(guān)注

    0

    文章

    148

    瀏覽量

    35675
  • SpringBoot
    +關(guān)注

    關(guān)注

    0

    文章

    172

    瀏覽量

    145
收藏 人收藏

    評論

    相關(guān)推薦

    labview基礎(chǔ)知識

    labview基礎(chǔ)知識labview基礎(chǔ)知識labview基礎(chǔ)知識labview基礎(chǔ)知識
    發(fā)表于 03-08 17:56

    EMC基礎(chǔ)知識

    EMC基礎(chǔ)知識EMC基礎(chǔ)知識---華為.pdf (440.74 KB )
    發(fā)表于 06-06 04:36

    SpringBoot知識總結(jié)

    SpringBoot干貨學(xué)習(xí)總結(jié)
    發(fā)表于 08-01 10:40

    通信基礎(chǔ)知識教程

    通信基礎(chǔ)知識 1、電信基礎(chǔ)知識2、通信電源技術(shù)3、配線設(shè)備結(jié)構(gòu)、原理與防護4、防雷基礎(chǔ)知識5、EMC基礎(chǔ)知識6、防腐蝕原理與技術(shù)7、產(chǎn)品安
    發(fā)表于 03-04 16:48 ?33次下載

    QC基礎(chǔ)知識

    QC基礎(chǔ)知識闡述
    發(fā)表于 06-02 10:01 ?154次下載

    軟板基礎(chǔ)知識

    軟板基礎(chǔ)知識
    發(fā)表于 06-30 19:22 ?1287次閱讀

    電子電路基礎(chǔ)知識

    電子電路基礎(chǔ)知識 電路基礎(chǔ)知識(一)電路基礎(chǔ)知識(1
    發(fā)表于 01-15 09:47 ?22.6w次閱讀

    電池基礎(chǔ)知識(集全版)

    電池基礎(chǔ)知識(集全版)  電池基礎(chǔ)知識
    發(fā)表于 11-10 14:19 ?2434次閱讀

    電池隔膜基礎(chǔ)知識

    電池隔膜基礎(chǔ)知識
    發(fā)表于 11-17 13:40 ?1094次閱讀

    計算機基礎(chǔ)知識介紹

    計算機基礎(chǔ)知識計算機基礎(chǔ)知識計算機基礎(chǔ)知識
    發(fā)表于 12-03 16:13 ?0次下載

    使用Eclipse基礎(chǔ)知識

    使用Eclipse 基礎(chǔ)知識 使用Eclipse 基礎(chǔ)知識 適合初學(xué)者學(xué)習(xí)使用
    發(fā)表于 02-26 10:30 ?0次下載

    synplify基礎(chǔ)知識說明

    synplify基礎(chǔ)知識說明
    發(fā)表于 06-17 17:40 ?25次下載

    電源管理基礎(chǔ)知識電源管理基礎(chǔ)知識電源管理基礎(chǔ)知識

    電源管理基礎(chǔ)知識電源管理基礎(chǔ)知識電源管理基礎(chǔ)知識
    發(fā)表于 09-15 14:36 ?76次下載
    電源管理<b class='flag-5'>基礎(chǔ)知識</b>電源管理<b class='flag-5'>基礎(chǔ)知識</b>電源管理<b class='flag-5'>基礎(chǔ)知識</b>

    優(yōu)質(zhì)LDO基礎(chǔ)知識分享

    本節(jié)分享下LDO的基礎(chǔ)知識,主要來源于Ti的文檔《LDO基礎(chǔ)知識》。
    的頭像 發(fā)表于 03-26 11:03 ?1224次閱讀

    什么是 SpringBoot?

    本文從為什么要有 `SpringBoot`,以及 `SpringBoot` 到底方便在哪里開始入手,逐步分析了 `SpringBoot` 自動裝配的原理,最后手寫了一個簡單的 `start` 組件,通過實戰(zhàn)來體會了 `
    的頭像 發(fā)表于 04-07 11:28 ?1183次閱讀
    什么是 <b class='flag-5'>SpringBoot</b>?