diff --git a/src/main/java/com/example/springtest/demo/resources/UsersRest.java b/src/main/java/com/example/springtest/demo/resources/UsersRest.java index 7ec878e..8b4ab4a 100644 --- a/src/main/java/com/example/springtest/demo/resources/UsersRest.java +++ b/src/main/java/com/example/springtest/demo/resources/UsersRest.java @@ -33,11 +33,36 @@ @GET @Produces(MediaType.APPLICATION_JSON) // 戻り値をJSONで返す. // public Collection getUsers() { - public Iterable getUsers() { + public Iterable getUsers(@Nullable @QueryParam("name") String name) { + if(name == null) { // return users.values(); // JSONが返る - return userRepository.findAll(); + return userRepository.findAll(); + } else { + List users = new ArrayList<>(); + for(User user: userRepository.findAll()) { + if (user.getName().equals(name)) { + users.add(user); + } + } + return users; + } } +// 競合? +// @GET +// @Produces(MediaType.APPLICATION_JSON) // 戻り値をJSONで返す. +// public Collection getUsersByName(@QueryParam("name") String name) { +// public Iterable getUsersByName(@QueryParam("name") String name) { +// return users.values(); // JSONが返る +// List users = new ArrayList<>(); +// for(User user: userRepository.findAll()) { +// if (user.getName() == name) { +// users.add(user); +// } +// } +// return users; +// } + @Path("/{uId}") @GET @Produces(MediaType.APPLICATION_JSON) // 戻り値をJSONで返す.