ww_coding
ww_coding
采纳率100%
2017-05-15 13:59 浏览 8.4k
已采纳

mybatis mapper配置错误

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">



select * from user where id = #{id}

以上是我的mapper的xml配置文件
然后测试的时候报错 报错信息为:
org.apache.ibatis.exceptions.PersistenceException:

Error building SqlSession.

The error may exist in sqlmap/User.xml

Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 26; 必须为元素类型 "mapper" 声明属性 "namespace"。

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)
at com.nullException.mybatis.first.MybatisFirst.init(MybatisFirst.java:22)
at com.nullException.mybatis.first.Test.main(Test.java:8)

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 26; 必须为元素类型 "mapper" 声明属性 "namespace"。
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
... 3 more

初学者,问题可能很白痴,有了解的大神帮忙看一下哈

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • 已采纳
    jsu_9207 eumji 2017-05-15 14:38
    <?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.eumji.zblog.mapper.ArticleMapper">
    
    

    namespace="这是你对应的mapper的全路径"

    点赞 1 评论 复制链接分享
  • qq_18895659 AngusC· 2017-05-15 14:55

    如果你是接口型的namespace必须是接口全路径,因为当service层去请求Dao层接口的时候如果Mapper不是全路径,就相当于没有实现这个接口。

    点赞 1 评论 复制链接分享

相关推荐