gpt4 book ai didi

java - 如何在maven项目中为sqlmapconfig.xml设置类路径

转载 作者:太空宇宙 更新时间:2023-11-04 13:27:32 24 4
gpt4 key购买 nike

我开始学习ibatis框架。我正在使用 Intellij 和 Maven。但也存在一些问题。我的主 java 类找不到我的 sql 配置 xml: enter image description here

我的SqlMapConfig.xml应该在哪个目录中?

最佳答案

我从未使用过 mybatis,但从文档看来,您需要将 XML 添加到包中,然后在 main 方法中引用路径。

http://mybatis.github.io/mybatis-3/java-api.html

String resource = "org/mybatis/builder/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory factory = builder.build(inputStream);

org/mybatis/builder/mybatis-config.xml 位于 src/main/java/

关于java - 如何在maven项目中为sqlmapconfig.xml设置类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32509723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com