Brian的雜記
  • Introduction
  • Brian's 雜記
    • My Awesome API
    • FB 大頭貼
    • 硬體雜記
    • PHP
    • project
      • 模擬器
      • WAMP
    • WinMerge
    • 雜記
      • LINQ
      • 方法
      • Grid View
      • namespace
      • global
      • 物件導向
      • Excel
      • VS2017
      • single sign on
      • Master
      • Https
      • 憑證
      • 略過憑證不符
      • NLog
      • 團隊開發
      • .NET Core
      • 共用網路上的芳鄰
      • 爬蟲
      • NPOI
      • RSS
      • 多執行緒
      • 記憶體回收
      • 密碼學
        • BCrypt
        • AES
      • 主機環境建置
      • Session
      • Error
      • IIS 相關
      • 無障礙相關
      • 介面
        • 影像地圖
      • telnet
        • smtp
      • nslookup
      • 協助客戶解決問題
      • 驗證欄位
      • 網站管理
      • 工具整理
    • 正規表示法
    • 影像處理
    • IntelliJ Idea
    • 觀念
      • Clean Code
        • 命名
        • 函式
        • 註解
        • 編排
        • 物件及資料結構
        • 錯誤處理
        • 邊界
        • 單元測試
        • 類別
      • Java 程式風格
      • Design Pattern
        • 單例模式
      • 同步
      • 畫圖
        • ER-Model
        • 類別圖
        • Use Case
        • 有限狀態機
      • 資料 API 文件 分析
      • CORS & SSL
      • 利用DISC幫助溝通
      • OAS
    • 檔案上傳
      • FileStore
      • App Engine
      • Google Storage
    • OAuth vs Open ID
    • MIME
    • 虛擬桌面
    • 待看資料
    • Selenium
    • CDN
    • HTTP
    • 編碼
    • 2nd-ML100Days
      • jupyter
    • 微服務
      • 設計
        • 1 ~ 5
        • 6
        • 7
        • 8
        • 9
    • Gradle
    • Maven
    • Error
    • 批次檔 BAT
    • Kurento
    • WebSocket & WebRTC
  • 需求面能力
    • User Story
  • Google Cloud Platform
    • Compute Engine
  • Python
    • 基本語法
    • Pandas
    • 套件
    • Matplotlib
    • Encoder
    • jupyter
  • Java
    • Java
      • File
      • Exception
      • 物件導向觀念
      • 加密
      • HTTP
      • 集合
      • Stream()
      • Web
      • ResultSet
      • JDK6
      • JDK8
    • 讀取、複寫MP3 Tag
    • Log4j2
    • Servlet
      • 容器
    • JSP
    • JBOSS
    • JWT
    • PreparedStatement
    • Error
    • Spring
      • Spring Boot
        • @Value
        • Build
      • RequestParameter
      • Error
      • Autowired
      • JPA
      • FeignClient
      • WebSocket
      • thymeleaf
      • Security
      • Test
      • Scheduled
      • Redirect
    • IntelliJ
  • Linux
    • Linux
    • Shell Script
    • Cygwin(在Windows執行Linux指令)
  • 前端
    • HTML
      • Link
    • CSS
      • Position
      • padding color
      • display
    • JS
      • jQuery
        • Select2
      • fancybox
      • ES6
      • 效能
      • GoogleMap API
        • Marker
        • InfoWindow
      • 事件
      • CKEditor
      • TGOS
      • JSON
      • QRcode
      • 核心概念
        • 物件 變數 型別
          • number
          • String
          • boolean
          • null & undefined
          • Symbol
        • JS 物件概念
        • 深入理解JS 函式物件
        • 更多ES2015/ES6 全新語言特性
      • Promise
    • 效果應用
  • 資料庫
    • 注意事項
    • MariaDB
    • MySQL
      • inner join 和 join
      • 字串比對
      • 倒數資料
    • SQL
      • DDL 資料定義語言
      • DML 資料操縱語言
      • DCL 資料控制語言
      • TCL 交易控制語言
      • T-SQL
      • CTE
      • JOIN
    • Oracle
    • MSSQL 操作
      • 新增使用者
      • SQL 指令
      • Sequence
    • 差異比較
    • MyBatis
    • Workbench 操作
    • SQL Injection
  • 版本控制
    • Gitlab
      • sign up
      • sign in
      • add project
      • add members
    • SourceGit
      • install
    • SmartGit
      • install
      • operate
      • git 操作雜記
    • TortoiseGit
    • Git
    • TFS
    • SVN
  • Test
    • 軟體測試原則
    • 演算法
    • XMind
      • install
    • Jenkins
      • 建置
    • HTTPie
    • Postman
    • 測試驅動開發
    • 撰寫測試的觀念
    • 測試框架
    • IoC & DI
    • 隔絕相依性的方式
    • JUnit
    • NUnit
    • 習慣
    • 虛設常式
  • Angular
    • hello world
    • ng-options
    • ES6
    • Build & Conponect
    • HttpClient
    • 部署
  • ASP.NET Web Form
    • Chapter 2
      • 2-1
        • 小東西
    • 略過請求驗證
  • Go
Powered by GitBook
On this page
  • 序
  • 用資料夾切割架構
  • @SpringCloudApplication和@SpringBootApplication的區別
  • @Scope
  • singleton(默認)
  • prototype:
  • request:
  • session:

Was this helpful?

  1. Java
  2. Spring

Spring Boot

PreviousSpringNext@Value

Last updated 4 years ago

Was this helpful?

序

參考資料:()

參考資料:()

當新建一個 Spring Boot 項目時,就會有一個 Application.java 了

只要再產生一個 Controller.java 就可以跑起來一個最簡單的 RESTful 伺服器了

以前是用 @Controller

如果要返回 json 要配合 @ResponseBody

Spring4 之後 加入 @RestController 就夠了

也就是說 @RestController = @Controller + @ResponseBody

@CrossOrigin(origins = "http://localhost:4200") 可以利用這個去允許特定前端存取

參考資料:()

在 Controller 裡面配置 url 映射是用 @RequestMapping

這邊就可以去參考章節 <RequestParameter>

如果需要重定向,可以回傳 ModelAndView

如果需要重定向,可以傳入 HttpServletResponse,再 sendRedirect()

spring boot 的 starter 可以幫助我們 減少相依套件的管理、配置時間

用資料夾切割架構

Controller - Service - Model - DAO - DB

handler

exception

utility

@SpringCloudApplication和@SpringBootApplication的區別

@SpringCloudApplication包括: @SpringBootApplication、@EnableDiscoveryClient、@EnableCircuitBreaker, 分別是SpringBoot注解、註冊服務中心Eureka注解、斷路器注解。

對於 SpringCloud 来说,這是每一微服務必須應有的三個注解,所以才推出了 @SpringCloudApplication 這一注解集合。

@Scope

Spring容器最初提供了兩種bean的scope類型:singleton和prototype;但發布2.0以後,又引入了另外三種scope類型:request、session和global session,這三種只能在web 應用中才可以使用。

singleton(默認)

這是Spring默認的scope,表示Spring容器只創建唯一一個bean的實例,所有該對象的引用都共享這個實例,並且Spring在創建第一次後,會在Spring的IoC容器中緩存起來,之後不再創建,就是設計模式中的單例模式的形式。

並且對該bean的所有後續請求和引用都將返回該緩存中的對象實例。一般情況下,無狀態的bean使用該scope。

prototype:

代表線程每次調用或請求這個bean都會創建一個新的實例。一般情況下,有狀態的bean使用該scope。

request:

每次http請求將會有各自的bean實例,類似於prototype。

也就是說每個request作用域內的請求只創建一個實例。

session:

在一個http session中,一個bean定義對應一個bean實例。也就是說每個session作用域內的請求只創建一個實例。

參考資料:()

參考資料:()

參考資料:()

https://kknews.cc/code/ebjoajz.html
https://blog.csdn.net/sifanlook/article/details/88905090
https://blog.csdn.net/sinat_23225111/article/details/77984206
https://www.baeldung.com/spring-boot-starters
https://blog.csdn.net/tt____tt/article/details/81080200
https://kknews.cc/zh-tw/code/zbvkozl.html