![]() | 1 chenguoyu OP ![]() |
![]() | 3 azygote 2017-07-25 21:40:41 +08:00 把 mapper 文件放到 resources 文件夹下,再在 mybatis.cfg.xml 里面改 mapper location。IDEA 编译后默认会把 resources 下的文件放到 target 的 classpath 下,但是 src 下的只有.java 文件编译生成.class 文件放入 classpath 下,其他文件会忽略的。 |
![]() | 4 misaka19000 2017-07-25 21:41:27 +08:00 资源文件不是应该放在 resources 下吗,Maven 会帮你把 resources 文件夹的内容拷贝到 classes 文件夹下的 |
5 Cbdy 2017-07-25 21:41:28 +08:00 via Android 用构建工具控制构建 |
![]() | 6 chenguoyu OP @sunsulei <configuration> <!-- 配置 mybatis 运行环境 --> <properties resource="jdbc.properties"/> <typeAliases> <package name="com.cgy.entity"></package> </typeAliases> <environments default="development"> <environment id="development"> <!-- type="JDBC" 代表直接使用 JDBC 的提交和回滚设置 --> <transactionManager type="JDBC"></transactionManager> <!-- POOLED 表示支持 JDBC 数据源连接池 --> <!-- 数据库连接池,由 Mybatis 管理,数据库名是 mybatis,MySQL 用户名 root,密码为空 --> <dataSource type="POOLED"> <property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </dataSource> </environment> </environments> <mappers> <package name="com.cgy.dao"></package> </mappers> &t;/configuration> |
![]() | 7 wly19960911 2017-07-25 21:44:31 +08:00 via Android 把 xml 放进 resource 目录,properties 自己看看 mybatis 的 XML 怎么导入,通过 mapperLocations 指定一下目录。 然后 interface 上标注 @Mapper 注解,之后在配置类上使用 @MapperScan 扫描下 interface 即可注入。 |
![]() | 8 chenguoyu OP |
9 luban 2017-07-25 21:50:15 +08:00 via iPhone maven 的话加插件,现在在路上,如果我回去你还没解决的话,给你发代码 |
![]() | 10 mosliu 2017-07-25 21:56:32 +08:00 Pom.xml 里面 加上这个 文件就好了吧? <resources> <resource> <directory>src/to/UserMapper.xml </directory> </resource> </resources> |
![]() | 11 xmh51 2017-07-25 21:57:05 +08:00 maven 可用 <resource> <directory>${basedir}/src/main/java</directory> <filtering>false</filtering> <includes> <include>**/*.xml</include> </includes> </resource> 解决 |
![]() | 12 wly19960911 2017-07-25 21:58:11 +08:00 via Android @chenguoyu 没看懂你的意思,你意思是其他人用 eclipse 没有 resource 文件夹?不是 maven 工程项目? |
![]() | 13 chenguoyu OP @wly19960911 因为 eclipse 不需要把 mybatis 的 mapper.xml 放到 resources 中就可以编译到 classes 下,而 idea 如果全放到 resources 中就冲突了 |
![]() | 14 chenguoyu OP @mosliu 感谢已解决 在 pox.xml 中添加 <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build> 就可以了 |
![]() | 15 wly19960911 2017-07-25 22:21:00 +08:00 via Android @chenguoyu 这个跟 idea 还是 eclipse 无关,完全看 maven 的配置,因为你的 spring boot 项目就是这样配置的…我也单纯配过普通的和你说的一样的,现在 spring boot 习惯了也就这样了。 |
![]() | 16 MajorAdam 2017-07-26 10:29:21 +08:00 maven 配置 |