<insertid="insertUser"parameterType="User"keyProperty="id"> insert into user (<includerefid="insertFields"></include>) values(#{username}, #{password}, #{salt}, #{email}, #{type}, #{status}, #{activationCode}, #{headerUrl}, #{createTime}) </insert>
keyProperty="id"用于绑定对应Java类中的id
分页查询
1 2 3 4 5 6 7 8 9 10
<selectid="selectDiscussPosts"resultType="DiscussPost"> select <includerefid="selectFields"></include> from discuss_post where status != 2 <iftest="userId!=0"> and user_id = #{userId} </if> order by type desc, create_time desc limit #{offset}, #{limit} </select>
1️⃣查询第1条到第10条的数据select * from table limit 0,10;
—>对应需求就是查询第一页的数据:select * from table limit
(1-1)*10,10;
2️⃣查询第11条到第20条的数据select * from table limit 10,10;
—>对应需求就是查询第二页的数据:select * from table limit
(2-1)*10,10;
3️⃣查询第21条到第30条的数据select * from table limit 20,10;
—>对应需求就是查询第三页的数据:select * from table limit
(3-1)*10,10;