Springboot总结

        新建项目后,我们一般都需要配置编码,这点非常重要,很多初学者都会忘记这一步,所以要养成良好的习惯。

IDEA 中,仍然是打开File->settings,搜索 encoding,配置一下本地的编码信息。如下:

src/main/java路径:主要编写业务程序
src/main/resources路径:存放静态文件和配置文件
src/test/java路径:主要编写测试程序
        默认情况下,如上图所示会创建一个启动类 Course01Application,该类上面有个@SpringBootApplication注解,该启动类中有个 main 方法,没错,Spring Boot 启动只要运行该 main 方法即可,非常方便。另外,Spring Boot 内部集成了 tomcat,不需要我们人为手动去配置 tomcat,开发者只需要关注具体的业务逻辑即可。
 

        Spring Boot返回Json数据及数据封装
        在项目开发中,接口与接口之间,前后端之间数据的传输都使用 Json 格式,在 Spring Boot 中,接口返回 Json 格式的数据很简单,在 Controller 中使用@RestController注解即可返回 Json 格式的数据,@RestController也是 Spring Boot 新增的一个注解,我们点进去看一下该注解都包含了哪些东西
 

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {
    String value() default "";
}

        可以看出, @RestController 注解包含了原来的 @Controller 和 @ResponseBody 注解,使用过 Spring 的朋友对 @Controller 注解已经非常了解了,这里不再赘述, @ResponseBody 注解是将返回的数据结构转换为 Json 格式。所以在默认情况下,使用了 @RestController 注解即可将返回的数据结构转换成 Json 格式,Spring Boot 中默认使用的 Json 解析技术框架是 jackson。我们点开 pom.xml 中的 spring-boot-starter-web 依赖,可以看到一个 spring-boot-starter-json 依赖:
 

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-json</artifactId>
    <version>2.0.3.RELEASE</version>
    <scope>compile</scope>
</dependency>

 

相关推荐

  1. SpringBoot】知识点总结

    2024-03-27 07:18:06       63 阅读
  2. springboot参数传递总结

    2024-03-27 07:18:06       35 阅读
  3. springBoot异常总结

    2024-03-27 07:18:06       23 阅读
  4. SpringBoot2升级到SpringBoot3总结

    2024-03-27 07:18:06       40 阅读
  5. SpringBoot RestTemplate远程调用总结

    2024-03-27 07:18:06       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 07:18:06       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 07:18:06       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 07:18:06       87 阅读
  4. Python语言-面向对象

    2024-03-27 07:18:06       96 阅读

热门阅读

  1. OpenCV基础demo

    2024-03-27 07:18:06       40 阅读
  2. 05、Lua 变量

    2024-03-27 07:18:06       37 阅读
  3. leetcode - 843. Guess the Word

    2024-03-27 07:18:06       36 阅读
  4. 【Django】枚举类型数据

    2024-03-27 07:18:06       37 阅读
  5. 微服务设计原则——低风险

    2024-03-27 07:18:06       36 阅读
  6. 滴滴出行高级Node.js开发工程师笔试题2024

    2024-03-27 07:18:06       42 阅读
  7. 【Mysql】更新脚本SQL——新增删除修改字段

    2024-03-27 07:18:06       38 阅读