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
版权声明:本文为bigtree_3721原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。