【发布时间】:2021-12-02 01:25:16
【问题描述】:
我在服务中有 post 方法。 如果学生年龄> 18,那么我想保存对象。 如果年龄
如何将此信息传递给控制器 (ResponseEntity) 以引发 401?
@Service
public class StudentService {
public Student save(Student Student) {
//some logic
if (studentAge > 20) {
student.setId(null);
return studentRepository.save(student);
} else {
//what are the good practices here?
}
}
}
【问题讨论】:
-
返回 null 呢?并检查一下?
标签: java spring spring-boot rest spring-mvc