完善我的好友、我的留言分页逻辑

master
pan 4 years ago
parent 25dc1c9acf
commit 109e0f57a7
  1. 2
      src/main/java/com/share/help/dao/LeaveWordMapper.java
  2. 1
      src/main/java/com/share/help/service/LeaveWordService.java
  3. 1
      src/main/java/com/share/help/service/UserService.java
  4. 4
      src/main/resources/application.yaml
  5. 2
      src/main/resources/mapping/FriendMapper.xml
  6. 1
      src/main/resources/mapping/LeaveWordMapper.xml
  7. 2
      src/test/java/com/share/help/HelpApplicationTests.java

@ -24,7 +24,7 @@ public interface LeaveWordMapper {
List<LeaveWordRes> select(@Param("start") long start,@Param("count") long count,@Param("userId") String userId); List<LeaveWordRes> select(@Param("start") long start,@Param("count") long count,@Param("userId") String userId);
// 统计留言列表分页数 // 统计留言列表分页数
@Select("select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from leave_word where target_user_id=#{userId}") @Select("select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage,#{pageSize} as pageSize from leave_word where target_user_id=#{userId}")
Page<List<LeaveWordRes>> count(@Param("pageSize") Integer pageSize,@Param("userId") String userId); Page<List<LeaveWordRes>> count(@Param("pageSize") Integer pageSize,@Param("userId") String userId);
/** /**

@ -45,6 +45,7 @@ public class LeaveWordService {
*/ */
public JSONResponse<DefaultRes, Page<List<LeaveWordRes>>> query(FindLeaveWordForm findLeaveWordForm){ public JSONResponse<DefaultRes, Page<List<LeaveWordRes>>> query(FindLeaveWordForm findLeaveWordForm){
Page<List<LeaveWordRes>> listPage=leaveWordMapper.count(pageSize,findLeaveWordForm.getUserId()); Page<List<LeaveWordRes>> listPage=leaveWordMapper.count(pageSize,findLeaveWordForm.getUserId());
listPage.setCurrentPage(findLeaveWordForm.getCurrentPage());
List<LeaveWordRes> leaveWordRes=leaveWordMapper.select((findLeaveWordForm.getCurrentPage()-1)*pageSize,pageSize,findLeaveWordForm.getUserId()); List<LeaveWordRes> leaveWordRes=leaveWordMapper.select((findLeaveWordForm.getCurrentPage()-1)*pageSize,pageSize,findLeaveWordForm.getUserId());
for(LeaveWordRes wordRes:leaveWordRes){ for(LeaveWordRes wordRes:leaveWordRes){
if(LeaveWordType.friend!=wordRes.getType()&&wordRes.getActivityId()!=null){ if(LeaveWordType.friend!=wordRes.getType()&&wordRes.getActivityId()!=null){

@ -216,6 +216,7 @@ public class UserService{
*/ */
public JSONResponse<DefaultRes, Page<List<Friend>>> searchFriend(SearchFrom searchFrom) { public JSONResponse<DefaultRes, Page<List<Friend>>> searchFriend(SearchFrom searchFrom) {
Page<List<Friend>> page=friendMapper.count(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),friendSize); Page<List<Friend>> page=friendMapper.count(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),friendSize);
page.setCurrentPage(searchFrom.getCurrentPage());
List<Friend> list=friendMapper.getFriend(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize); List<Friend> list=friendMapper.getFriend(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize);
page.setBody(list); page.setBody(list);
return new JSONResponse<DefaultRes,Page<List<Friend>>>(DefaultRes.ok,Result.OK).setBody(page); return new JSONResponse<DefaultRes,Page<List<Friend>>>(DefaultRes.ok,Result.OK).setBody(page);

@ -40,7 +40,7 @@ user:
#分页配置 #分页配置
page-size: page-size:
#留言列表 #留言列表
leave-word: 3 leave-word: 5
#活动列表 #活动列表
activity: activity:
# 分页大小 # 分页大小
@ -56,7 +56,7 @@ page-size:
# 单行显示数量 # 单行显示数量
row-size: 3 row-size: 3
#好友列表 #好友列表
friend: 3 friend: 5
#管理员列表 #管理员列表
manager: 10 manager: 10

@ -25,7 +25,7 @@
</select> </select>
<select id="count" resultType="com.share.help.res.Page"> <select id="count" resultType="com.share.help.res.Page">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage,#{pageSize} as pageSize
from user from user
<where> <where>
user_id in ( user_id in (

@ -17,5 +17,6 @@
where leave_word.target_user_id = #{userId} where leave_word.target_user_id = #{userId}
and leave_word.source_user_id = user.user_id and leave_word.source_user_id = user.user_id
order by create_time desc order by create_time desc
limit #{start},#{count}
</select> </select>
</mapper> </mapper>

@ -312,7 +312,7 @@ class HelpApplicationTests {
//更新活动信息 //更新活动信息
@Test @Test
public void testUpdateActivity(){ public void testUpdateActivity(){
Assertions.assertTrue(activityMapper.updateActivity(66L,"44","", imageName)); Assertions.assertTrue(activityMapper.updateActivity(66L,"44","", null));
} }
@Test @Test

Loading…
Cancel
Save