【后端】Idea下快速搭建 SpringBoot 工程,整合Mybatis+Druid

1、?idea下創(chuàng)建spring boot 工程

1.1打開(kāi)idea選擇新建一個(gè)Module工程

步驟一

?

步驟二

?

步驟三

?

步驟四接口訪問(wèn)使用spring Web Starter 這里

?

步驟五sql分勾選Mysql Driver和Mybatis Framework

?

步驟六完成創(chuàng)建,第一次創(chuàng)建需要等等maven的依賴(lài)包下載完成就建好了

?

步驟七在pom.xml文件中添加依賴(lài)

<!--使用durid連接池的依賴(lài)-->

<dependency>

? ? <groupId>com.alibaba</groupId>

? ? <artifactId>druid-spring-boot-starter</artifactId>

? ? <version>1.1.1</version>

</dependency>

?

步驟八在application.properties文件中添加 tomcat端口8080,mysql和druid配置

?

#內(nèi)置tomcat訪問(wèn)端口

server.port=8080

#mysql 數(shù)據(jù)庫(kù)配置信息

spring.datasource.url=jdbc:mysql://localhost:3306/lcit?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

#mybatis xml文件路徑映射

mybatis.mapper-locations=classpath*:mapper/*.xml

##druid

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

##最大活躍數(shù)

spring.datasource.maxActive=20

##初始化數(shù)量

spring.datasource.initialSize=1

##最大連接等待超時(shí)時(shí)間

spring.datasource.maxWait=60000

#配置監(jiān)控統(tǒng)計(jì)攔截的filters,去掉后監(jiān)控界面sql將無(wú)法統(tǒng)計(jì),'wall'用于防火墻

filters=stat, wall, log4j

# 監(jiān)控地址 http://baseUrl:port/druid/weburi.html

# StatViewServlet配置,說(shuō)明請(qǐng)參考Druid Wiki,配置_StatViewServlet配置

#是否啟用StatViewServlet(監(jiān)控頁(yè)面)默認(rèn)值為false(考慮到安全問(wèn)題默認(rèn)并未啟動(dòng),如需啟用建議設(shè)置密碼或白名單以保障安全)

spring.datasource.druid.stat-view-servlet.enabled= true

spring.datasource.druid.stat-view-servlet.login-username=admin

spring.datasource.druid.stat-view-servlet.login-password=admin

步驟九 創(chuàng)建controller、entity、dao文件

注意事項(xiàng): mybatis? @Repository注解時(shí)候時(shí),需要在LcitApplication.java? Spring Boot 啟動(dòng)類(lèi)中添加掃碼注@MapperScan("com.example.lcit")

?

步驟十? 測(cè)試代碼

訪問(wèn)durid監(jiān)控,地址http://127.0.0.1:8080/druid/login.html賬號(hào)/密碼admin/admin,這是sql監(jiān)控開(kāi)發(fā)時(shí)可以使用上生產(chǎn)時(shí)請(qǐng)記得關(guān)閉,在application.properties中spring.datasource.druid.stat-view-servlet.enabled= true 設(shè)置為false

?

測(cè)試新增

http://127.0.0.1:8080/lcit/add?id=1&name=獵潮girl

源碼地址:

https://gitee.com/swagest/spring-boot-lcit.git

歡迎轉(zhuǎn)載需并注明出處【獵潮IT】文章地址https://blog.csdn.net/qq_29707325/article/details/91129468

寫(xiě)文章不易,如果覺(jué)得這篇文章對(duì)你有幫助,或者對(duì)相關(guān)操作步驟有疑問(wèn),歡迎關(guān)注我的微信公眾號(hào)留言【獵潮IT】,打開(kāi)微信掃下面二維碼

?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容