Skip to content

Commit 738641f

Browse files
committed
[add] xml格式数据支持
1 parent 1e7cd2a commit 738641f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@
3434
<artifactId>lombok</artifactId>
3535
<optional>true</optional>
3636
</dependency>
37+
<!--xml数据处理-->
38+
<dependency>
39+
<groupId>com.fasterxml.jackson.dataformat</groupId>
40+
<artifactId>jackson-dataformat-xml</artifactId>
41+
</dependency>
42+
3743
</dependencies>
3844
</project>

web/src/main/java/demo/web/controller/RestfulController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.hibernate.validator.constraints.Range;
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.beans.factory.annotation.Value;
10+
import org.springframework.http.MediaType;
1011
import org.springframework.validation.annotation.Validated;
1112
import org.springframework.web.bind.annotation.*;
1213

@@ -97,11 +98,11 @@ public String task1() throws Exception {
9798
}
9899

99100
/**
100-
* 参数校验1,入参为键值对形式
101+
* 参数校验1,入参为键值对形式,返回xml格式数据
101102
* http://localhost:8080/param?email=abc@aa.com&username=alice
102103
* 异常类型:{@link org.springframework.validation.BindException}
103104
*/
104-
@RequestMapping("/param")
105+
@RequestMapping(value = "/param", produces = MediaType.APPLICATION_XML_VALUE)
105106
public User param(@Valid User user) {
106107
return user;
107108
}

0 commit comments

Comments
 (0)