org.apache.ibatis.builder.BuilderException: Could not find value method on SQL annotation

转载自  mybatis 注解引发的bug,org.apache.ibatis.builder.BuilderException: Could not find value method on SQL anno

Mybatis用注解开发且还用script标签

这种bug,网上一搜一大堆,但是都xml方式开发,大部分说的是返回类型或者入参类型对不上,而我是注解式开发。

先贴写出来的sql:

@Select({"<script>"
        ," select * "
        ,"   from table t"
        ,"    AND f.created_at >= to_date(#{paramMap.startDate}, 'yyyyMMddhh24miss')"
        ,"    AND f.created_at <= to_date(#{paramMap.endDate}, 'yyyyMMddhh24miss')"
        ,"</script>"
})


解决方法:把上面  的  <  换成转义字符 &lt; 就有ok了。

主要的表跟字段还有没有出错的where条件我已经简写了。这种注解式开发,如果加上script标签,代表该条sql以xml解析的方式解析映射,xml解析方式大家应该都知道,<  或者  >  应该都用转义字符,但是这里看起来是个String没在意,导致这个bug。最坑的不是这个,而且pom文件里的mybatis相关的jar包的版本也有点问题,在启动的时候不会报错,能启动成功,但是在你services调用dao层的时候就会报这个错。后来我把mybatis相关的jar版本指定了一个,在启动的时候就会报错,启动不成功,报的错误就是你那个dao文件解析失败,就是这个错误:

org.apache.ibatis.builder.BuilderException: Could not find value method on SQL annotation.  Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1807; The content of  elements must consist of well-formed character data or markup.
 

上一个回答的代码启动报错Error creating bean with name 'advertController' defined in file [E:\IdeaProjects\taihaolian\target\classes\com\ruifan\taihaolian\biz\controller\AdvertController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'advertServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'advertMapper' defined in file [E:\IdeaProjects\taihaolian\target\classes\com\ruifan\taihaolian\biz\mapper\AdvertMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [tk/mybatis/mapper/autoconfigure/MapperAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\IdeaProjects\taihaolian\target\classes\mapper\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Could not find value method on SQL annotation. Cause: org.apache.ibatis.builder.BuilderException: Error creating SqlSource for SqlProvider. Method 'selectByRoleAndPage' not found in SqlProvider 'org.apache.ibatis.annotations.SelectProvider'.
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值