0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JavaとPythonのHello World(http getバージョン)

Posted at

■前提

Javaのフレームワーク:spring boot
Pythonのフレームワーク:fastapi

■本題

Java

ファイル

HelloApplication.java
package com.example.hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloApplication {

	public static void main(String[] args) {
		SpringApplication.run(HelloApplication.class, args);
	}
}
GreetingController.java
package com.example.hello;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {
	private static final String template = "Hello, %s!";
	private final AtomicLong counter = new AtomicLong();

	@GetMapping("/greeting")
	public Greeting greeting(@RequestParam(value="name", defaultValue="world") String name) {
		return new Greeting(counter.incrementAndGet(), String.format(template, name));
	}
}
Greeting.java
package com.example.hello;

public class Greeting {
	private final long id;

	private final String content;

	// コンストラクタ
	public Greeting(long id, String content) {
		this.id = id;
		this.content = content;
		this.higaGreeting();
		Greeting.higaGreeting2();
	}

	// Getters
	public long getId() {
		return id;
	}
	public String getContent() {
		return content;
	}
}

Python

python -m venv venv
pip install fastapi
pip install uvicorn[standard]
main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
    return {"message":"Hello World"}

■所感

何を大事にするか、生きている間は考え続けますか

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?