Java Spring Boot VS .NetCore (一)來一個簡單的 Hello World


 

系列文章

Java Spring Boot VS .NetCore (一)來一個簡單的 Hello World

Java Spring Boot VS .NetCore (二)實現一個過濾器Filter

Java Spring Boot VS .NetCore (三)Ioc容器處理

Java Spring Boot VS .NetCore (四)數據庫操作 Spring Data JPA vs EFCore

Java Spring Boot VS .NetCore (五)MyBatis vs EFCore

Java Spring Boot VS .NetCore (六) UI thymeleaf vs cshtml

Java Spring Boot VS .NetCore (七) 配置文件

Java Spring Boot VS .NetCore (八) Java 注解 vs .NetCore Attribute

Java Spring Boot VS .NetCore (九) Spring Security vs .NetCore Security

Java Spring Boot VS .NetCore (十) Java Interceptor vs .NetCore Interceptor

Java Spring Boot VS .NetCore (十一)自定義標簽 Java Tag Freemarker VS .NetCore Tag TagHelper

今天開始學習Spring Boot,后面的文章會結合兩者區別一邊學習一邊理解用法上的區別

Java環境配置就不說明了

Java:

創建一個類 命名為 HomeController

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HomeController {
    @RequestMapping("/helloworld")

    public String Index()
    {
       return  "Hello World";
    }
}

.NetCore

using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace ExpressServices.Controllers
{
    public class HomeController : Controller
    {
        [Route("~/helloworld")]
        public IActionResult Index()
        {
            return Content("Hello World");
        }
    }
}

路由區別

路由:@RequestMapping("/helloworld")  vs   [Route("~/helloworld")]

包引用區別

import org.springframework.web.bind.annotation.RestController

using Microsoft.AspNetCore.Mvc;



主程序入口

@SpringBootApplication
public class DemoApplication {


    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
               .UseUrls("http://localhost:20002")
                .UseStartup<Startup>();
    }

都有很多相似之處,思想上沒什么區別,所以 一個Hello World 很快就搞定了~

運行下Spring Boot 項目

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM