zoukankan      html  css  js  c++  java
  • Hello Springboot

    微服务阶段

    javase:OOP

    mysql:持久化

    html+css+js+jquery+框架:视图

    javaweb:独立开发MVC三层架构的网站,原始

    ssm框架:简化了我们的开发流程,配置开始复杂

    war:tomcat运行

    spring再简化:SpringBoot - jar 内嵌tomcat,微服务架构

    服务越来越多:SpringCloud

    约定大于配置:maven,spring,springmvc,springboot,docker,...

    高内聚,低耦合!

    第一个SpringBoot程序

    • jdk 1.8
    • maven 3.6.1
    • springboot 最新版
    • IDEA

    官方:提供了一个快速生成的网站 https://start.spring.io/ ,IDEA继承了这个网站!

    • 可以在官网直接下载后,导入idea开发

    整体结构

    HelloworldApplication.java

    package com.peng.helloworld;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    //程序的主入口
    @SpringBootApplication
    public class HelloworldApplication {
    
    	public static void main(String[] args) {
    		//SpringApplication
    		SpringApplication.run(HelloworldApplication.class, args);
    	}
    }
    

    application.properties 空的配置文件

    # springboot 核心配置文件
    

    HelloworldApplicationTests.java 测试类

    package com.peng.helloworld;
    
    import org.junit.jupiter.api.Test;
    import org.springframework.boot.test.context.SpringBootTest;
    
    //单元测试
    @SpringBootTest
    class HelloworldApplicationTests {
    	@Test
    	void contextLoads() {
    	}
    }
    

    HelloController.java

    package com.peng.helloworld.controler;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class HelloController {
    
        //接口:http://localhost:8080/hello
        @RequestMapping("/hello")
        public String hello(){
            //调用业务,接受前端的参数
            return "hello,world";
        }
    }
    

    直接执行

    发现自带一个error接口

    双击package打包服务

    生成可执行的jar文件

    在cmd中运行

    在浏览器中还能运行,微服务思想,前后端分离

    • 直接使用idea创建一个springboot项目(一般开发直接在IDEA中创建)
  • 相关阅读:
    HttpServletRequest和HttpServletResponse
    .NET Core 通过 Ef Core 操作 Mysql
    spring-boot整合shiro实现权限管理
    spring-boot整合mongodb多数据源的案例
    spring-boot整合mybaits多数据源动态切换案例
    spring-boot整合Mybatis多数据源案例
    spring-boot整合mongodb的案例
    spring-boot和redis的缓存使用
    spring-boot 定时任务案例
    spring-cloud:熔断监控Hystrix Dashboard和Turbine的示例
  • 原文地址:https://www.cnblogs.com/peng8098/p/java_20.html
Copyright © 2011-2022 走看看