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

springboot - 应用实践(2)第一个springboot应用

时间:2019-09-16 00:56:40      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:url   mapping   name   run   依赖   pre   快速   web   unit   

1、使用maven创建一个快速启动项目

  技术图片

2、引入相关依赖

<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.lfy.cn</groupId>
  <artifactId>springbootTest-1.0.0</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>springbootTest-1.0.0</name>
  <url>http://maven.apache.org</url>
  
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.0.0.RELEASE</version>
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

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

3、HelloController.java

package com.lfy.cn.springbootTest;

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

@RestController
public class HelloController {

    @RequestMapping("/HelloController/hello")
    public String hello() {
        return "hello spring boot";
    }
}

4、App.java

package com.lfy.cn.springbootTest;

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

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class,args);
    }
}

5、在App.java中右键,作为Java Application启动运行

  技术图片

 

springboot - 应用实践(2)第一个springboot应用

标签:url   mapping   name   run   依赖   pre   快速   web   unit   

原文地址:https://www.cnblogs.com/ZeroMZ/p/11525056.html

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