GithubHelp home page GithubHelp logo

springboot-rest-service's Introduction

Spring Boot Getting Started

Build a RESTful Web Service

原文地址

  1. @SpringBootApplication 是一个简便的注解,包含以下内容:

    • @Configuration: 将类标记为应用上下文的 Bean 定义的源

    • @EnableAutoConfiguration: 告诉 Spring boot 根据类路径设置,其他的 Bean 和各种属性设置开始添加 Bean

    • @ComponentScan: 告诉 Spring 在包中寻找其他组件,配置服务等

  2. 注解 @RequestMapping 表示到 /greeting 的 http 请求将会被映射到 greeting 方法

    • 示例没有指明具体的 HTTP 请求方法(GET/POST/PUT), @RequestMapping 默认映射所有的 HTTP 方法. 可以使用 @RequestMapping(method=GET) 来指明具体的方法

    • 注解 @RequestParam 把 http query 中的参数 name 的值当做 name 参数传给 greeting() 方法,如果在 query string 中没有 name 参数,则会使用 defaultValue 的值

    • Spring 的 HTTP 消息转换器会将 Greeting 对象自动转换为 JSON. 由于 Jackson 2 位于 classpath z中,因此会自动选择 Spring 的 MappingJackson2HttpMessageConverter 来将 Greeting 转为 JSON

Scheduling Task

原文地址

  1. 注解 @Scheduled 定义了何时运行指定的方法。

    • 示例中使用了 fixedRate, 指定了任务开始运行时的时间间隔, 是指上次运行到这次运行之间的时间间隔。还有 其他选项,比如 fixedDelay, 就表示上次运行结束到本次开始执行的时间间隔

    • 也可以使用 @Scheduled(cron=" . . .") 进行更加复杂的任务调度,参考: spring 中使用 cron 调度任务

  2. 注解 @EnableScheduling 指明了需要在后台执行任务,如果没有的话则不会调度任何任务

Consuming a RESTful Web Service

原文地址

todo

Uploading Files

原文地址

  1. 当类使用 @Controller 注解时,Spring MVC 就会在其中寻找路由定义

  2. 使用 @GetMapping@PostMapping 注解标记的方法将会绑定 http 方法和 path 请求到对应的控制器类的方法

springboot-rest-service's People

Contributors

xjiaqing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.