环境
依赖
pom
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
配置
yml
spring:
datasource:
username: root
password: xxxxxxxx
url: jdbc:mysql://192.168.2.111:3306/xxx
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
代码
sql
<insert id="save" parameterType="com.xxx.xxx.xxx.entity.Article" useGeneratedKeys="true" keyProperty="id">
insert into
`article`(file_name, sub_title, description, file_type,
file_path, user_id, create_time, is_lock)
values
(#{fileName}, #{subTitle}, #{description}, #{fileType}, #{filePath}, #{userId}, #{createTime}, #{isLock})
</insert>
异常原因
配置信息异常,数据库连接信息中应该包含字符集,修改url后正常录入数据。jdbc:mysql://192.168.2.111:3306/mylog?userUnicode=true&characterEncoding=utf8