spring boot入门学习---1

Posted 努力中国

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot入门学习---1相关的知识,希望对你有一定的参考价值。

1.maven配置

<?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.example</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <!-- Package as an executable jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

 

2.简单运行

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GirlApplication {
    public static void main(String[] args) {
        //启动方式
        SpringApplication.run(GirlApplication.class, args);
    }
}

 

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

@RestController
public class HelloController {
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String say() {
        return "Hello Spring Boot!";
    }
}

 

3.配置访问

配置文件application.properties指定访问端口和路径

server.port=8081
server.context-path=/girl

******

 

3.连接数据库属性文件配置

 

 

 

以上是关于spring boot入门学习---1的主要内容,如果未能解决你的问题,请参考以下文章

Spring boot 学习 入门

Spring Boot入门——使用模板FreeMaker

Spring Boot学习大全(入门)

1spring-boot学习笔记简单入门

spring boot学习总结-- 基础入门 Hello,spring boot!

spring的Java配置入门(Spring Boot学习之一)