码迷,mamicode.com
首页 > 编程语言 > 详细

springboot入门案例

时间:2019-10-09 23:59:05      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:stc   prope   maven   work   ret   config   png   ack   div   

一、引入依赖

1.springboot项目必须继承springboot父工程

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

2.springboot开发web项目,所需要的依赖(也叫场景启动器) 

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

 项目的pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>springbootDemo</artifactId>
    <version>1.0-SNAPSHOT</version>

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

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

 二、编写配置文件application.properties(可以不写任何东西)

技术图片

三、创建相关类
  如上图
  IndexController类
 
package com.company.hf.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author wangsy
 * @Date 2019/10/9 15:16
 **/
@RestController
public class IndexController {

    @GetMapping("/index")
    public String hello(){
        return "hello";
    }
}

  BootApplication类是该项目的启动类

package com.company.hf;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Author wangsy
 * @Date 2019/10/9 15:16
 **/
@SpringBootApplication    
public class BootApplication {

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

  

springboot入门案例

标签:stc   prope   maven   work   ret   config   png   ack   div   

原文地址:https://www.cnblogs.com/itheima-wsy/p/11645094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!