为什么我的总是说设置参数时发生错误?

来源:5-3 一对多关系的配置 Ⅲ

慕用9049269

2016-08-24 17:25

代码配置: command.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="Command">

  <resultMap type="com.imooc.bean.Command" id="Command">

    <id column="c_id" jdbcType="INTEGER" property="id"/>

    <result column="name" jdbcType="VARCHAR" property="name"/>

    <result column="description" jdbcType="VARCHAR" property="description"/>

    <collection property="contentList"  resultMap="CommandContent.Content"/>

  </resultMap>

  

   <select id="queryCommandList" parameterType="com.imooc.bean.Command" resultMap="Command">

    select a.id c_id,a.name,a.description,b.id,b.content,b.command_id 

    from command a left join command_content b

    on a.id = b.command_id

    <where>

    <if test="name != null and !&quot;&quot;.equals(name.trim())">

    and a.name=#{name}

   </if>

   <if test="description != null and !&quot;&quot;.equals(description.trim())">

    and a.description like '%' #{description} '%'

   </if>

    </where>

  </select>

  </mapper>


错误信息:

2016-08-24 17:17:08,964 [http-apr-8080-exec-7] DEBUG [Command.queryCommandList] - ==>  Preparing: select a.id c_id,a.name,a.description,b.id,b.content,b.command_id from command a left join command_content b on a.id = b.command_id WHERE a.name=? 

2016-08-24 17:17:09,042 [http-apr-8080-exec-7] DEBUG [Command.queryCommandList] - ==> Parameters: test(String)

org.apache.ibatis.exceptions.PersistenceException: 

### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'contentList' in 'class com.imooc.bean.Command'

### The error may exist in com/imooc/config/sqlxml/Command.xml

### The error may involve Command.queryCommandList-Inline

### The error occurred while setting parameters

### SQL: select a.id c_id,a.name,a.description,b.id,b.content,b.command_id      from command a left join command_content b     on a.id = b.command_id      WHERE  a.name=?

### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'contentList' in 'class com.imooc.bean.Command'


at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)

at com.imooc.dao.CommandDao.queryCommandList(CommandDao.java:31)

at com.imooc.service.QueryService.queryByCommand(QueryService.java:58)

at com.imooc.servlet.AutoReplyServlet.doGet(AutoReplyServlet.java:26)

at com.imooc.servlet.AutoReplyServlet.doPost(AutoReplyServlet.java:34)


at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)


at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)

at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2462)

at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2451)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)


at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:619)

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'contentList' in 'class com.imooc.bean.Command'


at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:380)

at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:170)

at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:152)

at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:48)

at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.instantiateCollectionPropertyIfAppropriate(DefaultResultSetHandler.java:446)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:789)


at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:747)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:713)


at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:264)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)

at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)

at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)

at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)

at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)

at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)

... 25 more


代码配置:

<?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="Command">

  <resultMap type="com.imooc.bean.Command" id="Command">

    <id column="c_id" jdbcType="INTEGER" property="id"/>

    <result column="name" jdbcType="VARCHAR" property="name"/>

    <result column="description" jdbcType="VARCHAR" property="description"/>

    <collection property="contentList"  resultMap="CommandContent.Content"/>

  </resultMap>

  

   <select id="queryCommandList" parameterType="com.imooc.bean.Command" resultMap="Command">

    select a.id c_id,a.name,a.description,b.id,b.content,b.command_id 

    from command a left join command_content b

    on a.id = b.command_id

    <where>

    <if test="name != null and !&quot;&quot;.equals(name.trim())">

    and a.name=#{name}

   </if>

   <if test="description != null and !&quot;&quot;.equals(description.trim())">

    and a.description like '%' #{description} '%'

   </if>

    </where>

  </select>

  

</mapper>


写回答 关注

3回答

  • 琥珀川振早见
    2017-09-19 21:23:23

    请问这个问题你是怎么解决的呀,我也遇到了同样的问题。

  • 慕用9049269
    2016-08-24 18:55:19

    实体没有少属性啊,还是包错



    实体:command,

    public class Command {

    //指令id

    private Integer id;

    //指令名称

    private String name;

    //指令描述

    private String description;

    //一条指令对应的回复列表

    private List<CommandContent> contenList;

    public Integer getId() {

    return id;

    }

    public void setId(Integer id) {

    this.id = id;

    }

    public String getName() {

    return name;

    }

    public void setName(String name) {

    this.name = name;

    }

    public String getDescription() {

    return description;

    }

    public void setDescription(String description) {

    this.description = description;

    }

    public List<CommandContent> getContenList() {

    return contenList;

    }

    public void setContenList(List<CommandContent> contenList) {

    this.contenList = contenList;

    }

    }

    实体:command,

    public class CommandContent {

    //回复内容的ID

    private Integer id;

    //回复的内容

    private String content;

    //指令表的ID

    private Integer commandId;

    public Integer getId() {

    return id;

    }

    public void setId(Integer id) {

    this.id = id;

    }

    public String getContent() {

    return content;

    }

    public void setContent(String content) {

    this.content = content;

    }

    public Integer getCommandId() {

    return commandId;

    }

    public void setCommandId(Integer commandId) {

    this.commandId = commandId;

    }

    }


    配置信息:command.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="Command">

      <resultMap type="com.imooc.bean.Command" id="Command">

        <id column="c_id" jdbcType="INTEGER" property="id"/>

        <result column="name" jdbcType="VARCHAR" property="name"/>

        <result column="description" jdbcType="VARCHAR" property="description"/>

        <collection property="contentList"  resultMap="CommandContent.content"/>

      </resultMap>

      

       <select id="queryCommandList" parameterType="com.imooc.bean.Command" resultMap="Command">

        select a.id c_id,a.name,a.description,b.id,b.content,b.commandId 

        from command a left join command_content b

        on a.id = b.commandId

        <where>

        <if test="name != null and !&quot;&quot;.equals(name.trim())">

        and a.name=#{name}

       </if>

       <if test="description != null and !&quot;&quot;.equals(description.trim())">

        and a.description like '%' #{description} '%'

       </if>

        </where>

      </select>

    </mapper>

    错误信息:

    2016-08-24 18:48:04,035 [http-apr-8080-exec-2] DEBUG [Command.queryCommandList] - ==>  Preparing: select a.id c_id,a.name,a.description,b.id,b.content,b.commandId from command a left join command_content b on a.id = b.commandId WHERE a.name=? 

    2016-08-24 18:48:04,106 [http-apr-8080-exec-2] DEBUG [Command.queryCommandList] - ==> Parameters: test(String)

    org.apache.ibatis.exceptions.PersistenceException: 

    ### Error querying database.  Cause: java.lang.IllegalArgumentException: Result Maps collection does not contain value for CommandContent.content

    ### The error may exist in com/imooc/config/sqlxml/Command.xml

    ### The error may involve Command.queryCommandList-Inline

    ### The error occurred while setting parameters

    ### SQL: select a.id c_id,a.name,a.description,b.id,b.content,b.commandId      from command a left join command_content b     on a.id = b.commandId      WHERE  a.name=?

    ### Cause: java.lang.IllegalArgumentException: Result Maps collection does not contain value for CommandContent.content


    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)

    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)

    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)

    at com.imooc.dao.CommandDao.queryCommandList(CommandDao.java:31)

    at com.imooc.service.QueryService.queryByCommand(QueryService.java:58)

    at com.imooc.servlet.AutoReplyServlet.doGet(AutoReplyServlet.java:26)

    at com.imooc.servlet.AutoReplyServlet.doPost(AutoReplyServlet.java:34)


    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)


    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)

    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)

    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)

    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2462)

    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2451)

    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

    at java.lang.Thread.run(Thread.java:619)

    Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for CommandContent.content

    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:797)


    at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:550)

    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNestedResultMap(DefaultResultSetHandler.java:836)


    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:775)

    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:747)

    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:713)

    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:264)

    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)

    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)

    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)

    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)

    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)

    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)

    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)

    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)

    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)

    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)

    ... 25 more




    收拾好鑫情

    你写成contenList了,少了个t,应该是contentList

    2016-10-07 01:26:11

    共 1 条回复 >

  • 血色玫瑰之海
    2016-08-24 17:59:53

    你要·实体类里面是不是少了属性??可以再仔细看看,或者是不是属性名打错了


    席暖

    非常感谢你的回答,看了之后,我发现了自己程序的错误,我真是太马虎了

    2017-02-13 09:49:53

    共 1 条回复 >

通过自动回复机器人学Mybatis---基础版

微信公众号自动回复功能学习Mybatis,基础教程加案例实战方式学习

107412 学习 · 786 问题

查看课程

相似问题