系列文章
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 项目