场景:公司有一个商家系统,现在要做这个商家系统的后台管理系统。
我负责的项目需求:在用户忘记自己密码的时候,后台管理员手动帮用户修改密码,修改后的密码是随机生成的。
Controller层:
@Controller
@RequestMapping("/user")
public class UserController{
@Autowired
private IUserService iUserService;
@RequestMapping("/resetPassword")
public String resetPassword(long userId){
if(userId > 0){
return iUserService.resetPassword(userId);
}else{
throw new ApiException(400,"用户id小于等于0","用户不存在");
}
}
}
ApiException是公司自己封装的异常处理类。第一个参数是状态码,第二个参数是给开发人员看的错误信息,第三个参数是给用户看的信息。
Service层:
public interface IUserService{
String resetPassword(long userId);
}
@Service
public class IUserServiceImpl implements IUserService{
@Autowired
private UserMapper userMapper;
//根据salt值对s