First we create a MAVEN project, such as:
Step Two: Configure Pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-par ent</artifactid> <version>1.4.1.RELEASE</version> </parent><properties> <project .build.sourceencoding>utf-8</project.build.sourceencoding> <!--Specify the version of the JDK, where we use JDK 1.7, which is 1.6 by default <java.version>1.7</java.version> </properties> <dependencies> <dependency> < ;groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid > </dependency> <!--Add Fastjson dependency packages. -<dependency> <groupId>com.alibaba</groupId> <artifactid>fastjson</artif Actid> <version>1.2.15</version> </dependency> <!--spring boot devtools dependent packages. -<dependency> <groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <sco Pe>true</scope> </dependency> </dependencies>
Step three: Create the package structure and class as shown
Fourth step: Write the above three classes
User:
Provides a get, set method.
Fastjsoncontroller:
APP:
When the above steps are complete, execute the main method of the app class, waiting for the project to start. And then access it in the browser.
Http://localhost:8080/getJson, return results such as:
Find Chinese garbled, then modify the controller class, such as:
And then visit again, the results are as follows:
Solve garbled problems.
Use Fastjson to parse JSON data in Spring boot