java,go,python,node.js四个hellowor
2021-01-05 本文已影响0人
万州客
作一个记录。
github:
https://github.com/aguncn/bifang-app-demo-src
一,java(spring boot)
package learn.springboot.helloworld;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;
/**
* Created by mac on 2021/01/04.
*/
@RestController
@EnableAutoConfiguration
public class Application {
@RequestMapping("/")
public String home() {
return "Hello, Java Spring Boot!";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
二,go
package main
import (
"fmt"
"log"
"net/http"
)
func doRequest(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello Golang!") //这个写入到w的是输出到客户端的
}
func main() {
http.HandleFunc("/", doRequest) //设置访问的路由
err := http.ListenAndServe(":9090", nil) //设置监听的端口
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
三,python(flask)
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Hello, Flask!"
if __name__ == '__main__':
app.run()
四,node.js
const http = require('http');
http.createServer(function(request, response) {
// 设置响应头
response.writeHeader(200, {
"Content-Type" : "text/plain"
});
// 响应主体为 "Hello world!"
response.write("Hello Node.js!");
response.end();
})
// 设置监听端口为9000
.listen(9000);