问题一:### Error querying database. Cause: java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost:3306/mybatis01
肉眼可见的原因,是因为jdcb:mysql后面忘记加上分号:,属于低级错误!
<dataSource type="POOLED"> <property name="url" value="jdbc:mysql://localhost:3306/mybatis01"></property> </dataSource>
问题二:编写<property name="driver" value="com.mysql.jdbc.Driver"></property>时,com.后面并没有mysql
原因:没有点击Enable Auto-Import

问题三:### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause:
原因:是因为xml配置文件的namespace没有指定全限定接口名,光靠id是无法找到sql语句定位的,必须依靠namespace!!
<mapper namespace="com.itheima.dao.IUserDao">

问题四:泛型报错
原因:要先声明后使用 所以要在泛型前加 <泛型>

问题五:java.lang.Exception: No tests found matching Method testSaveUser(com.itheima.test.MybatisTest) from org.junit.internal.requests.ClassRequest@6267c3bb
原因:由于是get set 生成的方法属性,所以这里#{}里面写的是属性原名称,开头不用大写,如果是手动敲得,那就开头要大写,如Username
<insert id="saveUser" parameterType="com.itheima.domain.User">
insert into user(username,birthday,sex,address)values(#{username},#{birthday},#{sex},#{address});
</insert>
目前先总结到这里!
这篇博客详细分析了MyBatis配置中常见的错误及其原因,包括:JDBC连接字符串缺少分号、驱动类名拼写错误、XML配置文件namespace未指定全限定接口名以及泛型使用不当导致的问题。此外,还提到了单元测试方法名不匹配的错误。通过这些案例,读者可以更好地理解和避免在MyBatis开发中遇到的陷阱。
6018

被折叠的 条评论
为什么被折叠?



