我正在使用postman packaged app发送帖子请求。
我想请求以下控制器。
如何使用邮递员对象(带有值)和使用原始格式的列表发送帖子请求者?
@RequestMapping(value = "register", method = RequestMethod.POST)
@ResponseBody
public ResponseMessage save(@RequestBody Freelancer freelancer, @RequestBody List<Integer> skills) {
我试过这样的话:
{
"address": "colombo",
"username": "hesh",
"password": "123",
"registetedDate": "2015-4-3",
"firstname": "hesh",
"contactNo": "07762",
"accountNo": "16161",
"lastName": "jay"
}
{
"array[0]" :1436517454492,
"array[1]" :1436517476993
}
答案 0 :(得分:13)
确保您已在标头请求中将content-type
设为application/json
,并在原始标签下将其从主体发布。
{
"address": "colombo",
"username": "hesh",
"password": "123",
"registetedDate": "2015-4-3",
"firstname": "hesh",
"contactNo": "07762",
"accountNo": "16161",
"lastName": "jay",
"arrayObjectName" : [{
"Id" : 1,
"Name": "ABC" },
{
"Id" : 2,
"Name" : "XYZ"
}],
"intArrayName" : [111,222,333],
"stringArrayName" : ["a","b","c"]
}
答案 1 :(得分:2)
我不确定您使用的是哪种服务器端技术,但尝试使用json数组。您可以尝试以下几种选择:
{
"address": "colombo",
"username": "hesh",
"password": "123",
"registetedDate": "2015-4-3",
"firstname": "hesh",
"contactNo": "07762",
"accountNo": "16161",
"lastName": "jay"
},
[
1436517454492,
1436517476993
]
如果这不起作用,您也可以尝试:
{
freelancer: {
"address": "colombo",
"username": "hesh",
"password": "123",
"registetedDate": "2015-4-3",
"firstname": "hesh",
"contactNo": "07762",
"accountNo": "16161",
"lastName": "jay"
},
skills : [
1436517454492,
1436517476993
]
}
答案 2 :(得分:1)
在简单示例中,如果您的api在以下
@POST
@Path("update_accounts")
@Consumes(MediaType.APPLICATION_JSON)
@PermissionRequired(Permissions.UPDATE_ACCOUNTS)
void createLimit(List<AccountUpdateRequest> requestList) throws RuntimeException;
其中AccountUpdateRequest:
public class AccountUpdateRequest {
private Long accountId;
private AccountType accountType;
private BigDecimal amount;
...
}
那么您的邮递员请求将是: http://localhost:port/update_accounts
[
{
"accountType": "LEDGER",
"accountId": 11111,
"amount": 100
},
{
"accountType": "LEDGER",
"accountId": 2222,
"amount": 300
},
{
"accountType": "LEDGER",
"accountId": 3333,
"amount": 1000
}
]
答案 3 :(得分:0)
//后端。
@PostMapping("/")
public List<A> addList(@RequestBody A aObject){
//......ur code
}
class A{
int num;
String name;
List<B> bList;
//getters and setters and default constructor
}
class B{
int d;
//defalut Constructor & gettes&setters
}
//邮递员
{
"num":value,
"name":value,
"bList":[{
"key":"value",
"key":"value",.....
}]
}
答案 4 :(得分:0)
我也有一个几乎相同的问题,这是一个参考例子
我的控制器
@RequestMapping(value = {"/batchDeleteIndex"}, method = RequestMethod.POST)
@ResponseBody
public BaseResponse batchDeleteIndex(@RequestBody List<String> datasetQnames)
邮递员
确保Body中的原始文件为application / json
["aaa","bbb","ccc"]
答案 5 :(得分:0)
如果您在请求部分中使用以下格式,同时确保请求网址为http://localhost:XXXX/OperationName/V#。
{
"address": "colombo",
"username": "hesh",
"password": "123",
"registetedDate": "2015-4-3",
"firstname": "hesh",
"contactNo": "07762",
"accountNo": "16161",
"lastName": "jay",
"listName":[
{
"elementOne":"valueOne"
},
{
"elementTwo":"valueTwo"
},
...]
}
答案 6 :(得分:0)
尝试一下,
ssNew <- function(DF, LC2LC){
f <- function(df1, lc2lc){
inx <- which(df1[['LC']] %in% unique(unlist(lc2lc)))
for(i in inx){
if(df1$Freq[i] == 1) break
df1$SSnew[i] <- df1$SS[i]
}
df1
}
g <- function(df1){
inx <- seq_len(nrow(df1))
for(i in inx){
if(df1$Freq[i] == 1) break
df1$SSnew[i] <- df1$SS[i]
}
df1
}
DF[['SSnew']] <- 0
sp1 <- split(DF, DF[['Item']])
sp2 <- split(LC2LC, LC2LC[['Item']])
DFItem <- unique(DF[['Item']])
nms <- intersect(DFItem, LC2LC[['Item']])
res <- lapply(DFItem, function(i) {
if(i %in% nms){
f(sp1[[i]], sp2[[i]])
}else{
g(sp1[[i]])
}
})
res <- do.call(rbind, res)
row.names(res) <- NULL
res
}
Final_v1 <- ssNew(Final, lctolc)
Final_v1
# Item LC Fiscal.Week SS Freq SSnew
#1 A MW92 2019-W24 20 1 0
#2 A OY01 2019-W24 10 0 0
#3 A RM11 2019-W24 5 1 0
#4 B WK14 2019-W24 112 0 112
#5 B RS11 2019-W24 30 1 0
答案 7 :(得分:0)
根据您的要求使用此格式:
{
"address": "colombo",
"username": "hesh",
"password": "123",
"registetedDate": "2015-4-3",
"firstname": "hesh",
"contactNo": "07762",
"accountNo": "16161",
"lastName": "jay"
"arrayOneName" : [
{
"Id" : 1,
"Employee" : "EmpOne",
"Deptartment" : "HR"
},
{
"Id" : 2,
"Employee" : "EmpTwo",
"Deptartment" : "IT"
},
{
"Id" : 3,
"Employee" : "EmpThree",
"Deptartment" : "Sales"
}
],
"arrayTwoName": [
{
"Product": "3",
"Price": "6790"
}
],
"arrayThreeName" : [
"name1", "name2", "name3", "name4" // For Strings
],
"arrayFourName" : [
1, 2, 3, 4 // For Numbers
]
}
请记住在具有适当端点的POST中使用它。此外,RAW选择并在“正文”选项卡中选择JSON(application / json)。
就像这样:
更新1:
我认为不允许或不可能使用多个@RequestBody。
@RequestBody参数必须具有请求的整个主体,并将其仅绑定到一个对象。
您必须使用包装器对象之类的东西才能工作。
答案 8 :(得分:0)
{
"preOrderData" : [
{
"pname": "xyz",
"quantity": "1",
"unit": "Peice",
"description": "xyz 100 gram",
"preferred_brand": "xyz",
"entry_date": "2020-10-05 11:11:27",
"creation_date": "2020-10-05 11:11:27",
"updated_date": "2020-10-05 11:11:27",
"user": "ABC@gmail.com",
"user_type": "individual"
},
{
"productname": "abc cream",
"quantity": "1",
"unit": "Peice",
"description": "abc 100 gram",
"preferred_brand": "abccream",
"entry_date": "2020-10-05 11:11:27",
"creation_date": "2020-10-05 11:11:27",
"updated_date": "2020-10-05 11:11:27",
"user": "xyz@gmail.com",
"user_type": "individual"
}
]
}