崔向南 | 03d21b9 | 2025-06-05 17:42:23 +0800 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 3 | <mapper namespace="bounty.mapper.BountyMapper"> |
| 4 | <!-- 确保 namespace 与 BountyMapper 接口全限定名一致 --> |
| 5 | |
| 6 | <!-- 添加 selectPage 方法的 SQL 语句 --> |
| 7 | <select id="selectPage" resultType="bounty.domain.Bounty"> |
| 8 | SELECT * FROM bounty |
| 9 | <!-- MyBatis-Plus 分页插件会自动添加 LIMIT 语句,无需手动写分页 --> |
| 10 | </select> |
| 11 | |
| 12 | <select id="selectList" resultType="bounty.domain.Bounty"> |
| 13 | SELECT * FROM bounty |
| 14 | </select> |
| 15 | |
| 16 | <insert id="insert" parameterType="bounty.domain.Bounty"> |
| 17 | INSERT INTO bounty ( |
| 18 | title, |
| 19 | description, |
| 20 | reward, |
| 21 | creator_id, <!-- 假设 creator_id 是非空字段 --> |
| 22 | deadline, |
| 23 | create_time, <!-- 假设 create_time 是非空字段 --> |
| 24 | status <!-- 假设 status 是非空字段 --> |
| 25 | ) |
| 26 | VALUES ( |
| 27 | #{title}, |
| 28 | #{description}, |
| 29 | #{reward}, |
| 30 | #{creator_id}, <!-- 假设 creatorId 是 Bounty 类中的属性 --> |
| 31 | #{deadline}, |
| 32 | NOW(), <!-- create_time 默认当前时间(MySQL 函数) --> |
| 33 | '0' <!-- status 默认值(如已发布) --> |
| 34 | ) |
| 35 | </insert> |
| 36 | |
| 37 | |
| 38 | |
| 39 | <update id="updateById" parameterType="bounty.domain.Bounty"> |
| 40 | UPDATE bounty |
| 41 | SET |
| 42 | status = #{et.status} <!-- 使用 et 别名访问实体的 status 属性 --> |
| 43 | WHERE id = #{et.id} <!-- 使用 et 别名访问实体的 id 属性 --> |
| 44 | </update> |
| 45 | |
| 46 | |
| 47 | <resultMap id="BountyWithSubmissionsResult" type="bounty.domain.Bounty"> |
| 48 | <id property="id" column="id"/> |
| 49 | <result property="title" column="title"/> |
| 50 | <result property="description" column="description"/> |
| 51 | <result property="reward" column="reward"/> |
| 52 | <result property="deadline" column="deadline"/> |
| 53 | <result property="status" column="status"/> |
| 54 | <!-- 关联查询回复列表,填充到 submissions 字段 --> |
| 55 | <collection |
| 56 | property="submissions" |
| 57 | column="id" |
| 58 | ofType="bounty.domain.BountySubmission" |
| 59 | select="bounty.mapper.BountySubmissionMapper.getSubmissionsByBountyId"/> |
| 60 | </resultMap> |
| 61 | |
| 62 | <!-- 修改 selectById 方法,使用新的 resultMap --> |
| 63 | <select id="selectById" resultMap="BountyWithSubmissionsResult"> |
| 64 | SELECT * FROM bounty WHERE id = #{id} |
| 65 | </select> |
| 66 | |
| 67 | |
| 68 | </mapper> |