我的问题是我无法按日期获取候选人,在我的代码中,我使用了如下的控制器和存储库
1- CandidatController
@RestController
@RequestMapping("/api")
public class CandidatController {
@Autowired
CandidatDao candidatdao;
@GetMapping(value = "/GetAllCandidats")
public List<Candidat> listeDesCandidat(){
List<Candidat> candidats = candidatdao.findAll();
return candidats;
}
@GetMapping(value = "/GetAllCandidats/{date}")
public List<Candidat> afficherCandidat(@PathVariable ("date")
@DateTimeFormat(pattern="yyyy-MM-dd") Date date) {
return candidatdao.findByDate(date);
}
2- CandidatDAO
@Repository
public interface CandidatDao extends JpaRepository <Candidat, String>{
List<Candidat> findByDate(Date date);
}
3- classcandidat
@Entity
public class Candidat {
@Id
@GeneratedValue
@Column(name = "candidat_id")
private int id;
private String nom;
private String prenom;
private String ville;
private int numTel;
private String mail;
private String pseudo;
private String roleCible;
private String typeContrat;
private String villeRecherchee;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date date;
在浏览器中,结果是: 与(http://localhost:8080/api/GetAllCandidats/)
{
id: 1,
nom: "Sar",
prenom: "Samir",
ville: "tissemsilt",
numTel: 76676810,
mail: "kira.DJ@gmail.com",
pseudo: "FET",
roleCible: "INGENIEUR",
typeContrat: "CDI",
villeRecherchee: "NANTES",
techno: [ ],
date: "2019-04-16",
secteurActivites: [ ]
},
{
id: 2,
nom: "xxxx",
prenom: "yyyyy",
ville: "zzzzzz",
numTel: 76676810,
mail: "kira.DJ@gmail.com",
pseudo: "FET",
roleCible: "INGENIEUR",
typeContrat: "CDI",
villeRecherchee: "NANTES",
techno: [ ],
date: "2019-04-22",
secteurActivites: [ ]
},
但是对于(http://localhost:8080/api/GetAllCandidats/2019-04-22),结果为null:
[]
答案 0 :(得分:0)