1. Mybatis中使用#与$的区别。
    #:预编译sql语句,类似于JDBC中PreparedStatement.防止sql的注入。获取值。
    $: 获取值直接拼接到sql语句中。安全性不高。获取的是表结构的信息。例如表名,列名等
    2. 表中的列名与类的属性名不同时。
    1. 查询的结果无法封装到该属性上。
    解决方案是:
    1. 为查询的列起别名 别名和属性名相同。
    Mapper.xml相关的sql语句 - 图1
    Mapper.xml相关的sql语句 - 图2
    1. 使用resultMap来解决。关联关联
    Mapper.xml相关的sql语句 - 图3

关联查询。
1. 链表的关联查询
映射文件:
Mapper.xml相关的sql语句 - 图4

Mapper.xml相关的sql语句 - 图5
Mapper.xml相关的sql语句 - 图6

sql语句的增删改查:

1.1添加

映射文件:
Mapper.xml相关的sql语句 - 图7
测试:
Mapper.xml相关的sql语句 - 图8
可获取添加的id值。
Mapper.xml相关的sql语句 - 图9

1.2 修改.

Mapper.xml相关的sql语句 - 图10
测试Mapper.xml相关的sql语句 - 图11
接口与映射文件一起使用。
1. 映射文件。
Mapper.xml相关的sql语句 - 图12
2.接口中Mapper.xml相关的sql语句 - 图13
1. 测试类中的代码Mapper.xml相关的sql语句 - 图14
Mybatis传入多个参数时的处理方式
Mapper.xml相关的sql语句 - 图15
Mapper.xml相关的sql语句 - 图16
Mapper.xml相关的sql语句 - 图17
可以直接使用map作为方法的参数。
Mapper.xml相关的sql语句 - 图18
Mapper.xml相关的sql语句 - 图19

模糊查询:

Mapper.xml相关的sql语句 - 图20

分页查询:

Mapper.xml相关的sql语句 - 图21

Mapper.xml相关的sql语句 - 图22

Mapper.xml相关的sql语句 - 图23

Mapper.xml相关的sql语句 - 图24
一对多。Mapper.xml相关的sql语句 - 图25

Mapper.xml相关的sql语句 - 图26

动态sql where+(choose+when+otherwise)
Mapper.xml相关的sql语句 - 图27
动态sql trim
Mapper.xml相关的sql语句 - 图28

动态sql set标志 用于修改。
update 表名 set 列名=值,列名=值 where 条件
Mapper.xml相关的sql语句 - 图29

foreach+sql
Mapper.xml相关的sql语句 - 图30

bind:Mapper.xml相关的sql语句 - 图31