遇到的一些问题及解决方法
报错1
### Error building SqlSession.
### The error may exist in SQL Mapper Configuration
问题:在config.xml文件中没有填写type的值
解决方法如下代码:
<!-- 配置JDBC的事务管理 -->
<transactionManager type="JDBC"></transactionManager>
报错2
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: Unknown database 'mybatis'
### Cause: java.sql.SQLSyntaxErrorException: Unknown database 'mybatis'
问题:我的数据库叫mybatistest,而不是mybatis,在填写config.xml的url时写错了
解决方法如下代码:
<property name="url" value="jdbc:mysql://localhost:3306/mybatistest?serverTimezone=UTC&useUnicode=true&character=UTF-8"/>
其中&是&的转义字符,表示将以下三者并列
- serverTimezone=UTC
- useUnicode=true
- character=UTF-8
Mybatis的开发方式1——使用原生接口
Maven工程的配置文件pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</gro