org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

程柯梦想 2015-12-03 05:42:15
spring+mybatis 运用tk.mybaits和分页插件
我想测试下mapper接口语句是否
异常:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zy.m.mapper.ClientMapper.queryForList
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:43)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
at sun.proxy.$Proxy48.queryForList(Unknown Source)
at com.zy.m.mapper.test.ClientMapperTest.testnull(ClientMapperTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

测试类:
package com.zy.m.mapper.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zy.m.domain.Client;
import com.zy.m.mapper.ClientMapper;

import junit.framework.TestCase;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-config.xml")
public class ClientMapperTest extends TestCase {

@Autowired
private SqlSession sqlSession;
@Test
public void testnull() {
ClientMapper clientMapper = sqlSession.getMapper(ClientMapper.class);
PageHelper.startPage(1,20);
List<Client> list = clientMapper.queryForList(null);
assertEquals(20, list.size());
assertEquals(183, ((Page) list).getTotal());
System.out.println(list);
}
}
mapper接口
package com.zy.m.mapper;

import java.util.List;

import com.kkl.framework.base.CommonMapper;
import com.zy.m.domain.Client;

import tk.mybatis.mapper.entity.Example;

public interface ClientMapper extends CommonMapper<Client> {


List<Client> queryForList(Example example);
}
...全文
1048 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
程柯梦想 2015-12-03
  • 打赏
  • 举报
回复
mpper.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.zy.m.mapper.ClientMapper"> <resultMap id="BaseResultMap" type="com.zy.m.domain.Client"> <!-- WARNING - @mbggenerated --> <id column="id" property="id" jdbcType="BIGINT" /> <result column="client_name" property="clientName" jdbcType="VARCHAR" /> <result column="password" property="password" jdbcType="VARCHAR" /> <result column="email" property="email" jdbcType="VARCHAR" /> <result column="mobile" property="mobile" jdbcType="VARCHAR" /> <result column="salt" property="salt" jdbcType="VARCHAR" /> <result column="client_type" property="clientType" jdbcType="TINYINT" /> <result column="company_name" property="companyName" jdbcType="VARCHAR" /> <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> <result column="status" property="status" jdbcType="TINYINT" /> <result column="yn" property="yn" jdbcType="TINYINT" /> <result column="memo" property="memo" jdbcType="VARCHAR" /> <result column="operate_userid" property="operateUserid" jdbcType="BIGINT" /> <result column="operate_time" property="operateTime" jdbcType="TIMESTAMP" /> </resultMap> <resultMap id="queryForListMap" type="com.zy.m.domain.Client"> <id column="id" property="id" jdbcType="BIGINT" /> <result column="client_name" property="clientName" jdbcType="VARCHAR" /> <result column="password" property="password" jdbcType="VARCHAR" /> <result column="email" property="email" jdbcType="VARCHAR" /> <result column="mobile" property="mobile" jdbcType="VARCHAR" /> <result column="salt" property="salt" jdbcType="VARCHAR" /> <result column="client_type" property="clientType" jdbcType="TINYINT" /> <result column="company_name" property="companyName" jdbcType="VARCHAR" /> <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> <result column="status" property="status" jdbcType="TINYINT" /> <result column="yn" property="yn" jdbcType="TINYINT" /> <result column="memo" property="memo" jdbcType="VARCHAR" /> <result column="operate_userid" property="operateUserid" jdbcType="BIGINT" /> <result column="operate_time" property="operateTime" jdbcType="TIMESTAMP" /> <collection property="clientDetails" javaType="java.util.List" ofType="com.zy.m.domain.ClientDetails"> <id column="d_id" property="id" jdbcType="BIGINT" /> <result column="sex" property="sex" jdbcType="BIT" /> <result column="area" property="area" jdbcType="VARCHAR" /> <result column="province" property="province" jdbcType="VARCHAR" /> <result column="city" property="city" jdbcType="VARCHAR" /> <result column="file_path1" property="filePath1" jdbcType="VARCHAR" /> <result column="file_path2" property="filePath2" jdbcType="VARCHAR" /> <result column="file_path3" property="filePath3" jdbcType="VARCHAR" /> <result column="file_path4" property="filePath4" jdbcType="VARCHAR" /> <result column="d_status" property="status" jdbcType="TINYINT" /> <result column="bill_company" property="billCompany" jdbcType="VARCHAR" /> <result column="d_memo" property="memo" jdbcType="VARCHAR" /> <result column="d_operate_time" property="operateTime" jdbcType="TIMESTAMP" /> <result column="d_operate_userid" property="operateUserid" jdbcType="BIGINT" /> </collection> </resultMap> <sql id="Example_Where_Clause" > <where > <foreach collection="oredCriteria" item="criteria" separator="or" > <if test="criteria.valid" > <trim prefix="(" suffix=")" prefixOverrides="and" > <foreach collection="criteria.criteria" item="criterion" > <choose > <when test="criterion.noValue" > and ${criterion.condition} </when> <when test="criterion.singleValue" > and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue" > and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue" > and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <select id="queryForList" resultMap="queryForListMap" parameterType="tk.mybatis.mapper.entity.Example"> SELECT <if test="distinct" > distinct </if> c.id, c.client_name, c.password, c.email, c.mobile, c.salt, c.client_type, c.company_name, c.create_time, c.update_time, c.status, c.yn, c.memo, c.operate_userid, c.operate_time, d.id d_id, d.client_id, d.sex, d.area, d.province, d.city, d.file_path1, d.file_path2, d.file_path3, d.file_path4, d.status d_status, d.bill_company, d.memo d_memo, d.operate_userid d_operate_userid, d.operate_time d_operate_time FROM client c LEFT JOIN client_details d ON c.id = d.client_id <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null" > order by ${orderByClause} </if> <if test="orderByClause == null" > order by id </if> </select> </mapper>
程柯梦想 2015-12-03
  • 打赏
  • 举报
回复
配置文件:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <context:property-placeholder location="classpath:resources.properties" /> <!-- 扫描注解Bean --> <context:component-scan base-package="com.zy.**.service,com.kkl.**.service"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!-- 开启AOP监听 只对当前配置文件有效 --> <aop:aspectj-autoproxy expose-proxy="true" /> <!-- 数据源 --> <!--see https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_DruidDataSource%E5%8F%82%E8%80%83%E9%85%8D%E7%BD%AE --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性 url、user、password --> <property name="url" value="${connection.url}" /> <property name="username" value="${connection.username}" /> <property name="password" value="${connection.password}" /> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="${druid.initialSize}" /> <property name="minIdle" value="${druid.minIdle}" /> <property name="maxActive" value="${druid.maxActive}" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="${druid.maxWait}" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" /> <property name="validationQuery" value="${druid.validationQuery}" /> <property name="testWhileIdle" value="${druid.testWhileIdle}" /> <property name="testOnBorrow" value="${druid.testOnBorrow}" /> <property name="testOnReturn" value="${druid.testOnReturn}" /> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 如果用Oracle,则把poolPreparedStatements配置为true,mysql可以配置为false。 --> <property name="poolPreparedStatements" value="${druid.poolPreparedStatements}" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="${druid.maxPoolPreparedStatementPerConnectionSize}" /> <!-- 配置监控统计拦截的filters --> <property name="filters" value="${druid.filters}" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations"> <array> <value>classpath:mapper/*.xml</value> </array> </property> <property name="typeAliasesPackage" value="com.zy.**.domain,com.kkl.**.domain" /> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageHelper"> <property name="properties"> <value> dialect=mysql offsetAsPageNum=true rowBoundsWithCount=true pageSizeZero=false reasonable=true </value> </property> </bean> </array> </property> </bean> <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.kkl.**.mapper,com.zy.**.mapper" /> <property name="properties"> <value> mappers = com.kkl.framework.base.CommonMapper</value> </property> </bean> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="select*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="get*" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config expose-proxy="true" proxy-target-class="true"> <aop:pointcut id="txPointcut" expression="execution(* com.kkl..service..*Service*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" /> </aop:config> <!-- 国际化的消息资源文件(本系统中主要用于显示/错误消息定制) --> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <!-- 在web环境中一定要定位到classpath 否则默认到当前web应用下找 --> <value>classpath:messages</value> <value>classpath:ValidationMessages</value> </list> </property> <property name="useCodeAsDefaultMessage" value="false" /> <property name="defaultEncoding" value="UTF-8" /> <property name="cacheSeconds" value="60" /> </bean> <!-- 以下 validator ConversionService 在使用 mvc:annotation-driven 会 自动注册 --> <!-- <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="providerClass" value="org.hibernate.validator.HibernateValidator" /> 如果不加默认到 使用classpath下的 ValidationMessages.properties <property name="validationMessageSource" ref="messageSource" /> </bean> --> <!-- 类型转换及数据格式化 --> <!-- <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/> --> <!--设置查询字符串转换器的conversion service --> <!-- <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="staticMethod" value="com.kkl.framework.search.util.SearchableConvertUtils.setConversionService" /> <property name="arguments" ref="conversionService" /> </bean> --> <!-- spring工具类 方便在非spring管理环境中获取bean --> <bean id="springUtils" class="com.kkl.framework.util.SpringUtil" /> <import resource="spring-config-ehcache.xml" /> <import resource="spring-config-shiro.xml" /> <import resource="spring-config-monitor.xml" /> </beans>

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧