# MybatisExample-XML
**Repository Path**: xiyg/mybatis-example-xml
## Basic Information
- **Project Name**: MybatisExample-XML
- **Description**: 极简 xml 版本保持映射文件的老传统,接口层只需要定义空方法,系统会自动根据方法名在映射文件中找对应的 Sql .
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-06-06
- **Last Updated**: 2023-06-06
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Java, SpringBoot, MyBatis, MySQL, Oracle
## README
# MybatisExample-XML
#### 配置
pom 文件和上个版本一样,只是application.properties新增以下配置
```
server:
port: 8088
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test1?serverTimezone=UTC
mybatis:
type-aliases-package: com.mybatis.sp.mybatisexamle_xml.pojo
config-location: classpath:mybatis-config/mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
```
```
@MapperScan("com.mybatis.sp.mybatisexamle_xml.mapper")
@SpringBootApplication
public class MybatisexamleXmlApplication {
public static void main(String[] args) {
SpringApplication.run(MybatisexamleXmlApplication.class, args);
}
}
```
指定了 Mybatis 基础配置文件和实体类映射文件的地址
mybatis-config.xml 配置
```
```
这里也可以添加一些 Mybatis 基础的配置
#### 添加 User 的映射文件
```
id, userName, passWord, user_sex, nick_name
INSERT INTO
users
(userName,passWord,user_sex)
VALUES
(#{userName}, #{passWord}, #{userSex})
UPDATE
users
SET
userName = #{userName},
passWord = #{passWord},
nick_name = #{nickName}
WHERE
id = #{id}
DELETE FROM
users
WHERE
id =#{id}
其实就是把上个版本中 Mapper 的 Sql 搬到了这里的 xml 中了
#### 编写 Mapper 层的代码
public interface UserMapper {
List getAll();
UserEntity getOne(Long id);
void insert(UserEntity user);
void update(UserEntity user);
void delete(Long id);
}
```
对比上一步,这里只需要定义接口方法
#### 使用
使用和上个版本没有任何区别,大家就看文章对应的示例代码吧