Spring Boot中Lombok的使用

2021-10-05 01:30:47 字數 990 閱讀 5839

@data:註解在類上;提供類所有屬性的 getting 和 setting 方法,此外還提供了equals、canequal、hashcode、tostring 方法

@setter:註解在屬性上;為屬性提供 setting 方法

@getter:註解在屬性上;為屬性提供 getting 方法

@log4j :註解在類上;為類提供乙個 屬性名為log 的 log4j 日誌物件

@noargsconstructor:註解在類上;為類提供乙個無參的構造方法

@allargsconstructor:註解在類上;為類提供乙個全參的構造方法

1.不使用 lombok 的方案

public

class

person

public

person

(string id, string name, string identity)

public string getid()

public string getname()

public string getidentity()

public

void

setid

(string id)

public

void

setname

(string name)

public

void

setidentity

(string identity)

}

2.使用 lombok 的方案:

@data

@log4j

@noargsconstructor

@allargsconstructor

public

class

person

Springboot中Thymeleaf外部模板

spingboot專案中,預設的thymeleaf模板資料夾是在 src main resources templates,打包時後在classpath templates下 jar包同目錄下的 templates 目錄 spring.thymeleaf.prefix file templates ...

springboot中controller無法訪問

configuration 該註解將類可以看成配置檔案,通常和 bean配合使用 enableautoconfiguration 在程式啟動時自動載入配置 componentscan 會自動掃瞄指定包下的全部標有 component的類,並註冊成bean,當然包括 component下的子註解 se...

SpringBoot中的註解

在spring boot中幾乎可以完全棄用xml配置檔案,本文的主題是分析常用的註解。spring最開始是為了解決ejb等大型企業框架對應用程式的侵入性,因此大量依靠配置檔案來 非侵入式 得給pojo增加功能,然而,從spring 3.x開始,spring被外界最為詬病的一點就是配置繁多,號稱 配置...