Cause: org.xml.sax.SAXParseException;columnNumber: 101; 必须为元素类型 "insert" 声明属性 "resultType

今天在完成一个demo时,一直在spring的配置文件mybatis部分出错。现对该问题做记录:

Spring-mybatis配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties" />
    bean>
    <bean id="DateSource" class="org.apache.commons.dbcp.BasicDataSource"
        init-method="close" destroy-method="close">
        
        <property name="driverClassName" value="${driver}" />
        
        <property name="url" value="${url}" />
        
        <property name="username" value="${username}" />
        
        <property name="password" value="${password}" />
    bean>
    
    <bean id="SqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        
        <property name="dataSource" ref="DateSource" />
        
        <property value="classpath:com/demo/oracle/mapping/*.xml" name="mapperLocations"/>
    bean>
    
    <bean id="MapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.demo.oracle.dao" />
        <property name="sqlSessionFactoryBeanName" value="SqlSessionFactoryBean" />
    bean>
beans>
mapping映射文件


<mapper namespace="com.demo.oracle.dao.UserDao">
    <resultMap type="com.demo.oracle.domain.User" id="selectUser">
        <result column="username" property="username" />
        <result column="password" property="password" />
        <result column="age" property="age" />
    resultMap>
    
    <select id="selectUserByUsername" resultMap="selectUser">
        select * from
        usertable
    select>
    
    <insert id="insertUser" parameterType="com.demo.oracle.domain.User" resultType="java.lang.Integer" >
        insert into usertable
        (username,password,age) values(#{username},#{password},#{age})
    insert>
    
    <delete id="delateUser" parameterType="java.lang.String" resultType="java.lang.Integer">
        delete from usertable where username=#{username}
    delete>
mapper>

解决方法:删除insert、delete中的resultType属性

你可能感兴趣的:(问题)