You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.6 KiB
89 lines
3.6 KiB
<?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.learning.newdemo.mapper.ArgumentHistoryMapper">
|
|
|
|
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.ArgumentHistory">
|
|
<id column="id" property="id" jdbcType="INTEGER"/>
|
|
<result column="user_id" property="userId" jdbcType="INTEGER"/>
|
|
<result column="topic" property="topic" jdbcType="VARCHAR"/>
|
|
<result column="argument_content" property="argumentContent" jdbcType="LONGVARCHAR"/>
|
|
<result column="position" property="position"
|
|
typeHandler="org.apache.ibatis.type.EnumTypeHandler"
|
|
jdbcType="VARCHAR"/>
|
|
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
|
</resultMap>
|
|
|
|
<sql id="Base_Column_List">
|
|
id, user_id, topic, argument_content, position, create_time
|
|
</sql>
|
|
|
|
<!-- 插入立论记录 -->
|
|
<insert id="insert" parameterType="com.learning.newdemo.entity.ArgumentHistory"
|
|
useGeneratedKeys="true" keyProperty="id">
|
|
INSERT INTO argument_history (
|
|
user_id, topic, argument_content, position
|
|
)
|
|
VALUES (
|
|
#{userId,jdbcType=INTEGER},
|
|
#{topic,jdbcType=VARCHAR},
|
|
#{argumentContent,jdbcType=LONGVARCHAR},
|
|
#{position,jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler}
|
|
)
|
|
</insert>
|
|
|
|
<!-- 根据用户ID查询 -->
|
|
<select id="selectByUserId" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List"/>
|
|
FROM argument_history
|
|
WHERE user_id = #{userId,jdbcType=INTEGER}
|
|
ORDER BY create_time DESC
|
|
</select>
|
|
|
|
<!-- 根据用户ID和持方查询 -->
|
|
<select id="selectByUserAndPosition" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List"/>
|
|
FROM argument_history
|
|
WHERE user_id = #{userId,jdbcType=INTEGER}
|
|
AND position = #{position,jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler}
|
|
ORDER BY create_time DESC
|
|
</select>
|
|
|
|
<!-- 根据主键查询 -->
|
|
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List"/>
|
|
FROM argument_history
|
|
WHERE id = #{id,jdbcType=INTEGER}
|
|
</select>
|
|
|
|
<!-- 获取用户最新立论记录 -->
|
|
<select id="selectLatestByUserId" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List"/>
|
|
FROM argument_history
|
|
WHERE user_id = #{userId,jdbcType=INTEGER}
|
|
ORDER BY create_time DESC
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<!-- 根据用户ID查询最新的i条记录 -->
|
|
<select id="selectLatestByUserIdWithLimit" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List"/>
|
|
FROM argument_history
|
|
WHERE user_id = #{userId,jdbcType=INTEGER}
|
|
ORDER BY create_time DESC
|
|
LIMIT #{limit,jdbcType=INTEGER}
|
|
</select>
|
|
|
|
<!-- 根据用户ID和持方查询最新的i条记录 -->
|
|
<select id="selectLatestByUserAndPositionWithLimit" resultMap="BaseResultMap">
|
|
SELECT <include refid="Base_Column_List"/>
|
|
FROM argument_history
|
|
WHERE user_id = #{userId,jdbcType=INTEGER}
|
|
<if test="position != null">
|
|
AND position = #{position,jdbcType=VARCHAR,
|
|
typeHandler=org.apache.ibatis.type.EnumTypeHandler}
|
|
</if>
|
|
ORDER BY create_time DESC
|
|
LIMIT #{limit,jdbcType=INTEGER}
|
|
</select>
|
|
|
|
</mapper> |