第二阶段冲刺六

今天主要完成的任务:服务端Mybatis框架的搭建

遇到的困难:映射失败的问题

解决办法:相关bean没有写重构方法,无法映射,添上默认重构方法就行

源程序代码,这里只附上核心代码:

<?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="mapper.UserAndNoteMapper">
    
    <select id="judgeUserExist" parameterType="bean.User" resultType="bean.User">
        select * from user where username=#{username} and password=#{password}
    </select>
    
    <select id="judgeUserNameExist" parameterType="String" resultType="bean.User">
        select * from user where username=#{value}
    </select>
    
    <insert id="addUser" parameterType="bean.User">
        <selectKey keyProperty="user_id" order="AFTER" resultType="int">
            select LAST_INSERT_id()
        </selectKey>
        insert into user(username,password,user_icon) values(#{username},#{password},#{user_icon})
    </insert>
    
    <insert id="addNote" parameterType="bean.Note">
        <selectKey keyProperty="note_id" order="AFTER" resultType="int">
            select LAST_INSERT_id()
        </selectKey>
        insert into note(title,course,date,txt_path,image1_path,image2_path,image3_path,permission) 
        values(#{title},#{course},#{date},#{fileMap.txt_path},#{fileMap.image1_path},#{fileMap.image2_path},
        #{fileMap.image3_path},#{permission})
    </insert>
    
    <insert id="addUserWritedNote" parameterType="int">
        insert into user_note(user_id,note_id) values(#{0},#{1})
    </insert>
    
    <select id="getNoteAndUser" parameterType="int" resultType="bean.Notepojo">
        SELECT user_icon,username,date,title,course,txt_path,image1_path,image2_path,
        image3_path FROM note JOIN user_note un ON note.note_id=un.note_id JOIN user ON 
        un.user_id=user.user_id WHERE note.note_id=#{value}
    </select>
    
    <select id="getNotes" parameterType="int" resultType="bean.Note">
        SELECT note.* FROM user_note JOIN note ON user_note.note_id=note.note_id WHERE user_id=#{value}
    </select>

    <select id="getpublicNotes"  resultType="bean.Notepojo">
        SELECT user_icon,username,note.note_id,date,title,course FROM note JOIN user_note un ON note.note_id=un.note_id JOIN user ON 
        un.user_id=user.user_id WHERE permission='public'
    </select>
    
    <insert id="addUserCollectNote" parameterType="int">
        insert into user_collect_note(user_id,note_id) values(#{0},#{1})
    </insert>
    
    <select id="judgeUserCollectNote" parameterType="int" resultType="bean.Note">
        SELECT note_id FROM user_collect_note WHERE user_id=#{0} AND note_id=#{1}
    </select>
    
    
    <select id="getUserCollectNotes" parameterType="int" resultType="bean.Note">
        SELECT note.* FROM user_collect_note JOIN note ON user_collect_note.note_id=note.note_id 
        WHERE user_id=#{value}
    </select>
    
    <delete id="deleteNote" parameterType="int">
        delete from note where note_id = #{value}
    </delete>
    
    <delete id="deleteCollectedNote" parameterType="int">
        delete from user_collect_note where note_id = #{value}
    </delete>
    
    <delete id="deleteUserWritedNote" parameterType="int">
        delete from user_note where user_id=#{0} and note_id=#{1}
    </delete>
    
    <delete id="deleteUserCollectNote" parameterType="int">
        delete from user_collect_note where user_id=#{0} and note_id=#{1}
    </delete>
    
    <select id="getIconPath" parameterType="int" resultType="String">
        SELECT user_icon FROM user WHERE user_id=#{value}
    </select>
    
    <update id="modifyIcon" parameterType="bean.User">
        update user set user_icon=#{user_icon} WHERE user_id=#{user_id}
    </update>
    
    <update id="modifyPass" parameterType="String">
        update user set password=#{1} WHERE username=#{0}
    </update>
    
    <select id="getUnderNotes" parameterType="String"  resultType="bean.Notepojo">
        SELECT user_icon,username,note.note_id,date,title FROM note JOIN user_note un ON note.note_id=un.note_id JOIN user ON 
        un.user_id=user.user_id WHERE permission='public' AND course=#{value}
    </select>
    

</mapper>

 

posted @ 2020-05-27 22:16  一粒盐  阅读(98)  评论(0编辑  收藏  举报