springboot - 2 创建项目
2019-09-30 本文已影响0人
lkd_wang
先创建一个简单的maven项目


随便起一个项目名

添加maven依赖
<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</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springBoot Maven Webapp</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>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>springBoot</finalName>
</build>
</project>
创建一个启动类

package com.wyl.boot;
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);
}
}
创建一个请求类

package com.wyl.boot.MyFirstController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/first")
public class FirstController {
@RequestMapping(value = "/hello", produces = "application/json;charset=UTF-8")
private String selectPriceAccount() {
return "hello world";
}
}
启动项目,试着访问下

给项目起个名字,换个端口试试(注意yaml格式)

spring:
application:
name: springBoot
server:
port: 8089
servlet:
context-path: /springBoot
重启项目,访问下
