为了账号安全,请及时绑定邮箱和手机立即绑定

### Error building SqlSession. ### The error may exist in com/imooc/config/sqlxml/Message.xml

错误信息:

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 

### Error building SqlSession.

### The error may exist in com/imooc/config/sqlxml/Message.xml

### The error occurred while processing mapper_resultMap[MessageResult]

### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/imooc/config/sqlxml/Message.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'VARCHAR'.  Cause: java.lang.ClassNotFoundException: Cannot find class: VARCHAR

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)

at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:36)

at com.imooc.db.DBAccess.getSqlSession(DBAccess.java:21)

at com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:32)

at com.imooc.dao.MessageDao.main(MessageDao.java:48)

<?xml version="1.0" encoding="UTF-8" ?>

 configuration的代码

<!DOCTYPE configuration

    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

    "http://mybatis.org/dtd/mybatis-3-config.dtd">


<configuration>

<!--   <settings>

    <setting name="useGeneratedKeys" value="false"/>

    <setting name="useColumnLabel" value="true"/>

  </settings>


  <typeAliases>

    <typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>

  </typeAliases>

 -->

  <environments default="development">

    <environment id="development">

      <transactionManager type="JDBC">

        <property name="" value=""/>

      </transactionManager>

      <dataSource type="UNPOOLED">

        <property name="driver" value="com.mysql.jdbc.Driver"/>

        <property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/>

        <property name="username" value="root"/>

        <property name="password" value="1234"/>

      </dataSource>

    </environment>

  </environments>


  <mappers>

    <mapper resource="com/imooc/config/sqlxml/Message.xml"/>

  </mappers>


</configuration>

message.xml代码

<?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="Message">

<resultMap type="com.imooc.bean.Message" id="MessageResult">

<id column="ID" jdbcType="INTEGER" property="id" />

<result column="COMMAND" javaType="VARCHAR" property="command" />

<result column="DESCRIPTION" javaType="VARCHAR" property="description" />

<result column="CONTENT" javaType="VARCHAR" property="content" />

</resultMap>

<select id="queryMessageList" resultMap="MessageResult">

select ID,COMMAND,DESCRIPTION,CONTENT from message where 1=1

</select>

</mapper>

 DBAccess 代码

public class DBAccess {

public SqlSession getSqlSession() throws IOException{

//通过配置文件获取数据库连接信息

Reader reader = Resources.getResourceAsReader("com/imooc/config/Configuration.xml");

//通过配置信息来构造一个SqlSessionFactory

SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

//通过sqlSessionFactory打开一个会话

SqlSession sqlSession = sqlSessionFactory.openSession();

return sqlSession;

}

}

https://img1.sycdn.imooc.com//5c3572b20001649c06760372.jpg

正在回答

4 回答

<typeAliases>

    <typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>

  </typeAliases>

这个加个注释试下

1 回复 有任何疑惑可以回复我~

检查下你的实体类的类型和数据库表里面的类型是否都对应的上,int和vachar都对应得上

0 回复 有任何疑惑可以回复我~
#1

淋雨明天 提问者

检查过了,对应上的,我是跟着视频敲的代码,不知道哪里出问题
2019-01-10 回复 有任何疑惑可以回复我~

全部跟视频的一样的,照着打的

https://img1.sycdn.imooc.com//5c35b79300017a4502330327.jpg

0 回复 有任何疑惑可以回复我~

把你项目的结构贴出来,有可能没找到这个文件

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

### Error building SqlSession. ### The error may exist in com/imooc/config/sqlxml/Message.xml

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信