forked from HappySnailSunshine/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMybatis.md
More file actions
1993 lines (1240 loc) · 72.1 KB
/
Copy pathMybatis.md
File metadata and controls
1993 lines (1240 loc) · 72.1 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Mybatis
自己总结这个过程是非常重要的,自己总结自己思考才知道自己学会了没有。
> 学习进度,第三个 10分钟
# Bilibili 狂神说
## 简介
### 什么是 MyBatis

- MyBatis 是一款优秀的**持久层框架**
- 它支持自定义 SQL、存储过程以及高级映射
- MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作
- MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,
普通老式 Java 对象)为数据库中的记录。
- MyBatis 本是[apache](https://baike.baidu.com/item/apache/6265)的一个开源项目[iBatis](https://baike.baidu.com/item/iBatis), 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis 。2013年11月迁移到Github
- 2013年11月迁移到Github。
#### 如何获取
- Maven仓库:
```xml
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
```
- Github:https://github.com/mybatis/mybatis-3.git
- 中文文档:https://mybatis.org/mybatis-3/zh/index.html
### 持久化
数据持久化
- 持久化就是将程序的数据在持久状态和瞬时状态转换的过程
- 内存 断电即失去
- 数据库(JDBC):IO文件持久化
为什么要持久化?
- 有一些对象不能让他丢掉
- 内存太贵啦
### 持久层
Dao层,Service层,Controller层....
- 完成持久化工作的代码块
- 层界限十分明显
### 为什么要用Mybatis?
- 帮助程序员将数据存入数据库。
- 方便
- 传统的JDBC太复杂了,简化,框架,自动化。
- 不用Mybatis也行,使用了更加方便。技术本身没有高低之分,只有使用技术的人有高低之分。
- 优点
- 简单易学
- 灵活
- 解除sql与程序代码的耦合
- 提供映射标签
- 提供对象关系映射标签,支持对象关系组建维护
- 提供xml标签,支持编写动态sql。
**最重要的一点:使用的人多。**
42分钟
## 第一个Mybatis程序
### Mybatis配置文件
```xml
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--加载配置文件-->
<properties resource="db.properties">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://47.92.208.93:3306/mybatis?useUnicode=true&characterEncoding=utf-8"/>
</properties>
<!--别名-->
<typeAliases>
<!--<typeAlias type="com.cskaoyan.bean.User" alias="userz"/>-->
<!--别名是类名的小写形式 user car UserDetail userdetail-->
<package name="com.cskaoyan.bean"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/><!--MANAGED-->
<dataSource type="POOLED"><!--池-->
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<!--mybatis的映射文件 sql和代码进行分离-->
<!--下面是常使用的几种方式,都可以找到UserMapper-->
<mappers>
<!--下面的一个一个放开测试-->
<!--相对于classpath下的映射文件的路径-->
<mapper resource="com/cskaoyan/mapper/UserMapper.xml"/>
<!--class→对应接口的全类名-->
<!--<mapper class="com.cskaoyan.mapper.UserMapper"/>-->
<!--url-->
<!--<mapper url="file:\\\D:\JavaEEWorkplace\mybatis2\demo01_mapper\src\main\resources\com\cskaoyan\mapper\UserMapper.xml"/>-->
<!--使用扫描包的实行加载映射文件-->
<!--<package name="com.cskaoyan.mapper"/>--> <!--使用的配置-->
</mappers>
</configuration>
```
里面吧数据库需要的驱动,URL,用户名,密码弄上。可以写死,也可以写在配置文件中,参考mybatis2。
### 实体类
```java
public class User {
private int id;
private String username;
private String password;
private int age;
private String gender;
//省略setter和getter
}
```
### mapper
接口
### UserMapper.xml
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace要等于接口的全类名-->
<mapper namespace="com.cskaoyan.mapper.UserMapper">
<!--根据id查询用户-->
<select id="queryUserById" resultType="com.cskaoyan.bean.User">
select id,username,password,age,gender from user where id = #{id}
</select>
<!--插入用户-->
<insert id="insertUser">
insert into user (username,password,age,gender) values (
#{username},
#{password},
#{age},
#{gender}
)
</insert>
<!--根据id删除用户-->
<delete id="deleteUserById">
delete from user where id = #{id}
</delete>
</mapper>
```
## CRUD
### namespace
namespace中的包名要和Dao/mapper接口的包名一致。
### select
选择,查询语句
- id:就是对相应namespace中的方法名
- resultType:SQL执行的返回值
- parameterType: 参数类型
# Mybatis
## Mybatis入门
### Mybatis入门案例2

写单元测试的时候,可以直接通过SqlSession获得dao层接口的实例

当我们去写一个接口中的方法,一定要有对应的标签与之对应
通过,如果新增标签可以不写对应的接口中的方法
### Mybatis配置文件
#### Properties

#### Setting
缓存
懒加载→多表查询
#### typeAliases(别名→小名)
com.cskaoyan.bean.User→user
resultType、parameterType(不写)


#### typeHandler(类型转换)
#### plugins(插件)
pageHelper分页的插件
#### mappers的配置

## log4j 日志
springboot日志
日志级别
格式
1. 导包2、引入日志的配置文件
### 导包

### 引入配置文件



其中他们之间的优先级是有一个等级划分的!如果输出的是优先级为7的debug,则,控制台会输出他和他以下优先级的所有日志! 下面的优先级来自互联网,和上面的优先级有出入!以后看书学习正确的!......
FATAL 0
ERROR 3
WARN 4
INFO 6
DEBUG 7
### 格式

%d 日期(date)ABSOLUTE(这是一个格式名)
%5p 优先级(privilege)5代表使用5个占位符
%c{1}+方法名 顺序从后往前取
%L 行号
%m 消息 输出的日志信息
%n 换行
### 输出自定义的日志
Logger

## 映射
### 输入映射(重点)
#### 没有注解
##### 基本类型

##### Javabean

##### Map

##### 多个参数


##### List或数组(讲sql标签的时候补充这一部分)
##### 使用注解来输入映射
\@Param 出现在dao层,在方法对应的参数前

在@param注解里面写了什么,在映射文件中就可以用什么
### 输出映射(重点)
#### 简单类型
#### Pojo类型

查询结果的列名,(而不是表的列名),和javabean的成员变量名对应
#### List或者数组
##### 基本类型 list或array

##### Javabean list或array

#### resultMap
输出结果的封装
将查询结果的列名和javabean的成员变量名建立联系

## Sql标签、动态sql
### Where标签
成对存在,两个标签之间放条件

Where标签可以帮我们去掉他紧跟着的第一个关系词

### If
这个标签中,如果if不成立,前面的and,标签会自动维护,就会取消的!不会出现异常!
如果写在标签中,>
```xml
> 表示>
```

### Trim

### Choose when
If和else

### Sql

### SelectKey
主要做的是赋值的操作 怎么找到返回来的这个id在?????

上面是以前学习的时候的笔记
下面是代码中的具体使用 : 有效
1.mapper.xml层是这么写的没有问题

返回来怎么用呢?
返回结果是直接不是返回给id 而是将id 直接赋值给了goods里面的id,你在使用的时候直接从goods里面拿出来就可以啦.

测试结果:是有效的

### Foreach


## 多表查询
### 一对一
#### Javabean关系维护

#### 表关系维护

#### 执行查询
##### 分次查询

##### 连接查询

### 一对多
#### Javabean关系维护

#### 表关系维护

#### 执行查询
##### 分次查询

##### 连接查询
首先查出全部的数据,接着进行封装


### 多对多
双向的一对多
#### Javabean关系维护
维护双向一对多,在各自bean中维护另一个bean的list

#### 表关系的维护
通过一张中间表维护互相之间的关系

#### 执行查询
##### 分次查询


##### 连接查询


### 分次和连接查询的limit
一对多查询中
分次查询limit限制的是左一的数据数
连接查询limit限制的是右多的数据数
## Orm层的优化
### 懒加载
分次查询的使用场景、默认没有开启懒加载、需要手动开启
当setting中lazyLoadingEnabled= true时,分次查询已经开启了懒加载

开启懒加载开关后,默认分次查询都为懒加载;如果需要开启立即加载,需要让association或collection标签的fetchType属性为eager

### 缓存
#### 一级缓存
会话级别:同一个sqlSession
默认开启一级缓存


#### 二级缓存
3件事情:
1. 开启缓存开关
2. Javabean增加序列化的接口
3. 映射文件中增加缓存标签

> sqlSession.commit时存入二级缓存
> 执行cud操作时,清空二级缓存
## Alias
在类上出现定义别名

## 使用注解替代部分标签
CRUD
## 逆向工程mybatis generator
数据库中的表→Bean mapper mapper.xml

要想用mybatis代码生成器生成对象 要导入这两个依赖
```xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
```
需要注意的点为:逆向工程生成器,所指定的generatorConfig.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.3.200:3306/litemalltest"
userId="root"
password="123456">
<!--是否去除同名表 这句话一定要加上-->
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!--下面这些是oracle中用的配置-->
<!--<!–
for oracle
–>
<jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
userId="yycg"
password="yycg">
</jdbcConnection>-->
<!-- 默认false,
为false把JDBC DECIMAL 和 NUMERIC 类型解析为Integer,
为 true把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal -->
<!--<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>-->
<!-- javaModelGenerator javaBean生成的配置信息
targetProject:生成PO类的位置
targetPackage:生成PO类的类名-->
<javaModelGenerator targetPackage="com.cskaoyan.bean"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否允许子包,是否让schema作为包的后缀
即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值是否清理前后的空格 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--sqlMapGenerator Mapper映射文件的配置信息
targetProject:mapper映射文件生成的位置
targetPackage:生成mapper映射文件放在哪个包下-->
<sqlMapGenerator targetPackage="com.cskaoyan.mapper"
targetProject=".\src\main\resources">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--javaClientGenerator 生成 Model对象(JavaBean)和 mapper XML配置文件 对应的Dao代码
targetProject:mapper接口生成的位置
targetPackage:生成mapper接口放在哪个包下
ANNOTATEDMAPPER
XMLMAPPER
MIXEDMAPPER
-->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.cskaoyan.mapper"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true"/>
</javaClientGenerator><!---->
<!-- 指定数据库表 -->
<!-- 指定所有数据库表 -->
<!--<table tableName="%"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
enableInsert="false"
enableDeleteByPrimaryKey="true"
enableSelectByPrimaryKey="true"
selectByExampleQueryId="false" ></table>-->
<!-- 指定数据库表,要生成哪些表,就写哪些表,要和数据库中对应,不能写错! -->
//这下面 如果将ByExample全部false,那么生成的代码,就没有example
<!--<table tableName="j16_user_t"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
enableInsert="true"
enableDeleteByPrimaryKey="true"
enableSelectByPrimaryKey="true"
selectByExampleQueryId="false"
domainObjectName="User"
></table>
<table tableName="j16_student_t" domainObjectName="Studentz"/>-->
<table tableName="litemall_goods" domainObjectName="LitemallGoods"/>
<table tableName="litemall_admin_store" domainObjectName="LitemallAdminStore"/>
<!--<table schema="" tableName="orders"></table>
<table schema="" tableName="items"></table>
<table schema="" tableName="orderdetail"></table>
-->
<!-- 有些表的字段需要指定java类型
<table schema="" tableName="">
<columnOverride column="" javaType="" />
</table> -->
</context>
</generatorConfiguration>
```

生成的bean对象是这个样子的,没有example。

只写了一个相对路径,这里要将下面的项目配置改成 如下:


generatorConfig.xml放在module下面就可以,配置里面,要将工作路径设置成module目录下面!
然后运行Generator中的main方法就可以啦!就可以啦!
//下面这是Mybatis-plus 代码逆向工程:
```java
package com.cskaoyan;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class Generator {
public void generator() throws Exception{
List<String> warnings = new ArrayList<String>();
boolean overwrite = true; //指向逆向工程配置文件
File configFile = new File("generatorConfig.xml");
System.out.println(configFile.getAbsolutePath());
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator =
new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
public static void main(String[] args) throws Exception {
try {
Generator generatorSqlmap = new Generator();
generatorSqlmap.generator();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
```
在实际项目开发中,不要在当前项目中使用逆向工程,会报错.
在其他项目中用逆向工程生成代码,然后拷进来
拷进来要注意:
1.修改包名和导入的包名等:

2.正确的mapper是这样的:

如果下面买有画红线,说明正确.
如果错误:
需要修改mapper.xml中的命名空间:

这些地方都修改好,修改好的标志是:

对应mapper的接口不是红色 说明正确.
### 逆向工程中的example(牛皮)

### example实例解析
mybatis的逆向工程中会生成实例及实例对应的example,example用于添加条件,相当where后面的部分
xxxExample example = new xxxExample();
Criteria criteria = new Example().createCriteria();

### 应用举例:
#### 1.查询
1.selectByPrimaryKey()
```java
User user = XxxMapper.selectByPrimaryKey(100); //相当于select * from user where id = 100
```
2.selectByExample() 和 selectByExampleWithBLOGs()
```java
UserExample example = new UserExample();
Criteria criteria = example.createCriteria();
criteria.andUsernameEqualTo("wyw");
criteria.andUsernameIsNull();
example.setOrderByClause("username asc,email desc");
List<?>list = XxxMapper.selectByExample(example);
//相当于:select * from user where username = 'wyw' and username is null order by username asc,email desc
```
注:在iBator逆向工程生成的文件XxxExample.java中包含一个static的内部类Criteria,Criteria中的方法是定义SQL 语句where后的查询条件。
#### 2.插入数据
1.insert()
```java
User user = new User();
user.setId("dsfgsdfgdsfgds");
user.setUsername("admin");
user.setPassword("admin")
user.setEmail("wyw@163.com");
XxxMapper.insert(user);
//相当于:insert into user(ID,username,password,email) values ('dsfgsdfgdsfgds','admin','admin','wyw@126.com');
```
#### 3.更新数据
1.updateByPrimaryKey()
```java
User user =new User();
user.setId("dsfgsdfgdsfgds");
user.setUsername("wyw");
user.setPassword("wyw");
user.setEmail("wyw@163.com");
XxxMapper.updateByPrimaryKey(user);
//相当于:update user set username='wyw', password='wyw', email='wyw@163.com' where id='dsfgsdfgdsfgds'
```
2.updateByPrimaryKeySelective()
```java
User user = new User();
user.setId("dsfgsdfgdsfgds");
user.setPassword("wyw");
XxxMapper.updateByPrimaryKey(user);
//相当于:update user set password='wyw' where id='dsfgsdfgdsfgds'
```
3.updateByExample() 和 updateByExampleSelective()
```java
UserExample example = new UserExample();
Criteria criteria = example.createCriteria();
criteria.andUsernameEqualTo("admin");
User user = new User();
user.setPassword("wyw");
XxxMapper.updateByPrimaryKeySelective(user,example);
//相当于:update user set password='wyw' where username='admin'
```
updateByExample()更新所有的字段,包括字段为null的也更新,建议使用 updateByExampleSelective()更新想更新的字段
#### 4.删除数据
1.deleteByPrimaryKey()
```java
XxxMapper.deleteByPrimaryKey(1); //相当于:delete from user where id=1
```
2.deleteByExample()
```java
UserExample example = new UserExample();
Criteria criteria = example.createCriteria();
criteria.andUsernameEqualTo("admin");
XxxMapper.deleteByExample(example);
//相当于:delete from user where username='admin'
```
#### 5.查询数据数量
1.countByExample()
```java
UserExample example = new UserExample();
Criteria criteria = example.createCriteria();
criteria.andUsernameEqualTo("wyw");
int count = XxxMapper.countByExample(example);
//相当于:select count(*) from user where username='wyw'
```
## 在XML中使用`<>`
在mapper.xml使用大于、小于等符号会和xml语法冲突,解决冲突有两种方式。
#### 方法一:
使用转义字符:
| 字符名称 | 字符符号 | 转义字符 |
| -------- | -------- | -------- |
| 大于号 | > | > |
| 小于号 | < | < |
| 与 | & | & |
| 单引号 | ' | ' |
| 双引号 | " | " |
注:使用转义字符需要把空格去掉。
#### 第二种方法:
使用<![CDATA[]]> 。因为xml格式遇到这种格式会把方括号里的内容原样输出,不进行解析,如:
`<>` 改成` <![CDATA[<>]]>`。
参考:
https://www.cnblogs.com/tujietg/p/12036025.html
# Mybatis-plus
idea中插件叫mybatisX
这个插件没有安装上!
大佬说,首先要让market加载出来,才可以搜索的!
舍友说,分页插件要和生成器生成的mapper , .xml等一起用!不能单独用!然后有时间试试!
**这个分页和逆向工程很像,wrapper后面的,下面代码不完整!然后看官方文档!**
```java
Page<SteveOrderInfo> page = new Page<>(steveOrder.getNewPage(),steveOrder.getPageSize());
EntityWrapper<SteveOrderInfo> wrapper = new EntityWrapper<>();
wrapper.eq("user_id", userId);