• Spring Boot 编写入门程序


    1. SpringBoot 入门

    • 快速创建独立运行的Spring项目以及与主流框架集成;
    • 使用嵌入式的Servlet容器,应用无需打成WAR包;
    • starters自动依赖与版本控制;
    • 大量的自动配置,简化开发,也可修改默认值;
    • 无需配置XML,无代码生成,开箱即用;
    • 准生产环境的运行时应用监控;
    • 与云计算的天然集成;

    2. SpringBoot 之Hello World

    2.1 pom.xml 配置

    <parent>
      	  <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>1.5.9.RELEASE</version>
     </parent>
    
     <dependencies>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
     </dependencies>
    

    2.2 编写主程序,用于启动Spring Boot应用

    @SpringBootApplication
    public class HelloWorldMainApplication{
    
        public static void main(String[] args){
            SpringApplication.run(HelloWorldMainApplication.class,args);
        }
    }
    

    2.3 编写Controller

    @Controller
    public class HelloController{
        @ResponseBody
        @RequestMapping("/hello")
        public String hello(){
            return "Hello World!";
        }
    }
    

    3. HelloWorld 细节

    3.1 POM 文件

    <parent>
      	  <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>1.5.9.RELEASE</version>
     </parent>
    
     他的父项目
     <parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-dependencies</artifactId>
    		<version>1.5.9.RELEASE</version>
    		<relativePath>../../spring-boot-dependencies</relativePath>
    </parent>
    
    用来管理Spring Boot应用里面的所有依赖版本;
    

    3.2 导入的依赖(启动器)

    <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    spring-boot-starter: spring-boot 场景启动器,帮我们导入了Web模块正常运行所依赖的组件;
    

    4. 使用Spring starter Project创建Spring Boot应用

    4.1 默认生成的Spring Boot项目:

    • 主程序已经创建完成;
    • resources文件夹中目录结构:
      • static:保存所有的静态资源,JS,CSS,images;
      • templates:保存所有的模板页面;(Spring Boot默认jar包使用嵌入式的Tomcat,默认不支持JSP页面)
        可以使用模板引擎(freemarker,thymeleaf)
      • application.properties:Spring Boot应用的配置文件;

    参考资料:

  • 相关阅读:
    c语言中限制用户输入整数
    c语言 输入验证(限制输入正数)
    c语言中只读取输入的一行字符的首个字符
    python如何通过代码自动免密登陆ssh
    计算机科学速成课 02:电子计算机、继电器、术语“bug”的来源、真空管、晶体管、发展路径 转
    golang ...用法
    01 _ 程序的运行过程:从代码到机器运行
    深入Golang调度器之GMP模型 转
    golang可视化
    修改默认输入法,用英文标点符号
  • 原文地址:https://www.cnblogs.com/linkworld/p/9131570.html
Copyright © 2020-2023  润新知