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 项目

 

转载于:https://www.cnblogs.com/liyouming/p/9450029.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值