提问人:João Rollo 提问时间:11/15/2023 最后编辑:João Rollo 更新时间:11/16/2023 访问量:17
控制器 crud mvc java 层注解的问题 [已关闭]
Problems with controller crud mvc java layer annotations [closed]
问:
我遇到了问题,因为 Jpa 扩展存储库的标准方法不起作用或连接到我的控制器,我相信这是一个导入问题,但控制台中没有错误,只是端点不起作用。
package br.edu.unicesumar.crud.controller;
import br.edu.unicesumar.crud.model.domain.Pessoa;
import br.edu.unicesumar.crud.model.repository.PessoaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/pessoa")
public class PessoaController {
@Autowired
private PessoaRepository pessoaRepository;
@GetMapping
public List<Pessoa> all() {
return pessoaRepository.findAll();
}
@GetMapping("/{id}")
public Pessoa getById(@PathVariable Long id) {
return pessoaRepository.findById(id).orElse(null);
}
@PostMapping
public Pessoa create(@RequestBody Pessoa nova) {
return pessoaRepository.save(nova);
}
@DeleteMapping("/{id}")
public void delete(@PathVariable Long id) {
pessoaRepository.deleteById(id);
}
}
答: 暂无答案
评论