- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Controller :personController.java
@Controller
public class personController {
private static final Logger LOG = LoggerFactory.getLogger(OcaController.class);
@RequestMapping(value = "/person", method = {RequestMethod.POST, RequestMethod.GET})
public String ocaContract(@RequestBody String requestPerson) {
return requestPerson;
}
1 JSP:person.jsp
<html>
<head>
</head>
<body>
<form class="form-horizontal" METHOD="POST" ACTION="webmvc/person" ENCTYPE="x-www-form-urlencoded">
<div class="controls">
<input type="text" name="name" id="name" value="" placeholder="">
</div>
<div class="controls">
<input type="text" name="surname" id="surname" value="" placeholder="">
</div>
<input type="submit" value="ok"/>
</form>
</body>
</html>
和一个对象类:Person.java
@XmlRootElement(name="Person")
public class Person {
@XmlElement(required = true)
protected String name;
@XmlElement(required = true, nillable = true)
protected String surname;
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
} ...
当我填充 JSP 并单击输入按钮时,我的 Controller 返回此“requestPerson”字符串:
name=&surname=
是否可以将此字符串作为 POJO ?我的最终结果必须是 XML 格式:
<person>
<name>Lisala</name>
<surname>Lili</surname></person>
我希望你能帮助我,因为我从 1 天开始就在做这件事,但我没有找到一个简单的方法来完成这个任务。
最佳答案
您可以将@RequestBody
替换为@ModelAttribute
,将String
替换为Person
public String ocaContract(@ModelAttribute Person requestPerson) {
关于java - Spring mvc @RequestBody 字符串格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36148903/
当我定义 requestBody 时,它不会显示在 swagger 文档中。我想为 swagger 中的 gpx 文件创建一组图像和单个文件上传。如何才能实现 requestBody 像参数属性一样显
我正在使用 Spring 4.x 做 Spring Rest Api 项目 这有效: Controller.java @PostMapping("newTransaction") Transactio
我正在向服务器发送一个 JSON 对象,该服务器将填充我的域对象报告。 public class CustomReport {String name; String name; String emai
我有一个非常琐碎的问题,它占用了我很多时间。 我有一个 Spring Rest 服务,它接受 @RequestBody 中的模型对象。我在模型对象中传递的是格式为 yyyy-MM-dd'T'HH:mm
我一直在开发 Spring Boot Rest api 服务,这是我的 Rest Controller 方法之一: @RequestMapping(value = "manager", method
我使用 Spring Boot 2.0.8.RELEASE。 我有一个 @RestController 方法,如下所示: @PostMapping("/message") public
类(class): class Person { private String name; private List addr; } c
我有以下类作为我的@RequestBody,但我无法发送我的请求,我尝试以不同的格式准备 JSON,但它们都不起作用。 处理程序 @RequestMapping("/grades") @Respons
@PatchMapping("/update") HttpEntity updateOnlyIfFieldIsPresent(@RequestBody Person person) { if(
我正在尝试使用 apache 集合中的 MultiValueMap(MultiMap 的实现)。我正在使用 Spring MVC 的 @RequestBody 注释。但是,我不断收到 HTTPMedi
Requestbody 没有映射到我在这里使用的对象。 PaymentRequest 中的所有字段都为空。我看到注释和映射一切似乎都是正确的。 @RestController @RequestMapp
假设以下 JSON: { "attr_A": "val_A", "array_A": [{ "attr_B": "val_B" }] } 以及以下两个类: public class C
JavaScript 代码: function deleteMarks(list){ $http.post('/api/marks/delete/all',list).then( fu
我是 Java/Spring 的新手,正在尝试在现有项目中设置 API 端点。我基本上已经复制了一些当前正在工作的其他端点,但我的端点在被击中时没有验证,这似乎是因为 @RequestBody 没有填
我正在使用 postman 来测试我的请求。所以我从 postman 那里选择了显示代码 fragment 的选项并选择了 OkHttp fragment 是: OkHttpClient client
我使用 Spring-boot 2.0.1 和 WebFlux 作为 Rest 服务器。 在我的 RestController 中,我想自动反序列化一个对象(产品)。但我收到 Jackson 错误,就
我创建了一个简单的 REST 服务 (POST)。但是当我从 postman 那里调用这个服务时,@RequestBody 没有收到任何值。 import org.springframework.ht
PostMan传参给@RequestBody(接受前端参数) 今天新接手一个项目框架,需要改造,但后台写好方法,准备用postman 测试时候,发现用以前传参方式不行,需要需要将json字符串转成
springmvc @RequestBody String类型参数 通过如下配置: <bean id="mappingJacksonHttpMessageConverter&qu
目录 SpringMVC @RequestBody为null 关于inputsteam的一些理解 @RequestBody 自动映射原理的简单介
我是一名优秀的程序员,十分优秀!