我使用@RequestParam创建了一个POST Rest API,它可用于:
router.post('/',function(req,res){
var resultData= Array();
getBirthDates(function(result){
if(result.length>0)
resultData = result;
console.log('inside -- > ');
console.log(resultData);
});
// Add timer function
setTimeout(function() {
console.log('outside -- > ');
console.log(resultData);
}, 3000)
});
function getBirthDates(callback){
var sqlBirthDays = "SELECT displayName, DATE_FORMAT((userDob),'%m-%d') AS DOB, DATE_FORMAT(NOW(),'%m-%d') TD FROM mx_admin_user HAVING DOB = TD";
con.query(sqlBirthDays, function (err, result, fields) {
if (err) throw err;
return callback(result);
});
}
我使用邮差进行测试:
那很好。
现在,我想做同样的事情,但要提交请求:
@PostMapping("/shop-menu")
@PreAuthorize("@accessChecker.hasAccessToWebservice(#request)")
public ResponseEntity<EntiteShopMenuDTO> addShopMenu(HttpServletRequest request,
@RequestParam("numeroLicence") String numeroLicence,
@RequestParam("ordre") Integer ordre,
@RequestParam("titre") String titre,
@RequestParam("url") String url,
@RequestParam("logo") MultipartFile logo) throws URISyntaxException, CustomException, IOException {
与邮递员一起尝试:
结果是:
@PutMapping("/shop-menu/{numeroLicence}")
@PreAuthorize("@accessChecker.hasAccessToWebservice(#request)")
public ResponseEntity<EntiteShopMenuDTO> updateShopMenu(HttpServletRequest request,
@PathVariable String numeroLicence,
@RequestParam("test") String test,
@RequestParam(value = "logoFile", required = false) MultipartFile logoFile) throws CustomException, IOException {
我尝试使用json正文对对象参数(而不是测试参数)进行相同操作,并且结果相同。
使用Curl可以工作:
{
"type": "https://www.jhipster.tech/problem/problem-with-message",
"title": "Bad Request",
"status": 400,
"detail": "Required String parameter 'test' is not present",
"path": "/api/shop-menu/BJ3-M1",
"message": "error.http.400"
}
你能帮我吗?