# mybatis-test
**Repository Path**: kuwx/mybatis-test
## Basic Information
- **Project Name**: mybatis-test
- **Description**: mybatis从0搭建及mybatis使用中的问题
- **Primary Language**: Unknown
- **License**: BSD-2-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-03-07
- **Last Updated**: 2021-04-27
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# mybatis-test
mybatis功能测试
### mybatis 批量新增返回主键id
mysql 配置时,url
```
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
```
spring boot 下写mybatis 单元测试
```
@RunWith(SpringRunner.class)
@SpringBootTest
@EnableAutoConfiguration
class UserDaoTests {
@Resource
private UserDao userDao;
```
批量新增回返主键Id
```
insert into user(name)values
(#{item.name})
```
bug1: 整合 mybatis, 需要添加一些代码,未添加会启动报错
```
@SpringBootApplication
@MapperScan
public class MybatisTestApplication {
```
bug2: statment 找不到, pom.xml 未对resources目录扫描。或者,mapper-locations 路径不符合要求
```
mybatis:
mapper-locations: classpath:mapping/*Mapping.xml
```
bug3: 旧版本mybatis批量新增返回主键Id会报错,以下是修复的issue
https://github.com/mybatis/mybatis-3/pull/547
错误日志:
```
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException:
Error getting generated key or setting result to parameter object.
Cause: org.apache.ibatis.binding.BindingException:
Parameter 'articleHomeUserId' not found. Available parameters are [list, param1]
```
如果不需要返回主键
```
insert into country(countryname,countrycode)
VALUES
(#{country.countryname},#{country.countrycode})
```
如果需要,解决方法:更新更新版本Mybatis。或者使用 JDBC方式批量新增