<?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="cn.wisenergy.mapper.ScoreInfoMapper"> <resultMap id="userMap" type="cn.wisenergy.model.app.ScoreInfo"> <id column="id" property="id"/> <result column="user_id" property="userId"/> <result column="culture_grade" property="cultureGrade"/> <result column="major_grade" property="majorGrade"/> <result column="language_grade" property="languageGrade"/> <result column="math_grade" property="mathGrade"/> <result column="english_grade" property="englishGrade"/> <result column="physics_grade" property="physicsGrade"/> <result column="chemistry_grade" property="chemistryGrade"/> <result column="biology_grade" property="biologyGrade"/> <result column="history_grade" property="historyGrade"/> <result column="geography_grade" property="geographyGrade"/> <result column="politics_grade" property="politicsGrade"/> <result column="create_time" property="createTime"/> <result column="update_time" property="updateTime"/> </resultMap> <sql id="table"> score </sql> <sql id="cols_all"> id, <include refid="cols_exclude_id"/> </sql> <sql id="cols_exclude_id"> user_id,culture_grade, major_grade,language_grade,math_grade,english_grade, physics_grade,chemistry_grade, biology_grade,history_grade,geography_grade,politics_grade, create_time,update_time </sql> <sql id="vals"> #{userId},#{cultureGrade},#{majorGrade},#{languageGrade},#{mathGrade},#{englishGrade},#{physicsGrade}, #{chemistryGrade},#{biologyGrade}, #{historyGrade},#{geographyGrade},#{politicsGrade},now(),now() </sql> <sql id="updateCondition"> <if test="userId != null">user_id = #{userId},</if> <if test="cultureGrade != null">culture_grade =#{cultureGrade},</if> <if test="majorGrade != null">major_grade =#{majorGrade},</if> <if test="languageGrade != null">language_grade =#{languageGrade},</if> <if test="mathGrade != null">math_grade =#{mathGrade},</if> <if test="englishGrade != null">english_grade =#{englishGrade},</if> <if test="physicsGrade != null">physics_grade = #{physicsGrade},</if> <if test="chemistryGrade != null">chemistry_grade = #{chemistryGrade},</if> <if test="biologyGrade != null">biology_grade = #{biologyGrade},</if> <if test="historyGrade != null">history_grade = #{historyGrade},</if> <if test="geographyGrade != null">geography_grade = #{geographyGrade},</if> <if test="politicsGrade != null">politics_grade = #{politicsGrade},</if> update_time =now() </sql> <sql id="updateCondition2"> user_id = #{userId}, culture_grade =#{cultureGrade}, major_grade =#{majorGrade}, language_grade =#{languageGrade}, math_grade =#{mathGrade}, english_grade =#{englishGrade}, physics_grade = #{physicsGrade}, chemistry_grade = #{chemistryGrade}, biology_grade = #{biologyGrade}, history_grade = #{historyGrade}, geography_grade = #{geographyGrade}, politics_grade = #{politicsGrade}, update_time =now() </sql> <sql id="criteria"> <if test="id != null">id = #{id}</if> <if test="userId != null">and user_id = #{userId}</if> <if test="cultureGrade != null">and culture_grade =#{cultureGrade}</if> <if test="majorGrade != null">and major_grade =#{majorGrade}</if> <if test="languageGrade != null">and language_grade =#{languageGrade}</if> <if test="mathGrade != null">and math_grade =#{mathGrade}</if> <if test="englishGrade != null">and english_grade =#{englishGrade}</if> <if test="physicsGrade != null">and physics_grade = #{physicsGrade}</if> <if test="chemistryGrade != null">and chemistry_grade = #{chemistryGrade}</if> <if test="biologyGrade != null">and biology_grade = #{biologyGrade}</if> <if test="historyGrade != null">and history_grade = #{historyGrade}</if> <if test="geographyGrade != null">and geography_grade = #{geographyGrade}</if> <if test="politicsGrade != null">and politics_grade = #{politicsGrade}</if> <if test="createTime != null">and create_time >= #{createTime}</if> <if test="updateTime != null">and #{updateTime} >= update_time</if> </sql> <insert id="add" parameterType="cn.wisenergy.model.app.ScoreInfo" keyProperty="id" useGeneratedKeys="true"> insert into <include refid="table"/> (<include refid="cols_exclude_id"/>) value( <include refid="vals"/> ) </insert> <update id="edit" parameterType="cn.wisenergy.model.app.ScoreInfo"> UPDATE <include refid="table"/> <set> <include refid="updateCondition2"/> </set> <where> id = #{id} </where> </update> <delete id="delById" parameterType="java.lang.Integer"> delete from <include refid="table"/> where id = #{id} </delete> <select id="getByUserId" resultMap="userMap"> select <include refid="cols_all"/> from <include refid="table"/> <where> user_id=#{userId} </where> </select> </mapper>