好友按照id精确查询

master
pan 4 years ago
parent 68067dfc15
commit caed343fc4
  1. 4
      src/main/java/com/share/help/dao/UserMapper.java
  2. 10
      src/main/java/com/share/help/form/QueryUserForm.java
  3. 10
      src/main/java/com/share/help/form/SearchFrom.java
  4. 4
      src/main/java/com/share/help/service/UserService.java
  5. 7
      src/main/resources/mapping/UserMapper.xml
  6. 6
      src/test/java/com/share/help/HelpApplicationTests.java

@ -94,10 +94,10 @@ public interface UserMapper {
/**
* 查找用户
*/
List<UserWithName> queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId);
List<UserWithName> queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("targetUserId") String targetUserId);
Page<List<UserWithName>> countUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("pageSize") Integer pageSize);
Page<List<UserWithName>> countUser(@Param("name") String name, @Param("info") String info, @Param("userId") String userId,@Param("targetUserId") String targetUserId, @Param("pageSize") Integer pageSize);
/**
* 查看用户信息

@ -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;
}
}

@ -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;
}

@ -203,8 +203,8 @@ public class UserService{
* @return 返回查询结果
*/
public JSONResponse<DefaultRes, Page<List<UserWithName>>> queryUser(QueryUserForm queryUserForm){
Page<List<UserWithName>> page=userMapper.countUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId(),userPageSize);
List<UserWithName> userWithNameList=userMapper.queryUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId());
Page<List<UserWithName>> page=userMapper.countUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId(),queryUserForm.getTargetUserId(),userPageSize);
List<UserWithName> userWithNameList=userMapper.queryUser(queryUserForm.getName(),queryUserForm.getInfo(),queryUserForm.getUserId(),queryUserForm.getTargetUserId());
page.setBody(userWithNameList);
return new JSONResponse<DefaultRes,Page<List<UserWithName>>>(DefaultRes.ok,Result.OK).setBody(page);
}

@ -138,11 +138,8 @@
union all
select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId})
)
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
<if test="info!=null and info!=''">
and info like '%${info}%'
<if test="userId!=null and userId!=''">
and user_id=#{targetUserId}
</if>
</where>
</sql>

@ -199,13 +199,13 @@ class HelpApplicationTests {
//查询用户列表
@Test
public void queryUser(){
Page<List<UserWithName>> count=userMapper.countUser("6",null,"123",10);
Page<List<UserWithName>> count=userMapper.countUser("6",null,"123","222", 10);
Assertions.assertTrue(count.getCount()>0);
List<UserWithName> userWithNames =userMapper.queryUser("2",null,"123");
List<UserWithName> 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());
}

Loading…
Cancel
Save