IDEA 格式化SQL代碼技巧分享
寫(xiě)在前面
IntelliJ IDEA集成了很多我們開(kāi)發(fā)中常用的工具,Linux連接,Git,數(shù)據(jù)庫(kù)操作…
這里我們介紹,IDEA集成數(shù)據(jù)庫(kù)操作,并對(duì)SQL可格式化…
通過(guò)命令,但是在合適的執(zhí)行文件中…
Ctrl Alt L
1.1、建立連接,數(shù)據(jù)庫(kù)服務(wù)器地址,賬號(hào),密碼等…
1.2、基本操作,很多,增刪改查,控制臺(tái)SQl編寫(xiě)等等
SQL執(zhí)行控制臺(tái),這里是格式化之后的,我們平時(shí)手寫(xiě)的SQL都是沒(méi)有格式化的,注意這里提供了輸入框,操作占位符的參數(shù)也很方便…
那么這里的格式化的SQL是怎么實(shí)現(xiàn)的呢??
這里的哈,IDEA的快捷鍵 Ctrl + Alt + L,就可以格式化SQL
補(bǔ)充:解決idea的src目錄下不能編譯SQL語(yǔ)句的xml配置文件的問(wèn)題
一:正常配置下的情況
1.編譯的目錄下不會(huì)編譯映射配置文件.xml,但是resources目錄中的文件都被編譯出來(lái)。
2.pom.xml文件的配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sly</groupId> <artifactId>hrm01</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>hrm01 Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!-- 導(dǎo)入jar包 1.spring的jar包:11個(gè) com.springsource.org.aopalliance-1.0.0.jar com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar spring-aop-5.0.1.RELEASE.jar spring-aspects-5.0.1.RELEASE.jar spring-beans-5.0.1.RELEASE.jar spring-context-5.0.1.RELEASE.jar spring-core-5.0.1.RELEASE.jar spring-expression-5.0.1.RELEASE.jar spring-jcl-5.0.1.RELEASE.jar spring-jdbc-5.0.1.RELEASE.jar spring-tx-5.0.1.RELEASE.jar --> <!-- https://mvnrepository.com/artifact/org.aopalliance/com.springsource.org.aopalliance --> <dependency> <groupId>org.aopalliance</groupId> <artifactId>com.springsource.org.aopalliance</artifactId> <version>1.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/com.springsource.org.aspectj.weaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>com.springsource.org.aspectj.weaver</artifactId> <version>1.6.4.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.0.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>5.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jcl</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>5.0.1.RELEASE</version> </dependency> <!--導(dǎo)入jar包 2.springmvc的jar包:2個(gè) spring-web-5.0.1.RELEASE.jar spring-webmvc-5.0.1.RELEASE.jar 3.MyBatis的jar包:13個(gè) mybatis-3.4.2.jar 依賴jar包12個(gè) 4.MyBatis和Spring整合的jar包:1個(gè) mybatis-spring-1.3.1.jar --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.1</version> </dependency> <!--導(dǎo)入jar包 5.數(shù)據(jù)庫(kù)驅(qū)動(dòng)jar包:1個(gè) mysql-connector-java-5.1.7-bin.jar 6.數(shù)據(jù)源druid的jar包:1個(gè) druid-1.1.5.jar 7.JSTL的jar包:2個(gè) jstl-1.1.2 .jar standard-1.1.2.jar --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.48</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.5</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <!--導(dǎo)入Tomcat的jar包--> <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-servlet-api --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>9.0.21</version> </dependency> </dependencies> <build> <finalName>hrm01</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
3.控制臺(tái)無(wú)報(bào)錯(cuò)且網(wǎng)頁(yè)報(bào)錯(cuò)404 找不到,或者500如下錯(cuò)誤。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userHandler': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IUserDao' defined in file [D:\Tomcat\apache-tomcat-9.0.27\webapps\hrm01_war\WEB-INF\classes\com\hrm\user\dao\IUserDao.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Wrong namespace. Expected 'com.hrm.user.dao.IUserDao' but found 'com.hrm.user.dao.UserDao'.
二、解決方案
1.在pom文件中的build標(biāo)簽下配置該屬性即可解決這個(gè)問(wèn)題,但是要注意src前面不要加 / 。
一定不要寫(xiě)為:(/src/main/java)。
這樣在編譯目錄下xml文件也被編譯。
2.加入該配置后編譯目錄下有了映射配置文件,見(jiàn)上圖IUserDao.xml。
控制臺(tái)可以正常顯示數(shù)據(jù)。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章
IDEA 開(kāi)發(fā)多項(xiàng)目依賴的方法(圖文)
這篇文章主要介紹了IDEA 開(kāi)發(fā)多項(xiàng)目依賴的方法(圖文),本文講一下關(guān)于使用IntelliJ IDEA基于Maven創(chuàng)建多模塊項(xiàng)目的實(shí)際開(kāi)發(fā),非常具有實(shí)用價(jià)值,需要的朋友可以參考下2018-10-10Java的stream流多個(gè)字段排序的實(shí)現(xiàn)
本文主要介紹了Java的stream流多個(gè)字段排序的實(shí)現(xiàn),主要是兩種方法,第一種是固定多個(gè)字段排序和第二種動(dòng)態(tài)字段進(jìn)行排序,具有一定的參考價(jià)值,感興趣的可以了解一下2023-10-10Java自定義注解實(shí)現(xiàn)數(shù)據(jù)脫敏
在實(shí)際開(kāi)發(fā)中經(jīng)常會(huì)遇到有一些信息不能全部展示用戶,需要隱藏(可以叫脫敏),所以本文為大家分享了利用自定義注解實(shí)現(xiàn)數(shù)據(jù)脫敏的示例代碼,需要的可以參考下2023-07-07解決java?try?throw?exception?finally遇上return?break?conti
這篇文章主要介紹了解決java?try?throw?exception?finally遇上return?break?continue造成異常丟失問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11Spring中的攔截器HandlerInterceptor詳細(xì)解析
這篇文章主要介紹了Spring中的攔截器HandlerInterceptor詳細(xì)解析,HandlerInterceptor 是 Spring 框架提供的一個(gè)攔截器接口,用于在請(qǐng)求處理過(guò)程中攔截和處理請(qǐng)求,需要的朋友可以參考下2024-01-01Spring Boot簡(jiǎn)介與快速搭建詳細(xì)步驟
SpringBoot其本身沒(méi)有添加什么新的技術(shù),就是整合了一些現(xiàn)有的框架,并提供了一些默認(rèn)的配置,就是這些默認(rèn)的配置,極大的提高了我們的開(kāi)發(fā)效率。這篇文章主要介紹了Spring Boot簡(jiǎn)介與快速搭建,需要的朋友可以參考下2021-05-05Java實(shí)現(xiàn)文件和base64流的相互轉(zhuǎn)換功能示例
這篇文章主要介紹了Java實(shí)現(xiàn)文件和base64流的相互轉(zhuǎn)換功能,涉及Java文件讀取及base64 轉(zhuǎn)換相關(guān)操作技巧,需要的朋友可以參考下2018-05-05java實(shí)現(xiàn)全局監(jiān)聽(tīng)鍵盤(pán)詳解
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)全局監(jiān)聽(tīng)鍵盤(pán)的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解下2024-01-01