D:\All_jdk_package\jdk1.8.0_181_x64\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:E:\indelidea\IntelliJ IDEA 2018.2.5\lib\idea_rt.jar=54686:E:\indelidea\IntelliJ IDEA 2018.2.5\bin" -Dfile.encoding=UTF-8 -classpath "E:\indelidea\IntelliJ IDEA 2018.2.5\lib\idea_rt.jar;E:\indelidea\IntelliJ IDEA 2018.2.5\plugins\junit\lib\junit-rt.jar;E:\indelidea\IntelliJ IDEA 2018.2.5\plugins\junit\lib\junit5-rt.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\charsets.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\deploy.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\access-bridge-64.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\cldrdata.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\dnsns.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\jaccess.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\jfxrt.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\localedata.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\nashorn.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\sunec.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\sunjce_provider.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\sunmscapi.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\sunpkcs11.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\ext\zipfs.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\javaws.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\jce.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\jfr.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\jfxswt.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\jsse.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\management-agent.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\plugin.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\resources.jar;D:\All_jdk_package\jdk1.8.0_181_x64\jre\lib\rt.jar;C:\Users\yuanfeng\Desktop\myproject\mybatis\target\classes;D:\All_mavenVersion\apache-maven-3.0.5\repo\junit\junit\4.11\junit-4.11.jar;D:\All_mavenVersion\apache-maven-3.0.5\repo\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\All_mavenVersion\apache-maven-3.0.5\repo\org\mybatis\mybatis\3.4.5\mybatis-3.4.5.jar;D:\All_mavenVersion\apache-maven-3.0.5\repo\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.yuanfeng.test.TestMybatis,testSelectDynamic

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (com.yuanfeng.pojo.TeacherSql.getTeacher1). Cannot invoke a method that holds named argument(@Param) using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.
### Cause: org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (com.yuanfeng.pojo.TeacherSql.getTeacher1). Cannot invoke a method that holds named argument(@Param) using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.

    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
    at com.sun.proxy.$Proxy14.getById1(Unknown Source)
    at com.yuanfeng.test.TestMybatis.testSelectDynamic(TestMybatis.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (com.yuanfeng.pojo.TeacherSql.getTeacher1). Cannot invoke a method that holds named argument(@Param) using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.
    at org.apache.ibatis.builder.annotation.ProviderSqlSource.createSqlSource(ProviderSqlSource.java:124)
    at org.apache.ibatis.builder.annotation.ProviderSqlSource.getBoundSql(ProviderSqlSource.java:103)
    at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
    ... 29 more


Process finished with exit code -1
 

我出现这个问题是因为TeacherMapper 中的id为int,但是TeacherDynamicSql中方法的id为Integer,最后调整为相同的类型就可以了!