2013-01-08 26 views
8

Tôi có nhiều vấn đề với spring e mybatis. Đây là cấu hình mùa xuân của tôi: tôi có cùng cấu hình và ComuneMapper.java và ComuneMapper.xml vẫn nằm trong cùng một thư mục. nhưng tôi có tuy nhiên lỗi này Somebody to giúp meeeeemybatis IllegalArgumentException: Bộ sưu tập Bảng sao kê được ánh xạ không chứa giá trị

<?xml version="1.0" encoding="UTF-8"?> 
<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:webflow="http://www.springframework.org/schema/webflow-config" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
     http://www.springframework.org/schema/aop 
     http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-2.5.xsd 
     http://www.springframework.org/schema/webflow-config 
     http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd 
     http://www.springframework.org/schema/util 
     http://www.springframework.org/schema/util/spring-util-2.0.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:annotation-config /> 

    <!-- Scans the classpath of this application for @Components to deploy as beans --> 
    <context:component-scan 
     base-package="com.aieap" /> 

    <!-- Configures the @Controller programming model --> 
    <mvc:annotation-driven /> 


    <!-- Configurazione Spring MVC View Resolver --> 
    <bean 
     id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property 
      name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property 
      name="prefix" 
      value="/jsp/" /> 
     <property 
      name="suffix" 
      value=".jsp" /> 
    </bean> 

    <!-- Flow Handler Adapter --> 
    <bean 
     class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> 
     <property 
      name="flowExecutor" 
      ref="flowExecutor" /> 
    </bean> 

    <!-- Flow Handler Mapping --> 
    <bean 
     class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> 
     <property 
      name="flowRegistry" 
      ref="flowRegistry" /> 
    </bean> 

    <!-- Flow Executor --> 
    <webflow:flow-executor 
     id="flowExecutor" /> 

    <!-- Flow Registry --> 
    <webflow:flow-registry 
     id="flowRegistry" 
     flow-builder-services="flowBuilderServices"> 
     <!-- nonaut --> 
     <webflow:flow-location 
      id="home-nonaut" 
      path="/WEB-INF/flows/nonaut/home-nonaut.xml" /> 
     <webflow:flow-location 
      id="logout" 
      path="/WEB-INF/flows/nonaut/logout.xml" /> 

     <!-- aut --> 
     <webflow:flow-location 
      id="aut/home-aut" 
      path="/WEB-INF/flows/aut/home-aut.xml" /> 
     <webflow:flow-location 
      id="aut/nuova-domanda" 
      path="/WEB-INF/flows/aut/nuova-domanda.xml" /> 
     <webflow:flow-location 
      id="aut/invia-domanda" 
      path="/WEB-INF/flows/aut/invia-domanda.xml" /> 
     <webflow:flow-location 
      id="aut/nuovo-operatore-rer" 
      path="/WEB-INF/flows/aut/nuovo-operatore-rer.xml" /> 

    </webflow:flow-registry> 

    <webflow:flow-builder-services 
     id="flowBuilderServices" 
     view-factory-creator="viewFactoryCreator" /> 

    <bean 
     id="viewFactoryCreator" 
     class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"> 
     <property 
      name="viewResolvers"> 
      <list> 
       <ref 
        bean="viewResolver" /> 
      </list> 
     </property> 
     <property 
      name="useSpringBeanBinding" 
      value="true" /> 
    </bean> 

    <import resource="jdbc-context.xml" /> 


</beans> 

jdbc-context.xm:

<?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:p="http://www.springframework.org/schema/p" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd 
      "> 

    <context:property-placeholder 
     location="/WEB-INF/db.properties" /> 

    <!-- Enable annotation style of managing transactions --> 
    <tx:annotation-driven 
     transaction-manager="transactionManager" /> 

    <!-- Declare a datasource that has pooling capabilities --> 
    <bean 
     id="dataSource" 
     class="com.mchange.v2.c3p0.ComboPooledDataSource" 
     destroy-method="close" 
     p:driverClass="${jdbc.driver}" 
     p:jdbcUrl="${jdbc.url}" 
     p:user="${jdbc.username}" 
     p:password="$jdbc.password}" 
     p:acquireIncrement="10" 
     p:idleConnectionTestPeriod="60" 
     p:maxPoolSize="100" 
     p:maxStatements="50" 
     p:minPoolSize="10" /> 

    <!-- Declare a transaction manager --> 
    <bean 
     id="transactionManager" 
     class="org.springframework.jdbc.datasource.DataSourceTransactionManager" 
     p:dataSource-ref="dataSource" /> 


    <!-- define the SqlSessionFactory, notice that configLocation is not needed when you use MapperFactoryBean --> 
    <bean 
     id="sqlSessionFactory" 
     class="org.mybatis.spring.SqlSessionFactoryBean"> 
     <property 
      name="dataSource" 
      ref="dataSource" /> 
     <property 
      name="configLocation" 
      value="WEB-INF/mybatis/sqlmap-config.xml" /> 
    </bean> 

    <!-- scan for mappers and will automatically scan the whole classpath for xmls --> 
    <bean 
     class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
     <property name="sqlSessionFactory" ref="sqlSessionFactory" /> 
     <property name="basePackage" value="com.aieap.dao.mapper" /> 
    </bean> 

</beans> 

sqlmap-config.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE configuration 
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN" 
    "http://mybatis.org/dtd/mybatis-3-config.dtd"> 

<configuration> 
    <settings> 
     <!-- changes from the defaults --> 
     <setting name="lazyLoadingEnabled" value="false" /> 
    </settings> 
    <typeAliases> 
     <typeAlias type="com.aieap.model.Comuni" alias="comuni"/> 
    </typeAliases> 
</configuration> 

điều khiển:

package com.aieap.web.controller; 

import java.util.ArrayList; 
import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.apache.log4j.Logger; 

import com.aieap.dao.mapper.ComuniMapper; 
import com.aieap.model.Comuni; 
import com.aieap.model.OperatoriRer; 

@Controller 
public class OperatoriRerController { 

    @Autowired ComuniMapper comuniDao; 


    private static final Logger logger = Logger.getLogger(OperatoriRerController.class); 



    @RequestMapping("/aut/nuovo-operatore-rer") 
     public ModelMap start() { 

     Comuni comuni = comuniDao.selectByPrimaryKey(new Long(1)); 
     System.out.print(comuni); 
     OperatoriRer op = new OperatoriRer(); 
     op.setNome("ciccio"); 
     op.setCognome("cappuccio"); 
     ModelMap model = new ModelMap(); 
     model.addAttribute("OperatoriRer",op); 
     return model; 
     } 


    @RequestMapping("/aut/search-comune") 
     public ModelMap searchcomune() { 
     List<Comuni> comuniList = new ArrayList <Comuni>() ;   
     ModelMap model = new ModelMap(); 
     model.addAttribute("ComunuList",comuniList); 
     return model; 
     } 
} 

đây là lỗi:

GRAVE: Servlet.service() for servlet [dispatch] in context with path [/aieap] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.aieap.dao.mapper.ComuniMapper.selectByPrimaryKey] with root cause 
java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.aieap.dao.mapper.ComuniMapper.selectByPrimaryKey 
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:593) 
    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:393) 
    at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:160) 
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) 
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37) 
    at $Proxy9.selectByPrimaryKey(Unknown Source) 
    at com.aieap.web.controller.OperatoriRerController.start(OperatoriRerController.java:29) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687) 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 

please !!! ai đó giúp tôi tôi vô vọng !!!!!!!!!!!!!!!

Tôi đã quên. đây là ComuniMapper.java

package com.aieap.dao.mapper; 

import com.aieap.model.Comuni; 
import com.aieap.model.ComuniExample; 
import java.util.List; 
import org.apache.ibatis.annotations.Param; 

public interface ComuniMapper { 

    int countByExample(ComuniExample example); 
    int deleteByExample(ComuniExample example); 
    int deleteByPrimaryKey(Long idComune); 
    int insert(Comuni record); 
    int insertSelective(Comuni record); 
    List<Comuni> selectByExample(ComuniExample example); 
    Comuni selectByPrimaryKey(Long idComune); 

    /** 
    * This method was generated by MyBatis Generator. 
    * This method corresponds to the database table comuni 
    * 
    * @mbggenerated Tue Jan 08 16:52:16 CET 2013 
    */ 
    int updateByExampleSelective(@Param("record") Comuni record, @Param("example") ComuniExample example); 

    /** 
    * This method was generated by MyBatis Generator. 
    * This method corresponds to the database table comuni 
    * 
    * @mbggenerated Tue Jan 08 16:52:16 CET 2013 
    */ 
    int updateByExample(@Param("record") Comuni record, @Param("example") ComuniExample example); 

    /** 
    * This method was generated by MyBatis Generator. 
    * This method corresponds to the database table comuni 
    * 
    * @mbggenerated Tue Jan 08 16:52:16 CET 2013 
    */ 
    int updateByPrimaryKeySelective(Comuni record); 

    /** 
    * This method was generated by MyBatis Generator. 
    * This method corresponds to the database table comuni 
    * 
    * @mbggenerated Tue Jan 08 16:52:16 CET 2013 
    */ 
    int updateByPrimaryKey(Comuni record); 
} 

cuối ComuniMapper.xml này:

<?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.aieap.dao.mapper.ComuniMapper" > 
    <resultMap id="BaseResultMap" type="com.aieap.model.Comuni" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    <id column="ID_COMUNE" property="idComune" jdbcType="BIGINT" /> 
    <result column="CODICE_ISTAT" property="codiceIstat" jdbcType="VARCHAR" /> 
    <result column="DESCRIZIONE" property="descrizione" jdbcType="VARCHAR" /> 
    <result column="CAP" property="cap" jdbcType="VARCHAR" /> 
    <result column="CODICE_PROVINCIA" property="codiceProvincia" jdbcType="BIGINT" /> 
    <result column="COMUNE_SIGLA" property="comuneSigla" jdbcType="VARCHAR" /> 
    <result column="COMUNE_CFIS" property="comuneCfis" jdbcType="VARCHAR" /> 
    </resultMap> 
    <sql id="Example_Where_Clause" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    <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> 
    <sql id="Update_By_Example_Where_Clause" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    <where > 
     <foreach collection="example.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> 
    <sql id="Base_Column_List" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    ID_COMUNE, CODICE_ISTAT, DESCRIZIONE, CAP, CODICE_PROVINCIA, COMUNE_SIGLA, COMUNE_CFIS 
    </sql> 
    <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.aieap.model.ComuniExample" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    select 
    <if test="distinct" > 
     distinct 
    </if> 
    <include refid="Base_Column_List" /> 
    from comuni 
    <if test="_parameter != null" > 
     <include refid="Example_Where_Clause" /> 
    </if> 
    <if test="orderByClause != null" > 
     order by ${orderByClause} 
    </if> 
    </select> 
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    select 
    <include refid="Base_Column_List" /> 
    from comuni 
    where ID_COMUNE = #{idComune,jdbcType=BIGINT} 
    </select> 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    delete from comuni 
    where ID_COMUNE = #{idComune,jdbcType=BIGINT} 
    </delete> 
    <delete id="deleteByExample" parameterType="com.aieap.model.ComuniExample" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    delete from comuni 
    <if test="_parameter != null" > 
     <include refid="Example_Where_Clause" /> 
    </if> 
    </delete> 
    <insert id="insert" parameterType="com.aieap.model.Comuni" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    insert into comuni (ID_COMUNE, CODICE_ISTAT, DESCRIZIONE, 
     CAP, CODICE_PROVINCIA, COMUNE_SIGLA, 
     COMUNE_CFIS) 
    values (#{idComune,jdbcType=BIGINT}, #{codiceIstat,jdbcType=VARCHAR}, #{descrizione,jdbcType=VARCHAR}, 
     #{cap,jdbcType=VARCHAR}, #{codiceProvincia,jdbcType=BIGINT}, #{comuneSigla,jdbcType=VARCHAR}, 
     #{comuneCfis,jdbcType=VARCHAR}) 
    </insert> 
    <insert id="insertSelective" parameterType="com.aieap.model.Comuni" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    insert into comuni 
    <trim prefix="(" suffix=")" suffixOverrides="," > 
     <if test="idComune != null" > 
     ID_COMUNE, 
     </if> 
     <if test="codiceIstat != null" > 
     CODICE_ISTAT, 
     </if> 
     <if test="descrizione != null" > 
     DESCRIZIONE, 
     </if> 
     <if test="cap != null" > 
     CAP, 
     </if> 
     <if test="codiceProvincia != null" > 
     CODICE_PROVINCIA, 
     </if> 
     <if test="comuneSigla != null" > 
     COMUNE_SIGLA, 
     </if> 
     <if test="comuneCfis != null" > 
     COMUNE_CFIS, 
     </if> 
    </trim> 
    <trim prefix="values (" suffix=")" suffixOverrides="," > 
     <if test="idComune != null" > 
     #{idComune,jdbcType=BIGINT}, 
     </if> 
     <if test="codiceIstat != null" > 
     #{codiceIstat,jdbcType=VARCHAR}, 
     </if> 
     <if test="descrizione != null" > 
     #{descrizione,jdbcType=VARCHAR}, 
     </if> 
     <if test="cap != null" > 
     #{cap,jdbcType=VARCHAR}, 
     </if> 
     <if test="codiceProvincia != null" > 
     #{codiceProvincia,jdbcType=BIGINT}, 
     </if> 
     <if test="comuneSigla != null" > 
     #{comuneSigla,jdbcType=VARCHAR}, 
     </if> 
     <if test="comuneCfis != null" > 
     #{comuneCfis,jdbcType=VARCHAR}, 
     </if> 
    </trim> 
    </insert> 
    <select id="countByExample" parameterType="com.aieap.model.ComuniExample" resultType="java.lang.Integer" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    select count(*) from comuni 
    <if test="_parameter != null" > 
     <include refid="Example_Where_Clause" /> 
    </if> 
    </select> 
    <update id="updateByExampleSelective" parameterType="map" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    update comuni 
    <set > 
     <if test="record.idComune != null" > 
     ID_COMUNE = #{record.idComune,jdbcType=BIGINT}, 
     </if> 
     <if test="record.codiceIstat != null" > 
     CODICE_ISTAT = #{record.codiceIstat,jdbcType=VARCHAR}, 
     </if> 
     <if test="record.descrizione != null" > 
     DESCRIZIONE = #{record.descrizione,jdbcType=VARCHAR}, 
     </if> 
     <if test="record.cap != null" > 
     CAP = #{record.cap,jdbcType=VARCHAR}, 
     </if> 
     <if test="record.codiceProvincia != null" > 
     CODICE_PROVINCIA = #{record.codiceProvincia,jdbcType=BIGINT}, 
     </if> 
     <if test="record.comuneSigla != null" > 
     COMUNE_SIGLA = #{record.comuneSigla,jdbcType=VARCHAR}, 
     </if> 
     <if test="record.comuneCfis != null" > 
     COMUNE_CFIS = #{record.comuneCfis,jdbcType=VARCHAR}, 
     </if> 
    </set> 
    <if test="_parameter != null" > 
     <include refid="Update_By_Example_Where_Clause" /> 
    </if> 
    </update> 
    <update id="updateByExample" parameterType="map" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    update comuni 
    set ID_COMUNE = #{record.idComune,jdbcType=BIGINT}, 
     CODICE_ISTAT = #{record.codiceIstat,jdbcType=VARCHAR}, 
     DESCRIZIONE = #{record.descrizione,jdbcType=VARCHAR}, 
     CAP = #{record.cap,jdbcType=VARCHAR}, 
     CODICE_PROVINCIA = #{record.codiceProvincia,jdbcType=BIGINT}, 
     COMUNE_SIGLA = #{record.comuneSigla,jdbcType=VARCHAR}, 
     COMUNE_CFIS = #{record.comuneCfis,jdbcType=VARCHAR} 
    <if test="_parameter != null" > 
     <include refid="Update_By_Example_Where_Clause" /> 
    </if> 
    </update> 
    <update id="updateByPrimaryKeySelective" parameterType="com.aieap.model.Comuni" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    update comuni 
    <set > 
     <if test="codiceIstat != null" > 
     CODICE_ISTAT = #{codiceIstat,jdbcType=VARCHAR}, 
     </if> 
     <if test="descrizione != null" > 
     DESCRIZIONE = #{descrizione,jdbcType=VARCHAR}, 
     </if> 
     <if test="cap != null" > 
     CAP = #{cap,jdbcType=VARCHAR}, 
     </if> 
     <if test="codiceProvincia != null" > 
     CODICE_PROVINCIA = #{codiceProvincia,jdbcType=BIGINT}, 
     </if> 
     <if test="comuneSigla != null" > 
     COMUNE_SIGLA = #{comuneSigla,jdbcType=VARCHAR}, 
     </if> 
     <if test="comuneCfis != null" > 
     COMUNE_CFIS = #{comuneCfis,jdbcType=VARCHAR}, 
     </if> 
    </set> 
    where ID_COMUNE = #{idComune,jdbcType=BIGINT} 
    </update> 
    <update id="updateByPrimaryKey" parameterType="com.aieap.model.Comuni" > 
    <!-- 
     WARNING - @mbggenerated 
     This element is automatically generated by MyBatis Generator, do not modify. 
     This element was generated on Tue Jan 08 16:52:16 CET 2013. 
    --> 
    update comuni 
    set CODICE_ISTAT = #{codiceIstat,jdbcType=VARCHAR}, 
     DESCRIZIONE = #{descrizione,jdbcType=VARCHAR}, 
     CAP = #{cap,jdbcType=VARCHAR}, 
     CODICE_PROVINCIA = #{codiceProvincia,jdbcType=BIGINT}, 
     COMUNE_SIGLA = #{comuneSigla,jdbcType=VARCHAR}, 
     COMUNE_CFIS = #{comuneCfis,jdbcType=VARCHAR} 
    where ID_COMUNE = #{idComune,jdbcType=BIGINT} 
    </update> 
</mapper> 

Trả lời

0

Tôi đang sử dụng mybatis cách tương tự như bạn. Mã của bạn có vẻ ổn. Thậm chí tôi không chắc liệu có vấn đề với ánh xạ kiểu hay không. Hãy thử hai mẹo sau đây để khắc phục vấn đề của bạn:

  1. thay đổi loại java để mybtis bí danh a) "java.lang.Long" -> "dài", b) "com.aieap.model.Comuni" - > "comuni"

  2. cố gắng thêm bí danh thay vì ánh xạ XML @ org.apache.ibatis.type.Alias ​​("comuni") vào com.aieap.model.Comuni, loại bỏ xml typeAlias, thêm cấu hình mùa xuân vào org.mybatis.spring.SqlSessionFactoryBean của bạn:

Chúc may mắn, Martin

+0

cảm ơn phản hồi của bạn nhưng không hoạt động. Có thể có một số vấn đề trong thư viện: – user1671106

3

Xin chào vấn đề này thường được kết nối với vị trí người lập bản đồ. Vì vậy, cố gắng để thiết lập thuộc tính mapperLocation trong đậu của bạn:

<property name="mapperLocations" 
value="classpath*:pathWhereYouHaveMapper/*Mapper.xml" /> 

Hy vọng nó sẽ giúp!

7

Có thể có một số lý do ...!

  • -> SQL Cú pháp (có thể là một truy vấn nhỏ duy nhất có thêm "" ở cuối của chọn)

  • - Các vấn đề> Classpath, không thể giải quyết phụ thuộc jar

  • -> Ngoài ra, điều này có thể đến do vấn đề mã hóa tệp hoặc các ký tự xml bất hợp pháp được nhúng trong tệp '* Mapper.xml' của bạn. (để xem ra cho biên tập viên của bạn ..!)

quan trọng nhất bạn nên sử dụng cùng tên.

  • giao diện = xxx.yyy.mappers.SettingMapper.class
  • mapper file = /xxx/yyy/mappers/SettingMapper.xml
  • mapper namespace = xxx.yyy.mappers.SettingMapper
+1

Trong trường hợp của tôi, tôi đã chọn một chuỗi và đặt nó vào đối tượng ngày tháng. các loại kết quả không khớp. thay đổi để chọn một chuỗi trong trường chuỗi và lỗi được giải quyết. –

+0

Đúng vậy. Chúng tôi hy vọng nó sẽ quay trở lại ToString() nhưng nó sẽ không kích hoạt. – mahesh

+0

'java.lang.IllegalArgumentException: Bộ sưu tập các câu lệnh được ánh xạ không chứa giá trị cho com.ct ...' Tôi đã hitted vấn đề này trước đây. Nó có nghĩa là bộ sưu tập các câu lệnh được ánh xạ từ tệp '* ModelMapper.xml' không chứa phương thức được định nghĩa trong tệp' * ModelMapper.java' của bạn. Trong trường hợp của tôi, đôi khi nó được gây ra bởi sự không khớp giữa việc đặt tên tệp t xml và tệp java. – ZhaoGang

3

Điều này thường có nghĩa là mybatis không thể tìm thấy ánh xạ mà bạn tham chiếu. Có lẽ bạn quên để thêm các tập tin * Mapper.xml để mybatis-config.xml (mà là một tập tin cấu hình tiêu chuẩn cho MyBatis)

<mappers> 
    <mapper resource="org/mybatis/builder/AuthorMapper.xml"/> 
</mappers> 

Xem thêm trong tài liệu http://mybatis.github.io/mybatis-3/configuration.html#mappers

2

Trong trường hợp của tôi gì đã xảy ra có một tên là TYPO trong tên phương thức của tôi trong tệp ánh xạ xml. Khi tôi đã thay đổi tên DAO, tôi quên thay đổi trong xml, nó có thể giúp người khác.

+1

Ngoài ra 'parameterType' và' resultType' phải khớp chính xác sau khi tái cấu trúc. – DerMike

1

Trùng lặp id trong mapper.xml cũng ném ngoại lệ như vậy. Hy vọng điều này sẽ hữu ích.

0

Tôi gặp sự cố tương tự. Sau đó, tôi thấy rằng tất cả các yêu cầu có ánh xạ truy vấn được xác định trên mapper.xml đó có cùng lỗi.

Có thể là do xây dựng WAR không đúng hoặc triển khai không đúng với máy chủ. Dù sao, tôi đã xóa tệp WAR đó và được triển khai lại và nó đã hoạt động!

0

Tôi cũng đã xem ngoại lệ này. Trong trường hợp của tôi, tệp xml của người lập bản đồ đã có trong một tệp JAR được bao gồm trong classpath, nhưng bằng cách nào đó nó không thể được tìm thấy bởi MapperScannerConfigurer. Tôi đã biết điều này bằng cách đọc các bản ghi. Bạn nên đọc nhật ký và kiểm tra dòng của định dạng sau để biết liệu có bất kỳ người vẽ bản đồ nào được tìm thấy hay không. Tôi phải đưa đường dẫn gốc cho nó, sau đó nó tìm thấy người lập bản đồ của tôi.

PathMatchingResourcePatternResolver:423 - Resolved location pattern [classpath*:*.xml] to resources [URL [jar:file:/home/user/src/tomcat8/webapps/example/WEB-INF/lib/ExampleDao-1.0.0-SNAPSHOT.jar!/TestMapper.xml]] 
2

Thêm vào câu trả lời khác, bạn cũng phải

Check for duplicate method names

Lỗi này do thỏa thuận hợp các bản ghi cuối cùng.

IllegalArgumentException: Mapped Statements collection does not contain value 

Bỏ qua thông báo trên và chỉ cần di chuyển nhật ký của bạn và tìm thông báo lỗi đầu tiên trong nhật ký. Lỗi đầu tiên tôi nhận được,

ERROR [main] mapper.MapperFactoryBean (MapperFactoryBean.java:83) - Error while adding the mapper 'interface com.xyz.mappers.UserMapper' to configuration. 
java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.xyz.mappers.UserMapper.getAllUserDetails 

lỗi rõ ràng chỉ ra rằng, phương pháp getAllUserDetails đã tồn tại trong giao diện UserMapper (với số lượng khác nhau của các tham số). Nhân đôi tên phương thức cũng sẽ ném lỗi này. (Hình phạt cho mã dán sao chép): P

1

Tôi cũng gặp sự cố này.Ngoài khả năng của câu trả lời ở trên, tôi cố gắng sử dụng cách này giải quyết vấn đề:

Tên phương pháp phải giống nhau trong daomapper.xml, trong trường hợp tên phương pháp của tôi không giống nhau. Vì vậy, bạn phải chắc chắn rằng chúng giống nhau.

Chúc may mắn!

Các vấn đề liên quan