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

drgonroot/request-json-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

19 Commits

Repository files navigation

request-json-boot-starter: 可多层级提取request body json指定参数值

maven central License jdk


📚简介

支持语言: java8+
使用springboot: springboot2
使用json工具: jackson

对接前端上传各种json的参数:

  • 使用Spring框架,需要使用RequestBody.class解析参数,需要编写对应实体类,同时解析粒度是类级别。
  • 对接本框架,可以像RequestParam.class注解一样去获取对应参数值,同时还支持多层级的获取参数值的。解析注解:RequestJson.class RequestJsonParam.class。

🚀使用指南

EnableRequestJson.class 注解放在应用上

import org.springframework.boot.SpringApplication;
@EnableRequestJson
@SpringBootApplication
public class Application {
 public static void main(String[] args) {
 SpringApplication.run(Application.class);
 }
}

🌓HTTP请求解析参数使用指南

http发送Post请求,content-type: application/json。 通过RequestJson.class RequestJsonParam.class 提取json中参数值

/**
 * request body json:
 * {
 * "other1": "hello world",
 * "other2": {
 * "other3":"hello world"
 * },
 * "list": ["1", "2", "3"],
 * "set":[1, 2, 3]
 * }
 */
@RestController
public class TestController {
 @RequestMapping(value = "/", method = RequestMethod.POST)
 public void test(@RequestJsonParam String other,
 @RequestJsonParam(value = "other1") String other1,
 @RequestJsonParam(value = "other2", required = false) Object other2,
 // 多层级参数解析
 @RequestJsonParam(value = "other2.other3", required = false, defaultValue = "other") String other3,
 // 解析基础类型
 @RequestJsonParam long long1,
 @RequestJsonParam boolean bool,
 @RequestJsonParam Integer inta,
 @RequestJsonParam String str,
 @RequestJsonParam Object object,
 // request body解析
 @RequestJson JsonNode jsonNode,
 // 解析集合类型
 @RequestJsonParam Set<Object> set,
 @RequestJsonParam List<Object> list,
 @RequestJsonParam Map<String, Object> testMap) {
 }
}

📦安装

🍊Maven

在项目的pom.xml的dependencies中加入以下内容:

<dependency>
 <groupId>com.btye102</groupId>
 <artifactId>request-json-boot-starter</artifactId>
 <version>1.0.2</version>
</dependency>

About

spring-boot spring-mvc request body application/json extract name with value

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

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