Angularjs 无法使用Angular.JS执行POST Rest服务

Angularjs 无法使用Angular.JS执行POST Rest服务,angularjs,rest,post,spring-boot,Angularjs,Rest,Post,Spring Boot,我无法在春季使用AngularJs和REST服务发布帖子 HTML只是一个简单的表单,用于将数据提交到Rest服务并在同一页面上打印出来 我得到以下错误: 加载资源失败:服务器响应状态为400(错误请求) App.js var helloApp=angular.module(“SG”,['ngResource']); helloApp.controller(“HttpController”[“$scope”,“$resource”, 功能($scope$resource){ $scope.u

我无法在春季使用AngularJs和REST服务发布帖子

HTML只是一个简单的表单,用于将数据提交到Rest服务并在同一页面上打印出来

我得到以下错误:

加载资源失败:服务器响应状态为400(错误请求)

App.js

var helloApp=angular.module(“SG”,['ngResource']);
helloApp.controller(“HttpController”[“$scope”,“$resource”,
功能($scope$resource){
$scope.users=[];
$scope.saveUser=function(){
$scope.users.push({'name':$scope.name,'username':$scope.username,'size':$scope.size,'email':$scope.email});
//创建资源类对象
//
var User=$resource('/upload');
//对类调用操作方法(save)
//
User.save({name:$scope.firstname,username:$scope.username,size:$scope.size,email:$scope.email},函数(响应){
$scope.message=response.message;
});
$scope.firstname='';
$scope.username='';
$scope.size='';
$scope.email='';
}
} ]);

在此处插入标题
首页
开源表单验证 名称

必须输入您的姓名

用户名

必须输入您的姓名

电子邮件 输入有效的电子邮件

小时数 提交 {{$scope.message}
如果您的项目未在服务器中使用根文件夹运行,请检查主机。将项目名称与url一起添加。

更改您的方法签名

@RequestMapping(value="/upload",method=Request.Method.POST)
public @ResponseBody HashMap<String,String> handleFileUpload(@RequestBody HashMap<String,String> userdetails)
{
  System.out.println("User Details is : "+userdetails);
  HashMap<String,String> user = new HashMap<String,String>();
  user.put("name","example");
  return example
}
@RequestMapping(value=“/upload”,method=Request.method.POST)
public@ResponseBody HashMap handleFileUpload(@RequestBody HashMap userdetails)
{
System.out.println(“用户详细信息为:“+userdetails”);
HashMap用户=新建HashMap();
user.put(“名称”、“示例”);
返回示例
}
@RequestParam用于绑定url值
@RequestBody用于ajax解析请求正文


返回类型应该是JSONObject或HashMap。

我更改了方法签名,使其与JSON而不是字符串兼容

@RequestMapping(value="/upload", method=RequestMethod.POST, consumes = "application/json",produces= "application/json")
public @ResponseBody DataPost handleFileUpload( @RequestBody DataPost datapost){

    System.out.println(datapost.getUsername());
    datapost.setUsername(datapost.getUsername()+"Controller");
    System.out.println("hello");
    return datapost;
}

如果您签入web开发人员工具,那么失败的请求方法是什么?它是获得职位还是选择?