From 3b788177d8cf9f005bc2e72592be91aa3b938790 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 30 May 2020 04:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=90=9C=E7=B4=A2=E5=A5=BD?= =?UTF-8?q?=E5=8F=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/share/help/dao/FriendMapper.java | 4 ++-- .../java/com/share/help/form/SearchFrom.java | 10 +++++++++ .../com/share/help/service/UserService.java | 4 ++-- src/main/resources/mapping/FriendMapper.xml | 22 ++++++++++++++++--- .../com/share/help/HelpApplicationTests.java | 6 ++--- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/share/help/dao/FriendMapper.java b/src/main/java/com/share/help/dao/FriendMapper.java index 2479d2a..560ed4c 100644 --- a/src/main/java/com/share/help/dao/FriendMapper.java +++ b/src/main/java/com/share/help/dao/FriendMapper.java @@ -26,12 +26,12 @@ public interface FriendMapper { * @param userId 目标用户 * @return 返回好友id */ - List getFriend(@Param("userId") String userId, @Param("start") long start, @Param("count") long count); + List getFriend(@Param("userId") String userId, @Param("name") String name,@Param("start") long start, @Param("count") long count); /** * 统计好友分页数 * @param userId 目标用户 * @return 返回分页数 */ - Page> count(@Param("userId") String userId,@Param("pageSize") Integer pageSize); + Page> count(@Param("userId") String userId, @Param("name") String name,@Param("pageSize") Integer pageSize); } diff --git a/src/main/java/com/share/help/form/SearchFrom.java b/src/main/java/com/share/help/form/SearchFrom.java index 7c8e539..3f03bd5 100644 --- a/src/main/java/com/share/help/form/SearchFrom.java +++ b/src/main/java/com/share/help/form/SearchFrom.java @@ -6,9 +6,19 @@ package com.share.help.form; public class SearchFrom { // 用户id private String userId; + //用户名 + private String name; //分页数 private Integer currentPage; + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public Integer getCurrentPage() { return currentPage; } diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java index e393bbd..e5044f2 100644 --- a/src/main/java/com/share/help/service/UserService.java +++ b/src/main/java/com/share/help/service/UserService.java @@ -205,8 +205,8 @@ public class UserService{ * @return 返回好友列表 */ public JSONResponse>> searchFriend(SearchFrom searchFrom) { - Page> page=friendMapper.count(searchFrom.getUserId(),friendSize); - List list=friendMapper.getFriend(searchFrom.getUserId(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize); + Page> page=friendMapper.count(searchFrom.getUserId(),searchFrom.getName(),friendSize); + List list=friendMapper.getFriend(searchFrom.getUserId(),searchFrom.getName(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize); page.setBody(list); return new JSONResponse>>(DefaultRes.ok,Result.OK).setBody(page); } diff --git a/src/main/resources/mapping/FriendMapper.xml b/src/main/resources/mapping/FriendMapper.xml index 1321ffc..8dfb68e 100644 --- a/src/main/resources/mapping/FriendMapper.xml +++ b/src/main/resources/mapping/FriendMapper.xml @@ -10,12 +10,28 @@ select source_user_id as userId from friend where source_user_id!=#{userId} and target_user_id=#{userId} union all select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId}) + + and name like '%${name}%' + limit #{start},#{count} \ No newline at end of file diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 94137e7..84cd967 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -226,10 +226,10 @@ class HelpApplicationTests { */ @Test public void queryFriend(){ - Page> page=friendMapper.count("123",3); + Page> page=friendMapper.count("123","6",3); Assertions.assertEquals(1, (long) page.getCount()); - List user=friendMapper.getFriend("123",0,3); - Assertions.assertTrue(!user.isEmpty()&&"222".equals(user.get(0).getUserId())); + List user=friendMapper.getFriend("123","6",0,3); + Assertions.assertEquals(1,user.size()); } /**