0
Help us understand the problem. What are the problem?

posted at

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

■前提

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"}

■所感

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

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
0
Help us understand the problem. What are the problem?