@RequestMapping(value = "/createItem", method = RequestMethod.POST)
@Override
public void createItem(@RequestParam(value="userId") String userId, @RequestParam(value="title") String title, @RequestParam(value="subtitle") String subtitle, @RequestParam(value="description") String description, @RequestParam(value="category") String category, @RequestParam(value="datapack") String datapack) {
this.itemDAO.createItem(userId, title, subtitle, description, category, datapack);
}
我正在使用 Spring 创建 RESTful 应用程序。上面的方法工作得很好,但是当数据包长度超过一定长度时就会出错。错误提示...
Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
我需要将数据包作为参数传递,数据包本身将是一个 json 文件,我将其转换为字符串。
数据包文件可能非常复杂且庞大。我该如何解决这个问题?
以下是请求示例:
http://localhost:8090/createItem?userId=test&title=test&subtitle=test&description=test&category=test&datapack=
{
"CLASS": "com.mincom.ellipse.edoi.ejb.menu_item.MENU_ITEMRec",
"INSTANCE": {
"m_creationDate": "20150824",
"m_creationTime": "001616",
"m_creationUser": "SR4187",
"m_lastModDate": "20150824",
"m_lastModTime": "001616",
"m_lastModUser": "SR4187",
"m_menuType": "",
"m_invokationString": "",
"primaryKey": {
"m_uuid": "3b4d95fe3dd3432fb00cde0cc25f903f"
}
}
},
{
"CLASS": "com.mincom.ellipse.edoi.ejb.i18n_descriptions.I18N_DESCRIPTIONSRec",
"INSTANCE": {
"m_creationDate": "20150824",
"m_creationTime": "001616",
"m_creationUser": "SR4187",
"m_lastModDate": "20150824",
"m_lastModTime": "001616",
"m_lastModUser": "SR4187",
"m_description": "CUSTOM_MENU",
"primaryKey": {
"m_locale": "en",
"m_uuid": "3b4d95fe3dd3432fb00cde0cc25f903f"
}
}
},
{
"CLASS": "com.mincom.ellipse.edoi.ejb.top_level_menus.TOP_LEVEL_MENUSRec",
"INSTANCE": {
"m_creationDate": "20150824",
"m_creationUser": "SR4187",
"m_lastModDate": "20150824",
"m_lastModTime": "001620",
"m_creationTime": "001620",
"m_lastModUser": "SR4187",
"m_uuid": "3b4d95fe3dd3432fb00cde0cc25f903f",
"primaryKey": {
"m_name": "SX"
}
}
}
上面的示例有效,但如果我使用更长的 JSON 文件进行测试,它将不起作用。
最佳答案
创建一个 Controller 方法,该方法应使用 XHR (AJAX) 接收 $http 服务发布的 JSON 数据
@RequestMapping(value = "/savecompany_json", method = RequestMethod.POST)
public @ResponseBody String saveCompany_JSON( @RequestBody Company company ) {
//
// Code processing the input parameters
//
return "JSON: The company name: " + company.getName() + ", Employees count: " + company.getEmployees() + ", Headoffice: " + company.getHeadoffice();
}
创建映射到 JSON 对象的 POJO
public class Company {
private String name;
private long employees;
private String headoffice;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getEmployees() {
return employees;
}
public void setEmployees(Long employees) {
this.employees = employees;
}
public String getHeadoffice() {
return headoffice;
}
public void setHeadoffice(String headoffice) {
this.headoffice = headoffice;
}
}
关于java - Spring 参数太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32962285/