如果我向我的服务器发送一个带有参数的 GET 请求,我会得到一个 405 - Method not allowed.
package pkgService;
import com.fasterxml.jackson.databind.ObjectMapper;
import pkgData.pkgEmployee.User;
import pkgServer.pkgUser.UserManagement;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
@Path("/user")
public class UserRouter {
private UserManagement userManagement;
private ObjectMapper objMap;
public UserRouter() {
this.userManagement = new UserManagement();
objMap = new ObjectMapper();
//TODO delete test data
userManagement.addUser(new User(1,"lukad", "luki"));
userManagement.addUser(new User(2,"meli", "malal"));
}
@GET
@Path("{userId}")
public Response getBook(@PathParam("userId") String id) {
Response.ResponseBuilder response = Response.status(Response.Status.OK);
try {
response.entity(objMap.writeValueAsString(userManagement.getUser(id)));
} catch (Exception e) {
response.status(Response.Status.BAD_REQUEST);
response.entity("[ERROR] " + e.getMessage());
}
return response.build();
} }
我希望获得 ID 为 1 (lukad,luki) 的用户,但我收到了 405。
我的邮递员请求网址: http://localhost:8080/Server_war_exploded/user?userId=1
我忘记了代码中的某些内容吗?
噜噜哒
尚方宝剑之说
神不在的星期二
相关分类