springboot使用小工具之Lombok、devtools、Spring Initailizr詳解
Lombok
可以代替手寫get、set、構(gòu)造方法等,需要idea裝插件lombok
導(dǎo)包:
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> <scope>provided</scope> </dependency>
用法與功能:
package com.atguigu.boot.bean; import lombok.*; import org.springframework.boot.context.properties.ConfigurationProperties; @Data//get、set @AllArgsConstructor//全參構(gòu)造方法 @NoArgsConstructor//無參構(gòu)造方法 @ToString @EqualsAndHashCode @ConfigurationProperties(prefix = "mycar")//設(shè)置前綴為mycar,它將會(huì)自動(dòng)跟字段對(duì)應(yīng) public class Car { private String brand; private Integer price; }
package com.atguigu.boot.controller; import com.atguigu.boot.bean.Car; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j//使用注解 @RestController public class HelloController { @Autowired private Car car;//從spring容器中自動(dòng)注入 @RequestMapping("/hello") public String handle01() { return "Hello, Spring Boot 2!"; } @GetMapping("/car") public Car car() { log.info("請(qǐng)求car");//代替sout return car; } }
devtools
可以不用點(diǎn)重啟按鈕更新項(xiàng)目,按Ctrl + F9就可以重啟項(xiàng)目,相當(dāng)于重啟項(xiàng)目,如果項(xiàng)目沒有更改或者更改的是靜態(tài)頁(yè)面的時(shí)候是不會(huì)重啟的。
導(dǎo)包:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> </dependencies>
使用付費(fèi)的JRebel 可以實(shí)現(xiàn)熱更新。
Spring Initailizr(項(xiàng)目初始化向?qū)В?/h2>
需要用什么選什么
需要什么依賴就勾選什么依賴
點(diǎn)下一步一個(gè)springboot項(xiàng)目就創(chuàng)建好了。
到此這篇關(guān)于springboot使用小工具之Lombok、devtools、Spring Initailizr詳解的文章就介紹到這了,更多相關(guān)springboot使用工具內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決@PathVariable出現(xiàn)點(diǎn)號(hào).時(shí)導(dǎo)致路徑參數(shù)截?cái)喃@取不全的問題
這篇文章主要介紹了解決@PathVariable出現(xiàn)點(diǎn)號(hào).時(shí)導(dǎo)致路徑參數(shù)截?cái)喃@取不全的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08Springboot+Redis實(shí)現(xiàn)API接口防刷限流的項(xiàng)目實(shí)踐
本文主要介紹了Springboot+Redis實(shí)現(xiàn)API接口防刷限流的項(xiàng)目實(shí)踐,通過限流可以讓系統(tǒng)維持在一個(gè)相對(duì)穩(wěn)定的狀態(tài),為更多的客戶提供服務(wù),具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07Spring Boot 集成Shiro的多realm配置過程
這篇文章主要介紹了Spring Boot 集成Shiro的多realm配置,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10MybatisPlus中QueryWrapper常用方法總結(jié)
MyBatis-Plus是一個(gè)Mybatis增強(qiáng)版工具,在MyBatis上擴(kuò)充了其他功能沒有改變其基本功能,為了簡(jiǎn)化開發(fā)提交效率而存在,queryWrapper是mybatis plus中實(shí)現(xiàn)查詢的對(duì)象封裝操作類,本文就給大家總結(jié)了MybatisPlus中QueryWrapper的常用方法,需要的朋友可以參考下2023-07-07