注意点:
1.nested exception is org.apache.ibatis.binding.BindingException: Parameter 'record_id' not found. Ava
错误原因:
①可能是参数没有定义参数名,对应不上,可以如下:
public void deleteQues(@Param("id") String id);
②如果是对象则不要加:@Param(),应该入下:
public void addQues(Question2 question);
给一些例子吧,都是模仿着写就可以了。
public int insertAnswerRemark(Answer ans); public List<PaperQuesAns> findRemarkList(@Param("id")String id, @Param("questionId")String questionId); public List<Question2> findAllQues(@Param("id")String id); public void saveEditQues(Question question); public void deleteQues(@Param("id")String id); // public void addQues(@Param("paperId")String paperId,@Param("level")String level); // 添加问题: public void addQues(Question2 question);
<insert id="insertAnswerRemark" useGeneratedKeys="true" keyProperty="id"> INSERT INTO db_answer( paperId, questionId, userId, answer, subTime, remark, level ) VALUES ( #{paperId}, #{questionId}, #{userId}, #{answer}, #{subTime}, #{remark}, #{level} ) </insert> <select id="findRemarkList" resultType="PaperQuesAns"> SELECT a.paperId, a.questionId, u.name, a.remark, a.subTime FROM db_answer a left join sys_user u on a.userId=u.id where a.paperId=#{id} and a.questionId=#{questionId} ORDER BY a.subTime </select> <select id="findAllQues" resultType="Question"> SELECT * FROM db_question WHERE paperId = #{id} AND ( a IS NOT NULL OR b IS NOT NULL OR c IS NOT NULL OR d IS NOT NULL AND (content IS NOT NULL)) order by (num+0) </select> <update id="saveEditQues"> UPDATE db_question SET content=#{content}, num=#{num}, a=#{a}, b=#{b}, c=#{c}, d=#{d} WHERE paperId = #{paperId} and id=#{id}; </update> <update id="deleteQues"> delete from db_question WHERE id = #{id} </update> <insert id="addQues" useGeneratedKeys="true" keyProperty="id"> INSERT INTO db_question2( qid, paperid, content, <if test="remark != null"> remark, </if> level, <if test="num != null"> num, </if> ismust, type, min_num, max_num ) VALUES ( #{qid}, #{paperId}, #{content}, <if test="remark != null"> #{remark}, </if> #{level}, <if test="num != null"> #{num}, </if> #{ismust}, #{type}, #{minNum}, #{maxNum} ) </insert>
<?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.ctgu.collegeservice.dao.UserDao"> <insert id="insertUser" parameterType="com.ctgu.collegeservice.entity.User" useGeneratedKeys="true" keyProperty="id"> INSERT INTO user(username,password,nickname,name,studentid) values(#{username},#{password},#{name},#{name},#{studentid}) </insert> <select id="findUserBySome" parameterType="com.ctgu.collegeservice.entity.User" resultType="com.ctgu.collegeservice.entity.User"> SELECT * FROM user <where> <if test="id != null"> and id = #{id} </if> <if test="username != null"> and username = #{username} </if> <if test="name != null"> and name like'%${name}%' </if> <if test="studentid != null"> and studentid = #{studentid} </if> </where> </select> <select id="findAllUser" resultType="com.ctgu.collegeservice.entity.User"> SELECT * FROM user </select> <select id="findUserByUsername" parameterType="String" resultType="com.ctgu.collegeservice.entity.User"> SELECT * FROM user WHERE username = #{value} </select> <select id="findUserByStudentid" parameterType="String" resultType="com.ctgu.collegeservice.entity.User"> SELECT * FROM user WHERE studentid = #{value} </select> <update id="updateUser" parameterType="com.ctgu.collegeservice.entity.User" keyProperty="id" useGeneratedKeys="true"> UPDATE user <set> <if test="username != null">username=#{username},</if> <if test="password != null">password=#{password},</if> <if test="name != null">name=#{name},</if> <if test="nickname != null">nickname=#{nickname},</if> <if test="sex != null">sex=#{sex},</if> <if test="age != null">age =#{age },</if> <if test="school != null">school =#{school },</if> <if test="summary != null">summary =#{summary },</if> <if test="status != null">status =#{status },</if> </set> where id = #{id} </update> </mapper>