【问题标题】:problems with http post json (spring/angularjs)http post json(spring/angularjs)的问题
【发布时间】:2017-05-23 20:20:20
【问题描述】:

i create an spring/angularjs application but i have some problems with "post",when i tried to test the controller without angularjs i had this message :

“时间戳”:1495521855274, “状态”:415, "error": "不支持的媒体类型", “异常”:“org.springframework.web.HttpMediaTypeNotSupportedException”, "message": "不支持内容类型'multipart/form-data;boundary=----WebKitFormBoundaryShaAnQBDa47tg35j'", “路径”:“/employe1”

this is my controller

@Autowired
private EmployeMetier EmployeMetier;
@RequestMapping(value="/employe1",method=RequestMethod.POST)
public Employe saveEmploye(@RequestBody Employe e) {

    return EmployeMetier.saveEmploye(e);
}

[这是我的 angularjs 应用][3]

$scope.ajouter_employe=function(){
$http({
    method: 'POST',
    url: "/employe1",
    headers: {'Content-Type': 'application/json'},
    data: {idEmploye: $scope.idEmploye}
}).then( function(response){
               alert('yes');
             });

【问题讨论】:

    标签: angularjs json spring http spring-mvc


    【解决方案1】:

    如下更改您的@RequestMapping

    @RequestMapping(value="/employe1",method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produces=MediaType.APPLICATION_JSON_VALUE)
    

    【讨论】:

      猜你喜欢
      • 2020-04-06
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 2019-05-01
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多