idea mybatis generator插件_SpringBoot+MyBatis+Druid整合demo

最近自己寫了一個SpringBoot+Mybatis(generator)+druid的demo

be7fa3ccac4741668d555ccf97093c26

1. mybatis+generator逆向工程生成代碼

1. pom文件

pom文件添加如下內容,引入generator插件

                                    org.mybatis.generator                mybatis-generator-maven-plugin                1.3.5 mysql                         mysql-connector-java                        5.1.35org.mybatis.generator                        mybatis-generator-core                        1.3.5Generate MyBatis Artifactspackagegenerate           > 這里是引用         truetruesrc/main/resources/generator/generatorConfig.xml

當pom引入此插件成功的話,idea右側可以看到

d1b33d04f52e477b9fa5c53331911541

2. 在resources下新建generator文件夾,在generator下新建generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?>

3. 運行插件

9adc6174b32b480ca84ea297b0924707

4. 生成以下代碼

a516775018b44a6a899ccd4a33a59251

2. application.perperties中的配置

1. mybatis的配置

# mybatis實體類的包路徑mybatis.typeAliasesPackage=com.qlu.cloud.pojo# mybatis的dao層方法的實現xmlmybatis.mapper-locations: classpath:mapper/*.xml

2. druid的配置

# 連接數據庫的設置,SpringBoot會自動掃描這些# 連接數據庫的驅動名字,自6.x版本就換了名字spring.datasource.driverClassName=com.mysql.cj.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/hadoop?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=falsespring.datasource.username = rootspring.datasource.password = root# 初始化時建立物理連接的個數spring.datasource.druid.initial-size=5# 最大連接池數量spring.datasource.druid.max-active=30# 最小連接池數量spring.datasource.druid.min-idle=5# 獲取連接時最大等待時間,單位毫秒spring.datasource.druid.max-wait=60000# 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒spring.datasource.druid.time-between-eviction-runs-millis=60000# 連接保持空閑而不被驅逐的最小時間spring.datasource.druid.min-evictable-idle-time-millis=300000# 用來檢測連接是否有效的sql,要求是一個查詢語句spring.datasource.druid.validation-query=SELECT 1 FROM DUAL# 建議配置為true,不影響性能,并且保證安全性。申請連接的時候檢測,如果空閑時間大于timeBetweenEvictionRunsMillis,執行validationQuery檢測連接是否有效。spring.datasource.druid.test-while-idle=true# 申請連接時執行validationQuery檢測連接是否有效,做了這個配置會降低性能。spring.datasource.druid.test-on-borrow=false# 歸還連接時執行validationQuery檢測連接是否有效,做了這個配置會降低性能。spring.datasource.druid.test-on-return=false# 是否緩存preparedStatement,也就是PSCache。PSCache對支持游標的數據庫性能提升巨大,比如說oracle。在mysql下建議關閉。spring.datasource.druid.pool-prepared-statements=true# 要啟用PSCache,必須配置大于0,當大于0時,poolPreparedStatements自動觸發修改為true。spring.datasource.druid.max-pool-prepared-statement-per-connection-size=50# 配置監控統計攔截的filters,去掉后監控界面sql無法統計spring.datasource.druid.filters=stat,wall# 通過connectProperties屬性來打開mergeSql功能;慢SQL記錄spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500# 合并多個DruidDataSource的監控數據spring.datasource.druid.use-global-data-source-stat=true# druid連接池監控spring.datasource.druid.stat-view-servlet.login-username=adminspring.datasource.druid.stat-view-servlet.login-password=123# 排除一些靜態資源,以提高效率spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*

3. thymeleaf的配置

thymeleaf 是新一代的模板引擎,在spring4.0中推薦使用thymeleaf來做前端模板引擎。它可以完全替代 JSP 。

thymeleaf的使用

application.propertites中的配置

spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=HTMLspring.thymeleaf.encoding=utf-8spring.thymeleaf.cache=false

pom文件中

 org.springframework.boot            spring-boot-starter-thymeleaf        org.springframework.boot            spring-boot-starter-thymeleaf        

== thymeleaf下的return “start”;即為跳轉到start.html界面,前提是這個文件在配置文件下配置的/templates/下,他的意思是動態。==

3. 執行

接下來就可以寫controller層來執行函數了

package com.qlu.cloud.controller;import com.qlu.cloud.mapper.UserMapper;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping("a")public class demoController  {    /**     * auto scan配置     * 在編輯情況下,無法找不到對應的bean     * 于是提示找不到對應bean的錯誤。     * 常見于mybatis的mapper     *     * 解決辦法:降低Autowired檢測的級別,將Severity的級別由之前的error改成warning或其它可以忽略的級別。     */    @Autowired    private UserMapper userMapper;    @RequestMapping("show")    public String show(Model model){        model.addAttribute("info",userMapper.selectByPrimaryKey(1));        return "start";    }}

其實controller層的注解我是采用了之前SSM框架的寫法,其實這里有一個注解@RestController,它=@Controller+@ResponseBody,表示返回的是json

這里我們用model返回了一個類,然后跳轉到了start.html界面,在start.html界面展示數據start.html在/templates/下,它的內容為

    Title
序號 風機編號 報警時間 30s內溫度高于80度次數 最最重要的一點

因為之前在寫Mapper的時候(也就是DAO層是生成的,生成的Mapper類中沒有使用@Mapper注解,但是每個Mapper中的類要加一個@Mapper注解也很麻煩),所以我們要在啟動類上加一個@MapperScan(“com.qlu.cloud.mapper”)來聲明@Mapper所在的包即可,啟動類一般叫項目名+Application

然后運行項目即可。

實用插件

devtools熱部署

每次改完都要重新停止應用,再重新啟動很煩~但springboot有個叫熱部署的東西,就是說在項目中修改代碼可以不用重新停止應用再重新啟動,可以自動重啟,這里我們用的是devtools

1. pom文件中添加以下內容

     org.springframework.boot           spring-boot-devtools           providedtrue

2. 勾選setting->Build,Execution,Deployment->Compiler->Build project automatically

3. Ctrl+Shift+Alt+/ -> 選擇Registry… -> 勾選compiler.automake.allow.when.app.running

4. 重啟項目即可

最后附上完整的pom文件

<?xml version="1.0" encoding="UTF-8"?>4.0.0org.springframework.boot        spring-boot-starter-parent        2.1.1.RELEASEcom.qlu    cloud    0.0.1-SNAPSHOTcloudDemo project for Spring Boot1.8com.alibaba            fastjson            1.2.6org.springframework.boot            spring-boot-starter-data-jpa        org.springframework.boot            spring-boot-starter-web        org.mybatis.spring.boot            mybatis-spring-boot-starter            1.3.2org.springframework.boot            spring-boot-starter-test            testorg.springframework.boot            spring-boot-devtools            providedtrueorg.mybatis            mybatis            3.4.6org.mybatis.spring.boot            mybatis-spring-boot-starter            1.2.0mysql            mysql-connector-java        org.springframework.boot            spring-boot-starter-thymeleaf        org.springframework.boot            spring-boot-starter-thymeleaf        com.alibaba            druid-spring-boot-starter            1.1.9org.springframework.boot                spring-boot-maven-plugin            org.mybatis.generator                mybatis-generator-maven-plugin                1.3.5 mysql                         mysql-connector-java                        5.1.35org.mybatis.generator                        mybatis-generator-core                        1.3.5Generate MyBatis Artifactspackagegeneratetruetruesrc/main/resources/generator/generatorConfig.xml

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/394744.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/394744.shtml
英文地址,請注明出處:http://en.pswp.cn/news/394744.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

vr格式視頻價格_如何以100美元的價格打造自己的VR耳機

vr格式視頻價格by Maxime Coutte馬克西姆庫特(Maxime Coutte) 如何以100美元的價格打造自己的VR耳機 (How you can build your own VR headset for $100) My name is Maxime Peroumal. I’m 16 and I built my own VR headset with my best friends, Jonas Ceccon and Gabriel…

python_裝飾器

# 裝飾器形成的過程 : 最簡單的裝飾器 有返回值得 有一個參數 萬能參數# 裝飾器的作用# 原則 &#xff1a;開放封閉原則# 語法糖&#xff1a;裝飾函數名# 裝飾器的固定模式 import time # time.time() # 獲取當前時間 # time.sleep() # 等待 # 裝飾帶參數的裝飾器 def timer…

歐洲的數據中心與美國的數據中心如何區分?

人會想到這意味著&#xff0c;在歐洲和北美的數據中心的設計基本上不會有大的差異。不過&#xff0c;一些小的差異是確實存在的。您可能想知道為什么你需要了解歐洲和北美的數據中心之間的差異&#xff0c;這對你的公司有幫助嗎?一個設計團隊往往能從另一個設計團隊那里學到東…

老農過河

java老農過河問題解決 http://www.52pojie.cn/thread-550328-1-1.html http://bbs.itheima.com/thread-141470-1-1.html http://touch-2011.iteye.com/blog/1104628 轉載于:https://www.cnblogs.com/wangjunwei/p/6032602.html

python isalnum函數_探究Python中isalnum()方法的使用

探究Python中isalnum()方法的使用 isalnum()方法檢查判斷字符串是否包含字母數字字符。 語法 以下是isalnum()方法的語法&#xff1a; str.isa1num() 參數 NA 返回值 如果字符串中的所有字符字母數字和至少有一個字符此方法返回 true&#xff0c;否則返回false。 例子 下面的例…

docker快速入門_Docker標簽快速入門

docker快速入門by Shubheksha通過Shubheksha Docker標簽快速入門 (A quick introduction to Docker tags) If you’ve worked with Docker even for a little while, I bet you’ve come across tags. They often look like “my_image_name:1” where the part after the col…

動態規劃算法——最長上升子序列

今天我們要講的是最長上升子序列&#xff08;LIS&#xff09;。【題目描述】給定N個數&#xff0c;求這N個數的最長上升子序列的長度。【樣例輸入】      【樣例輸出】7        42 5 3 4 1 7 6那么什么是最長上升子序列呢&#xff1f; 就是給你一個序列…

如何快速掌握一門新技術/語言/框架

IT行業中的企業特點是都屬于知識密集型企業。這種企業的核心競爭力與員工的知識和技能密切相關。而如果你在企業中扮演的是工程師的角色的話&#xff0c;那么 你的核心競爭力就是IT相關的知識與技能的儲備情況。而眾所周知&#xff0c;IT行業是一個大量產生新知識的地方&#x…

c語言今天星期幾問題,C語言輸入今天星期幾

滿意答案迷茫03222015.07.24采納率&#xff1a;55% 等級&#xff1a;9已幫助&#xff1a;665人123456789101112131415161718192021#include<stdio.h>int main(void){ enum weekday{ sun, mon, tue, wed, thu, fri, sat }; int n; printf("輸入星期數(0-…

備忘錄模式 詳解

定義 在不破壞封裝性的前提下&#xff0c;捕獲一個對象的內部狀態&#xff0c;并在該對象之外保存這個狀態&#xff1b; 行為型模式 角色 發起人角色&#xff08;Originator&#xff09;&#xff1a;記錄當前時刻的內部狀態&#xff0c;負責定義哪些屬于備份范圍的狀態&#xf…

dll oem證書導入工具_技術干貨 | 惡意代碼分析之反射型DLL注入

歡迎各位添加微信號&#xff1a;qinchang_198231 加入安全 交流群 和大佬們一起交流安全技術01技術概要這是一種允許攻擊者從內存而非磁盤向指定進程注入DLL的技術&#xff0c;該技術比常規的DLL注入更為隱蔽&#xff0c;因為除了不需要磁盤上的實際DLL文件之外&#xff0c;它…

像程序員一樣思考_如何像程序員一樣思考-解決問題的經驗教訓

像程序員一樣思考by Richard Reis理查德里斯(Richard Reis) 如何像程序員一樣思考-解決問題的經驗教訓 (How to think like a programmer — lessons in problem solving) If you’re interested in programming, you may well have seen this quote before:如果您對編程感興趣…

CF908G New Year and Original Order 數位DP

傳送門 看到數據范圍到\(10^{700}\)毫無疑問數位DP。那么我們最重要的問題是如何有效地維護所有數位排序之后的數的值。 對于某一個數\(x\)&#xff0c;設\(f_{x,i} (i \in [1,9])\)表示\(x\)中的所有數位的值\(\geq i\)的數位數量&#xff0c;比如說\(f_{6345982 , 7} 2 , f_…

銳捷亮相GITC:請互聯網企業為我點個贊!

【51CTO.com原創稿件】GITC全球互聯網技術大會已成功舉辦四屆&#xff0c;今年的會議現場依然是摩肩接踵圍觀者眾。圍繞互聯網熱點技術&#xff0c;眾人根據云、大數據、安全、運維、基礎架構的不同主題&#xff0c;各自聚成小圈子展開深入交流。 銳捷的展位在主會場的內側&…

c語言匯編混合編程方法,C語言和匯編語言混合編程方法

摘要&#xff1a; C語言是一種高級的面向過程的開發語言&#xff0c;匯編語言是一種低級的面向機器的編程語言。兩者在程序設計開發方面各有優劣&#xff0c;目前兩者的混合編程得到了廣泛的應用。本文通過具體的實例&#xff0c;說明了混合編程的基本方法&#xff0c;為C語言應…

WPF Slider設置整數

IsSnapToTickEnabled"True" 轉載于:https://www.cnblogs.com/Fred1987/p/6038608.html

api代理提取_了解提取API

api代理提取Interested in learning JavaScript? Get my ebook at jshandbook.com有興趣學習JavaScript嗎&#xff1f; 在jshandbook.com上獲取我的電子書 Since IE5 was released in 1998, we’ve had the option to make asynchronous network calls in the browser using X…

react.lazy 路由懶加載_React lazy/Suspense使用及源碼解析

React v16.6.0已經發布快一年了&#xff0c;為保障項目迭代發布&#xff0c;沒有及時更新react版本&#xff0c;最近由于開啟了新項目&#xff0c;于是使用新的react版本進行了項目開發。項目工程如何搭建&#xff0c;如何滿足兼容性要求&#xff0c;如何規范化等等這里不作為介…

Dart編程語言入門

Dart基礎入門語法介紹&#xff0c;詳細說明可以查看相關視頻《Dart編程語言入門》。 變量與常量 變量 1.使用 var 聲明變量,默認值為 null var a;//null a 10;2.顯示類型聲明 int a;//null a 10;3.使用 var 聲明&#xff0c;可賦予不同類型的值 var a; //null a 10; //int a…

《PHP精粹:編寫高效PHP代碼》——1.1節為什么要使用面向對象編程

本節書摘來自華章社區《PHP精粹&#xff1a;編寫高效PHP代碼》一書中的第1章&#xff0c;第1.1節為什么要使用面向對象編程&#xff0c;作者&#xff1a;&#xff08;美&#xff09;  Davey Shafik&#xff0c;更多章節內容可以訪問云棲社區“華章社區”公眾號查看 1.1 為什…