• SpringBoot HelloWorld


    SpringBoot 是 基于Spring 开发的J2EE 一站式解决方案,近几年非常火热,今天刚入门,把自己的 SpringBoot 版的 HelloWorld 记录一下,以便后续整理,也希望各位大佬多多指教,感谢。

    1、创建 Maven 工程
    2、导入 Spring Boot 相关依赖

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

     3、编写主程序:启动 Spring Boot 应用 

    /**
     * @SpringBootApplication 标注主程序:说明此类是 SpringBoot 应用
     */
    @SpringBootApplication
    public class HelloWorldMainApplication {
        public static void main(String[] args) {
            //springboot 应用启动
            SpringApplication.run(HelloWorldMainApplication.class, args);
        }
    }

     4、编写业务逻辑 

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

    5、启动主程序,测试

    http://localhost:8080/hello

    页面响应:Hello World

    6、简化部署

    pom 文件添加如下内容

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    在 IDEA 右侧边栏,maven --> lifecycle--运行 package 命令进行打包,然后启动打包后的 jar 文件,访问 http://localhost:8080/hello 即可;

  • 相关阅读:
    基本语句
    mysql多表查询方法(join)
    MySQL JOIN 多表连接
    MySQL SHOW INDEX语法的实际应用
    1.索引作用
    MySQL索引和优化查询
    mysql复合索引、普通索引总结
    mysql 索引相关
    for循环的break和continue
    保护程序猿滴眼睛---修改VS 2012 编辑器颜色
  • 原文地址:https://www.cnblogs.com/wdh01/p/12677092.html
Copyright © 2020-2023  润新知