springmvc+mybatis+mysql.我想配置mapper路径向下面这样。不用每次新建了一个 xml文件就添加一个。但是系统启动的时候报 Could not find resource cn/com/vobile/**/*_sqlmap_mysql.xml错误
<mappers>
<mapper resource="cn/com/vobile/**/*_sqlmap_mysql.xml" />
</mappers>
关于通用匹配是spring提供的ant匹配法,mybatis 没有这个功能。具体实现见:
AntPathMatcher
<mappers>
<mapper resource="cn/com/vobile/**/*_sqlmap_mysql.xml" />
</mappers>
怎么解决?
回答:
你的那个不能使用统配(ant匹配模式)。
例子:文档
|
1
2
3
4
|
<
bean
id
=
"sqlSessionFactory"
class
=
"org.mybatis.spring.SqlSessionFactoryBean"
>
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
<
property
name
=
"mapperLocations"
value
=
"classpath*:sample/config/mappers/**/*.xml"
/>
</
bean
>
|
例子如下:
public class AntPathMatcher extends Object implements PathMatcher
PathMatcher implementation for Ant-style path patterns.
Part of this mapping code has been kindly borrowed from Apache Ant.
The mapping matches URLs using the following rules:
?matches one character*matches zero or more characters**matches zero or more directories in a path{spring:[a-z]+}matches the regexp[a-z]+as a path variable named "spring"
Examples
com/t?st.jsp— matchescom/test.jspbut alsocom/tast.jsporcom/txst.jspcom/*.jsp— matches all.jspfiles in thecomdirectorycom/**/test.jsp— matches alltest.jspfiles underneath thecompathorg/springframework/**/*.jsp— matches all.jspfiles underneath theorg/springframeworkpathorg/**/servlet/bla.jsp— matchesorg/springframework/servlet/bla.jspbut alsoorg/springframework/testing/servlet/bla.jspandorg/servlet/bla.jspcom/{filename:\\w+}.jspwill matchcom/test.jspand assign the valuetestto thefilenamevariable

本文介绍如何在Spring MVC + MyBatis项目中正确配置Mapper路径,避免使用时需要为每个XML文件单独添加配置的问题,并提供了一种通配符方式来批量加载所有Mapper文件。
1416

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



