SpringBoot入门程序适合新手基础知识

一、使用Maven方式构建SoringBoot项目

在准备写程序之前,我们的开发工具下载必不可少,建议大家官网下载:Spring | Home

1.1新建项目

首先选择File,然后选择New,最后选择Prohect

1.2 创建Maven项目

在你的项目pom.xml添加相关依赖

<!-- 引入Spring Boot依赖 -->
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.1.3.RELEASE</version>
</parent>
<dependencies>
	<!-- 引入Web场景依赖启动器 -->
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
</dependencies>


1.3 编写主程序启动类

首先创建一个包

新建一个ManualChapter01Application.java

ackage org.lzpu;
mport org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;
SpringBootApplication
public class ManualChapter01Application {
    public static void main(String[] args) {
        SpringApplication.run(ManualChapter01Application.class, args);
    }
}

1.4 创建一个用于访问的Controller

在项目创建一个Controller包,在该包下创建一个HelloController的控制类

package org.lzpu.controller;

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

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello(){
        return "hello Spring Boot";
    }
}

1.5  运行项目ManualChapter01Application.java

在浏览器输入localhost:8080/hello得出结果

二、SpringBoot的核心配置与注解

在resource目录下自动生成空的application.propertes文件,把相关代码放进去

2.1新建一个Pet的类和Person的类

Pet的代码块:

package org.lzpu.domain;

public class Pet {

    private String type;
    private String name;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Pet{" +
                "type='" + type + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}

Person的代码块:

package org.lzpu.domain;

    import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.TimeToLive;
import org.springframework.data.redis.core.index.Indexed;
import java.util.List;
import java.util.concurrent.TimeUnit;


    @Redis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值