我需要使用angular js $ http:
进行API调用JOSN格式:
{
jobData : {"companyName":"companyname", "designation":"Javascript developer", "hiringManagerEmail":"atul@xyz.com", "industry":"automotive", "location":"chennai", "typeOfWork":"full time", "jobDescription":"abcdefghijklmnop", "rolesAndResponsiblities":"Reviewing current systems.Presenting ideas for system improvements, including cost proposals. Working closely with analysts, designers and staff. Producing detailed specifications and writing the program codes. Testing the product in controlled, real situations before going live. Preparation of training manuals for users.Maintaining the systems once they are up and running", "minEducation":"bachelors", "minEdu_fieldOfStudy":"computer science", "prefEducation":"masters", "prefEdu_filedOfStudy":"computerscience", "recruiterNotes":"must be from premium institute", "minExperience":"5", "maxExperience":"7", "requiredSkills":[ "java", "spring", "hibernate" ], "goodToHaveSkills":[ "jsp", "jquery", "sql" ], "requiredSoftSkills":[ "team leadership", "project management" ], "goodToHaveSoftSkills":[ "growth mindset", "management skills" ], "preferredCertifications":[ "sun certified java programmer (SCJP)" ], "minCertification":[ "sun certified java associate (SCJA)" ], "workPermits":[ "united states of america", "singapore" ], "visaStatus":[ "united states of america - valid till december 2015", "singapore - valid till may 2016" ], "minSalaryBand":"7.5", "maxSalaryBand":"10.0", "shiftTiming":"daytime", "startTime":"", "endTime":"", "numberOfPositions":"2", "joining":"30 days after offer", "closingNoticePeriod":"no", "checklist":[ "does the candidate has any experience working in the automotive industry?", "is the candidate willing to work abroad if required?", "does the candidate have good communication skills?", "is the candidate passionate enough for the company?" ], "needProfilesBy":"20 september 2015" }}
API调用:
function postJob(){
var job = {
"companyName":"company",
"designation":"software engineer",
"needProfilesBy":"20 september 2015"
};
return $http({
method : 'POST',
url : api + 'job',
transformRequest: transformRequestAsFormPost,
data: {'jobData': job},
}).then(postJobComplete)
.catch(exception.catcher('XHR Failed for post signup'));
function postJobComplete (data, status, headers, config) {
console.log(data);
}
}
transformRequest.js
(function() {
'use strict';
angular
.module('app.core')
.factory('transformRequestAsFormPost', transformRequestAsFormPost);
transformRequestAsFormPost.$inject = [];
/* @ngInject */
function transformRequestAsFormPost() {
function transformRequest(data, getHeaders) {
var headers = getHeaders();
return (serializeData(data));
}
return (transformRequest);
function serializeData(data) {
if (!angular.isObject(data)) {
return ((data == null) ? '' : data.toString());
}
var buffer = [];
for (var name in data) {
if (!data.hasOwnProperty(name)) {
continue;
}
var value = data[ name ];
buffer.push(
encodeURIComponent(name) +
'=' +
encodeURIComponent((value == null) ? '' : value)
);
}
var source = buffer
.join('&')
.replace(/%20/g, '+')
;
return (source);
}
}
})();
我正在尝试使用' jobData'但是得到错误
错误:
"错误请求" 异常:" org.springframework.web.bind.MissingServletRequestParameterException" 消息:"必需的字符串参数' jobData'不存在"路径: " /作业"状态:400