SqlMapConfig.xml 注意在mybatis8.0后要对数据库的url配置要额外增加时区
serverTimezone=GMT%2B8
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <!--mybatis的主配置文件--> <configuration> <!--配置环境--> <environments default="mysql"> <!--配置mysql的环境--> <environment id="mysql"> <!--配置事务类型--> <transactionManager type="JDBC"></transactionManager> <!--配置数据源(连接池)--> <dataSource type="POOLED"> <!--配置连接数据库4个基本信息--> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/eesy_mybatis?serverTimezone=GMT%2B8"/> <property name="username" value="root"/> <property name="password" value="nimahaoma49"/> </dataSource> </environment> </environments> <!--指定映射配置文件的位置,映射配置文件指的是每个dao独立的配置文件--> <mappers> <mapper resource="com/itheima/dao/IUserDao.xml"/> </mappers> </configuration>
对其中某个dao类的配置
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.itheima.dao.IUserDao"> <!--配置查询所有--> <select id="findAll" resultType="com.itheima.domain.User"> select * from user; </select> </mapper>