zoukankan      html  css  js  c++  java
  • 编写第一个springboot应用

    1.1.1.   设置spring boot的parent

    <parent>
    
          <groupId>org.springframework.boot</groupId>
    
          <artifactId>spring-boot-starter-parent</artifactId>
    
          <version>1.5.2.RELEASE</version>
    
       </parent>

    说明:Spring boot的项目必须要将parent设置为spring boot的parent,该parent包含了大量默认的配置,大大简化了我们的开发。

    1.1.2.   导入spring boot的web支持

    <dependency>
    
            <groupId>org.springframework.boot</groupId>
    
            <artifactId>spring-boot-starter-web</artifactId>
    
          </dependency>
    

      

    1.1.3.   添加Spring boot的插件

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

    1.1.4.   编写第一个Spring Boot的应用

    @Controller
    
    @SpringBootApplication
    
    @Configuration
    
    public class HelloApplication {
    
       
    
        @RequestMapping("hello")
    
        @ResponseBody
    
        public String hello(){
    
            return "hello world!";
    
        }
    
       
    
        public static void main(String[] args) {
    
            SpringApplication.run(HelloApplication.class, args);
    
        }
    
     
    
    }
    
     
    

    代码说明:

    1、@SpringBootApplication:Spring Boot项目的核心注解,主要目的是开启自动配置。;

    2、@Configuration:这是一个配置Spring的配置类;

    3、@Controller:标明这是一个SpringMVC的Controller控制器;

    4、main方法:在main方法中启动一个应用,即:这个应用的入口;

    1.1.5.   启动应用

    在Spring Boot项目中,启动的方式有两种,一种是直接run Java Application另外一种是通过Spring Boot的Maven插件运行。

    第一种:

     

    第二种:

     

    启动效果:

     

    看到如下信息就说明启动成功了:

    INFO 6188 --- [           main] c.i.springboot.demo.HelloApplication     : Started HelloApplication in 3.281 seconds (JVM running for 3.601)

    1.1.6.   测试

    打开浏览器,输入地址:

     

    效果:

     

    是不是很Easy?

  • 相关阅读:
    registration system(map+思维)
    Codeforces 158B:Taxi(贪心)
    牛客小白月赛24 B-组队(二分)
    CF58C Trees(逆向思维)
    lower_bound和upper_bound学习笔记
    POJ--2689Prime Distance(区间素数筛)
    Codeforces Round #635 (Div. 2)
    navicat premium安装,使用
    Oracel 之PL/SQL Developer使用
    PLSQL,sql语句中带有中文的查询条件查询不到数据
  • 原文地址:https://www.cnblogs.com/renshengruozhiruchujian/p/7799189.html
Copyright © 2011-2022 走看看