zoukankan      html  css  js  c++  java
  • Spring Boot入门

    1、到https://start.spring.io/生成springboot maven工程目录。

    2、springboot工程目录结构如下

    3、可以看到,生成的maven工程目录和普通的maven工程目录没什么区别。主要区别在于pom文件。

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>springboot</groupId>
      <artifactId>springboot-helloworld</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>springboot-helloworld</name>
      <url>http://maven.apache.org</url>
      
      <!-- Inherit defaults from Spring Boot -->
      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
      </parent>
    
      <!-- Add typical dependencies for a web application -->
      <dependencies>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
      </dependencies>
    
      <!-- Package as an executable jar -->
      <build>
        <plugins>
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
        </plugins>
      </build>
    </project>

    4、spring配置类如下,实际上是默认扫描配置包路径,生成IOC容器,并启动tomcat容器。

    package com.coshaho.springboot;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class,args);
        }
    }

    5、controller类,普通的rest接口。

    package com.coshaho.springboot;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class HelloWorldController {
    
        @RequestMapping("/")
        public String sayHello() {
            return "Hello,World!";
        }
    }

    6、运行结果。

  • 相关阅读:
    Java流程控制,用户交互scanner和运算结构
    Day14_Date类
    Day14_BigDecimal的使用
    Day14_StringBuffer和StringBuilder
    Day14_String概述
    装箱、拆箱面试题
    Day14_类型转换与装箱、拆箱
    简单的银行小案例
    Day12_面向对象 异常处理机制
    Day12_面向对象 异常机制
  • 原文地址:https://www.cnblogs.com/coshaho/p/10504677.html
Copyright © 2011-2022 走看看