From caed343fc43710b8174a0b709e2ac3c452d208f4 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Wed, 3 Jun 2020 03:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E6=8C=89=E7=85=A7id=E7=B2=BE?= =?UTF-8?q?=E7=A1=AE=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/share/help/dao/UserMapper.java | 4 ++-- src/main/java/com/share/help/form/QueryUserForm.java | 10 ++++++++++ src/main/java/com/share/help/form/SearchFrom.java | 10 ++++++++++ src/main/java/com/share/help/service/UserService.java | 4 ++-- src/main/resources/mapping/UserMapper.xml | 7 ++----- src/test/java/com/share/help/HelpApplicationTests.java | 6 +++--- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/share/help/dao/UserMapper.java b/src/main/java/com/share/help/dao/UserMapper.java index 956796b..beb7033 100644 --- a/src/main/java/com/share/help/dao/UserMapper.java +++ b/src/main/java/com/share/help/dao/UserMapper.java @@ -94,10 +94,10 @@ public interface UserMapper { /** * 查找用户 */ - List queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId); + List queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("targetUserId") String targetUserId); - Page> countUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("pageSize") Integer pageSize); + Page> countUser(@Param("name") String name, @Param("info") String info, @Param("userId") String userId,@Param("targetUserId") String targetUserId, @Param("pageSize") Integer pageSize); /** * 查看用户信息 diff --git a/src/main/java/com/share/help/form/QueryUserForm.java b/src/main/java/com/share/help/form/QueryUserForm.java index 5a28d4a..925af01 100644 --- a/src/main/java/com/share/help/form/QueryUserForm.java +++ b/src/main/java/com/share/help/form/QueryUserForm.java @@ -6,6 +6,8 @@ package com.share.help.form; public class QueryUserForm { //用户id private String userId; + //搜索用户id + private String targetUserId; //用户名 private String name; //简介信息 @@ -34,4 +36,12 @@ public class QueryUserForm { public void setInfo(String info) { this.info = info; } + + public String getTargetUserId() { + return targetUserId; + } + + public void setTargetUserId(String targetUserId) { + this.targetUserId = targetUserId; + } } diff --git a/src/main/java/com/share/help/form/SearchFrom.java b/src/main/java/com/share/help/form/SearchFrom.java index 6306aa3..026c562 100644 --- a/src/main/java/com/share/help/form/SearchFrom.java +++ b/src/main/java/com/share/help/form/SearchFrom.java @@ -6,6 +6,8 @@ package com.share.help.form; public class SearchFrom { // 用户id private String userId; + //搜索目标用户 + private String targetUserId; //用户名 private String name; //服务地点 @@ -13,6 +15,14 @@ public class SearchFrom { //分页数 private Integer currentPage; + public String getTargetUserId() { + return targetUserId; + } + + public void setTargetUserId(String targetUserId) { + this.targetUserId = targetUserId; + } + public String getName() { return name; } diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java index 65ab69d..8f0f731 100644 --- a/src/main/java/com/share/help/service/UserService.java +++ b/src/main/java/com/share/help/service/UserService.java @@ -203,8 +203,8 @@ public class UserService{ * @return 返回查询结果 */ public JSONResponse>> queryUser(QueryUserForm queryUserForm){ - Page> page=userMapper.countUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId(),userPageSize); - List userWithNameList=userMapper.queryUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId()); + Page> page=userMapper.countUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId(),queryUserForm.getTargetUserId(),userPageSize); + List userWithNameList=userMapper.queryUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId(),queryUserForm.getTargetUserId()); page.setBody(userWithNameList); return new JSONResponse>>(DefaultRes.ok,Result.OK).setBody(page); } diff --git a/src/main/resources/mapping/UserMapper.xml b/src/main/resources/mapping/UserMapper.xml index bc411ca..e845f06 100644 --- a/src/main/resources/mapping/UserMapper.xml +++ b/src/main/resources/mapping/UserMapper.xml @@ -138,11 +138,8 @@ union all select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId}) ) - - and name like '%${name}%' - - - and info like '%${info}%' + + and user_id=#{targetUserId} diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 5dcce73..e5f0f73 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -199,13 +199,13 @@ class HelpApplicationTests { //查询用户列表 @Test public void queryUser(){ - Page> count=userMapper.countUser("6",null,"123",10); + Page> count=userMapper.countUser("6",null,"123","222", 10); Assertions.assertTrue(count.getCount()>0); - List userWithNames =userMapper.queryUser("2",null,"123"); + List userWithNames =userMapper.queryUser("2",null,"123","222"); Assertions.assertFalse(userWithNames.isEmpty()); - userWithNames =userMapper.queryUser("2","2", "123"); + userWithNames =userMapper.queryUser("2","2", "123","222"); Assertions.assertFalse(userWithNames.isEmpty()); }