我使用邮递员和弹簧靴。在春季启动中,我使用代码如下所示:
public PersistableCategory createCategory(@RequestBody PersistableCategory persistableCategory, MerchantStore store, HttpServletRequest httpRequest) {
MerchantStore merchantStore = (MerchantStore) httpRequest.getAttribute("MERCHANT_STORE");
return categoryService.saveCategories(store,persistableCategory);
}
从httpservletrequest获取属性。但是我不知道我在邮递员的哪里设置了名称为MERCHANT_STORE的属性。我的身体看起来像
{
"attributes": {
"MERCHANT_STORE": {
"code":"1"
}
},
但不起作用。如何在邮递员中设置属性并使用HttpServletRequest来获取它。
{
"attributes": {
"MERCHANT_STORE": {
"code":"1",
"code2":{
"element1":"1",
"element2":"2"
}}}
2。首先,创建一个响应类。
public class responseData {
private merchant_store;
// getter, setter, the other elements..
}
public class result{
private View json; // this object from spring servlet lib.
// and make methods to parse http header(yep, in postman) and to return datas.
}
public PersistableCategory createCategory(){
MerchantStore merchantStore = (MerchantStore);
httpRequest.getAttribute("MERCHANT_STORE");
Object purpose = categoryService.saveCategories(store,persistableCategory);
Object responseData = new responseData();
responseData.set(purpose);
result.set(responseData, successYn);
return result;
}