blob: 3267ef273f0bf9e6859be2957c01d4870fd14daf [file] [log] [blame]
崔向南03d21b92025-06-05 17:42:23 +08001<?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"/>
zhaoyumao9eb3e052025-06-08 00:26:32 +080054 <result property="creator_id" column="creator_id"/>
崔向南03d21b92025-06-05 17:42:23 +080055 <!-- 关联查询回复列表,填充到 submissions 字段 -->
56 <collection
57 property="submissions"
58 column="id"
59 ofType="bounty.domain.BountySubmission"
60 select="bounty.mapper.BountySubmissionMapper.getSubmissionsByBountyId"/>
61 </resultMap>
62
63 <!-- 修改 selectById 方法,使用新的 resultMap -->
64 <select id="selectById" resultMap="BountyWithSubmissionsResult">
65 SELECT * FROM bounty WHERE id = #{id}
66 </select>
67
68
69</mapper>