Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 41a2dab

Browse files
Merge remote-tracking branch 'origin/master' into thymeleaf
2 parents a316de5 + fd8017b commit 41a2dab

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# spring-boot-demo
2-
![](https://img.shields.io/badge/springboot-2.0.2.RELEAS-blue.svg?color=blue&message=)
3-
* spring-boot2.0
2+
![](https://img.shields.io/badge/springboot-2.1.7.RELEASE-blue.svg?color=blue&message=)
3+
* spring-boot 2.0
44
* https://shields.io/
55

66
# mvn打包测试

‎pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<name>spring-boot-demo</name>
1212
<url>https://github.com/netbuffer/spring-boot-demo</url>
13-
<description>Demo project for Spring Boot</description>
13+
<description>spring-boot 相关技术测试</description>
1414

1515
<developers>
1616
<developer>
@@ -115,6 +115,11 @@
115115
<artifactId>print-server-address</artifactId>
116116
<version>2.1.0</version>
117117
</dependency>
118+
<dependency>
119+
<groupId>com.fasterxml.jackson.dataformat</groupId>
120+
<artifactId>jackson-dataformat-xml</artifactId>
121+
<version>2.10.0</version>
122+
</dependency>
118123
</dependencies>
119124

120125
<build>
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
package cn.netbuffer.springbootdemo.config;
22

33
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.http.MediaType;
5+
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
47

58
@Configuration
6-
public class Config {
9+
public class Config implements WebMvcConfigurer {
10+
11+
/**
12+
* /bean/map?mt=xml
13+
* /bean/map?mt=json
14+
* @param configurer
15+
*/
16+
@Override
17+
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
18+
configurer
19+
.favorParameter(true)
20+
.parameterName("mt")
21+
.favorPathExtension(true)
22+
// 根据Accept请求头来响应对应的数据格式
23+
// .ignoreAcceptHeader(true)
24+
.defaultContentType(MediaType.APPLICATION_JSON);
25+
}
26+
727
}

‎src/main/java/cn/netbuffer/springbootdemo/controller/BeanController.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import javax.annotation.Resource;
1919
import java.io.IOException;
2020
import java.util.ArrayList;
21+
import java.util.HashMap;
2122
import java.util.List;
23+
import java.util.Map;
2224

2325
@Slf4j
2426
@RestController
@@ -64,4 +66,12 @@ public List getBeanDefinitionNames(@RequestParam("path") String path) throws IOE
6466
return beanNames;
6567
}
6668

67-
}
69+
@GetMapping(value = {"map"})
70+
public Map getMap() {
71+
Map data = new HashMap();
72+
data.put("name", "test");
73+
data.put("age", "30");
74+
return data;
75+
}
76+
77+
}

‎src/main/resources/application.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ var:
1212
logging:
1313
level:
1414
root: WARN
15+
org:
16+
springframework:
17+
web: INFO

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /