1.git上传远程仓库(现在才想起来)
git init
git add .
git commit -m "first commit"
git remote add origin OLiyscxm/shortlink
git push -u origin "master"
2.开发全局异常拦截器之后就可以简化UserController
拦截器可以替代为空判断
3.common目录下创建目录serialize,再创建类
public class PhoneDesensitizationSerializer extends JsonSerializer<String> {
@Override
public void serialize(String phone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
throws IOException {
String phoneDesensitization = DesensitizedUtil.mobilePhone(phone);
jsonGenerator.writeString(phoneDesensitization);
}
}
4.UserRespDTO添加json序列化注释
5.resp目录下定义一个UserActualRespDTO类,这个类就不要json序列化注释了,再修改UserController,这时就可以选择是否查看真实用户手机号了
@RestController
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
/**
*
* 根据用户名查询用户信息
*
*/
@GetMapping("/api/shortlink/v1/user/{username}")
public Result<UserRespDTO> getUserByUsername(@PathVariable("username") String username) {
return Results.success(userService.getUserByUsername(username));
}
@GetMapping("/api/shortlink/v1/actual/user/{username}")
public Result<UserActualRespDTO> getActualUserByUsername(@PathVariable("username") String username) {
return Results.success(BeanUtil.toBean(userService.getUserByUsername(username), UserActualRespDTO.class));
}
}
6.新增查询用户名是否存在功能
UserService中添加
/**
* 查询用户名是否存在
* @param username 用户名
* @return 存在返回True,不存在返回False
*/
Boolean hasUsername(String username);
UserServiceImpl中添加
@Override
public Boolean hasUsername(String username) {
LambdaQueryWrapper<UserDO> queryWrapper = Wrappers.lambdaQuery(UserDO.class)
.eq(UserDO::getUsername, username);
UserDO userDO = baseMapper.selectOne(queryWrapper);
return userDO==null;
}
UserController中添加
/**
*查询用户名是否存在
*/
@GetMapping("/api/shortlink/v1/user/has-username")
public Result<Boolean> hasUsername(@RequestParam("username") String username){
return Results.success(userService.hasUsername(username));
}
7.data一栏OLi存在,返回false