猿问

mybatis配置错误

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

<select id="findAllUser2" resultType="hashmap">

SELECT * FROM student

</select>

<select id="findUserByname" parameterType="String" resultType="hashmap">

    SELECT * FROM student where name=#{xxx}

    </select>

<select id="findUserByUsernameAndNumber" parameterType="domain.User" resultType="domain.User">

    SELECT * FROM student where name='${name}' and number='${number}'

    </select>

    

<insert id="insertUserByUsernameAndNumber" parameterType="domain.User">

    insert into student(name,number)

    value(#{name},'${number}')

    </insert>

    

    <update id="updateUserByUsernameAndNumber" parameterType="domain.User">

   update student set name='${name}' where number=#{number} 

    </update>

    

     <delete id="deleteUserByUsernameAndNumber" parameterType="string">

     delete from student where  name=#{name} 

    </delete>

   

   

    <!-- 子查询 -->>

    <select id="findOneDepartment" parameterType="int" resultType="domain.Department">

    select * from department

    where id=#{id}

    </select>

    <select id="findAllUserSub" resultMap="findAllUserSub">

    select * from student

    </select>

    <resultMap type="domain.User" id="findAllUserSub">

    <id property="name" column="name"/>

    <result property="number" column="number"/>

    <association column="deptid" property="deptid" javaType="domain.Department" select="findOneDepartment">

    </association>

    </resultMap>

   

    <!--构造查询   -->

    <association column="deptid" property="deptid" javaType="domain.Department">

    <constructor>

    <arg column="id" javaType="int"/>

    <arg column="depname" javaType="String"/> 

    </constructor>

    <id column="id" property="id"></id>

    <result column="depname" property="dname"></result>

    </association>  

   

    <!-- 一对多查询 -->>

   <select id="findAllUsercollection" resultMap="resultUsers">

select * from student,department where student.deptid=department.id

</select>

<resultMap id="resultUsers" type="domain.Department">

<id column="id" property="id"></id>

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

<collection property="users" column="User.name" javaType="ArrayList" ofType="domain.User">

<result column="username" property="name"></result>

<result column="password" property="number"></result>

<result column="deptid" property="deptid"></result>

</collection>

</resultMap>

</mapper>


time初夏时光
浏览 1365回答 2
2回答

霜花似雪

注意resultType,parameterType对应的类型不要写错,其他的错误看不出来,能力有限

慕粉3233872

把错误信息贴出来
随时随地看视频慕课网APP

相关分类

Java
我要回答