Spring Boot - Helloworld

Download Spring Initializer

HelloController.java
package com.example.demo;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;


@RestController
public class HelloController {

    @GetMapping
    public String hello(@RequestParam(defaultValue = "", required = false) String name) {
        return "hello " + name;
    }

    @GetMapping("/ids")
    public Flux<String> ids() {
        return Flux.just("1","2","3");
    }
}

Run bootRun
gradle bootRun
Starting a Gradle Daemon, 1 busy and 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

> Task :bootRun

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::        (v2.2.7.RELEASE)


2020-05-12 23:30:11.100  INFO 6864 --- [  restartedMain] com.example.demo.DemoApplication         : Starting DemoApplication on isaac-PC with PID 6864 (C:\Users\isaac\workspace_github\study-practice\build\classes\java\main started by isaac in C:\Users\isa
ac\workspace_github\study-practice)
2020-05-12 23:30:11.103  INFO 6864 --- [  restartedMain] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2020-05-12 23:30:11.150  INFO 6864 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-05-12 23:30:11.150  INFO 6864 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-05-12 23:30:12.218  INFO 6864 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2020-05-12 23:30:12.470  INFO 6864 --- [  restartedMain] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 8080
2020-05-12 23:30:12.475  INFO 6864 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 1.683 seconds (JVM running for 2.171)
<=========----> 75% EXECUTING [52s]
> :bootRun

Curl example
$ curl -s http://localhost:8080/ids
123

$ curl -s http://localhost:8080
hello

$ curl -s http://localhost:8080?name=QQQ
hello QQQ



沒有留言:

張貼留言

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法...