)系列文章汇总
)
)
)
)
)
)
)
)
)
)
)关于springboot整合jackson
用properties或yml配置文件来配置,即本篇的内容;
用配置类来配置,这是下一篇文章的主题;
)本篇概览
今天实战内容如下:
开发springboot应用,体验springboot默认支持jackson,包括jackson注解和ObjectMapper实例的注入;
在application.yml中添加jackson配置,验证是否生效;
)源码下载
| 名称 | 链接 | 备注 |
| :-- | :-- | :-- |
| 项目主页 | https://github.com/zq2599/blog_demos | 该项目在GitHub上的主页 |
| git仓库地址(https) | https://github.com/zq2599/blog_demos.git | 该项目源码的仓库地址,https协议 |
| git仓库地址(ssh) | [email protected]:zq2599/blog_demos.git | 该项目源码的仓库地址,ssh协议 |
)开始实战
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd”> 4.0.0 jacksondemo com.bolingcavalry 1.0-SNAPSHOT …/pom.xml com.bolingcavalry springbootproperties 0.0.1-SNAPSHOT springbootproperties Demo project for Spring Boot org.springframework.boot spring-boot-dependencies 2.3.3.RELEASE pom import org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine io.springfox springfox-swagger2 io.springfox springfox-swagger-ui org.springframework.boot spring-boot-maven-plugin package com.bolingcavalry.springbootproperties; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringbootpropertiesApplication { public static void main(String[] args) { SpringApplication.run(SpringbootpropertiesApplication.class, args); } } package com.bolingcavalry.springbootproperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.service.Tag; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .tags(new Tag(“JsonPropertySerializationController”, “JsonProperty相关测试”)) .select() // 当前包路径 .apis(Reque stHandlerSelectors.basePackage(“com.bolingcavalry.springbootproperties.controller”)) .paths(PathSelectors.any()) .build(); } //构建 api文档的详细信息函数,注意这里的注解引用的是哪个 private ApiInfo apiInfo() { return new ApiInfoBuilder() //页面标题 .title(“SpringBoot整合Jackson(基于配置文件)”) //创建人 .contact(new Contact(“程序员欣宸”, “https://github.com/zq2599/blog_demos”, “[email protected]”)) //版本号 .version(“1.0”) //描述 .description(“API 描述”) .build(); } } package com.bolingcavalry.springbootproperties.bean; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import java.util.Date;
【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】
浏览器打开:qq.cn.hn/FTf 免费领取