写在前面
intellij idea集成了很多我们开发中常用的工具,linux连接,git,数据库操作…
这里我们介绍,idea集成数据库操作,并对sql可格式化…
通过命令,但是在合适的执行文件中…
ctrl alt l
1.1、建立连接,数据库服务器地址,账号,密码等…
1.2、基本操作,很多,增删改查,控制台sql编写等等
sql执行控制台,这里是格式化之后的,我们平时手写的sql都是没有格式化的,注意这里提供了输入框,操作占位符的参数也很方便…
那么这里的格式化的sql是怎么实现的呢??
这里的哈,idea的快捷键 ctrl + alt + l,就可以格式化sql
补充:解决idea的src目录下不能编译sql语句的xml配置文件的问题
一:正常配置下的情况
1.编译的目录下不会编译映射配置文件.xml,但是resources目录中的文件都被编译出来。
2.pom.xml文件的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
<?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> <!-- 导入jar包 1 .spring的jar包: 11 个 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> <!--导入jar包 2 .springmvc的jar包: 2 个 spring-web- 5.0 . 1 .release.jar spring-webmvc- 5.0 . 1 .release.jar 3 .mybatis的jar包: 13 个 mybatis- 3.4 . 2 .jar 依赖jar包 12 个 4 .mybatis和spring整合的jar包: 1 个 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> <!--导入jar包 5 .数据库驱动jar包: 1 个 mysql-connector-java- 5.1 . 7 -bin.jar 6 .数据源druid的jar包: 1 个 druid- 1.1 . 5 .jar 7 .jstl的jar包: 2 个 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> <!--导入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.控制台无报错且网页报错404 找不到,或者500如下错误。
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标签下配置该属性即可解决这个问题,但是要注意src前面不要加 / 。
一定不要写为:(/src/main/java)。
这样在编译目录下xml文件也被编译。
2.加入该配置后编译目录下有了映射配置文件,见上图iuserdao.xml。
控制台可以正常显示数据。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。
原文链接:https://blog.csdn.net/qq_42105629/article/details/104004538