春季开机自检未返回有效号码

Spring POST not returning valid numbers

本文关键字:有效 号码 返回 开机自检 春季      更新时间:2023-09-26

我对 spring 非常陌生,但我设法从我的 javascript 中想出了这段代码

$scope.addMe = function(){
        var params = {
            date :111111,
            username: 'thisGuy',
            notetext: 'this is a new note that was just added'
        };
        $http.post(afHttp.baseUrl + "/blah/" + $scope.dog.id, {params: params})
            .success(function(data) {
            });
    }

在埃尔克利普,我有

@POST
@Path("/{id}")
public void getAddMssg(@PathParam("id") int id, @FormParam("date") int date, @FormParam("username") String username, @FormParam("notetext") String notetext) {
    System.out.println("date:      "+date);
    System.out.println("username:   "+ username);
    System.out.println("notetext:   "+ notetext);
    System.out.println("id:   "+ id);
}

当我在日食中查看我的控制台登录时,它说

date:   0
username:   null
notetext:   null
id:   123124

我做错了什么? 我已经为此工作了一段时间,但无济于事。 有人可以帮忙吗?

哦,对不起,我忘了补充我正在使用angularjs。

将参数传递到该参数中,而不是 {params:params}。此外,添加内容类型标头作为第三个参数:

$http.post(afHttp.baseUrl + "/blah/" + $scope.dog.id, params, {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded'}})

在服务器端,继续执行@Consumes(MediaType.APPLICATION_FORM_URLENCODED)@POST:

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
MediaType

的完全限定名称是 javax.ws.rs.core.MediaType,以防您需要导入它。

什么是

$http?如果是jQuery,post方法需要"data"而不是"params"。http://api.jquery.com/jQuery.post/