1 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊
您可以執(zhí)行以下操作來實(shí)現(xiàn)一個(gè)處理對(duì) Biography 實(shí)體的請(qǐng)求的 Spring 控制器。
您的傳記實(shí)體似乎不錯(cuò)
要使用它,您可以利用
org.springframework.data.repository.CrudRepository;
即:
public interface BiographyRepository extends CrudRepository <Biography, Long> { }
Spring 非常靈活,您可以按照自己喜歡的方式組織代碼。以下是如何組織控制器代碼的示例:
@RestController
@RequestMapping
public class BiographyController {
@Autowired
private BiographyRepository biographyRepository;
@RequestMapping(value = "/biography, method = RequestMethod.POST)
public @ResponseBody
Response create (HttpServletRequest request) {
//read biography object from the request
biographyRepository.save(biography);
}
//other methods...
}
根據(jù)您的需要,更好的做法可能是通過@Service控制器中的存儲(chǔ)庫進(jìn)行操作。
添加回答
舉報(bào)