Spring boot项目创建和配置文件

本文详细介绍SpringBoot项目的创建步骤及配置过程,包括添加依赖、配置文件设置与测试代码实现等核心内容。通过实例演示如何使用SpringBoot快速构建应用程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建项目流程

在这里插入图片描述
在这里插入图片描述

添加需要的依赖(要用就钩)

lombok
在这里插入图片描述
Spring分布式Session
在这里插入图片描述
页面相关
在这里插入图片描述
spring的安全框架
在这里插入图片描述
数据库
在这里插入图片描述
启动类(springboot项目启动不需要添加到tomcat直接启动该类即可)
在这里插入图片描述

测试代码与配置文件

pom依赖

		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

注意把test给注释
在这里插入图片描述

配置文件

这里文件后缀已经被我修改成了yml在这里插入图片描述

测试代码

配置文件内容对应的实体类
在这里插入图片描述
Controller

package com.rong.springboot01.controller;

import com.rong.springboot01.configurationProperties.MysqlEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Ivan
 * @company xxx公司
 * @create  2020-11-26 18:45
 */
@RestController
public class HelloController {

    @Value("${user.uname}")
    private String uname;
    @Value("${user.pwd}")
    private String pwd;

    @Autowired
    private MysqlEntity mysqlEntity;

    @RequestMapping("/hello1")
    public String hello1(){
        return "hello springboot!";
    }

    @RequestMapping("/hello")
    public String hello(){
        return "hello springboot 你大爷";
    }

    @RequestMapping("/say1")
    public String say1(String name){
        return name + "say hello springboot 你大爷";
    }

    @RequestMapping("/say2/{name}")
    public String say2(@PathVariable("name") String name){
        return name + "say hello springboot 你大爷";
    }

    @RequestMapping("/json")
    public Map returnJson(){
        Map map = new HashMap();
        map.put("success",true);
        map.put("msg","恭喜你中奖了!!!");
        return map;
    }

    @RequestMapping("/say3")
    public Map say3(){
        Map map = new HashMap();
        map.put("uname",uname);
        map.put("pwd",pwd);
        return map;
    }

    @RequestMapping("/say4")
    public MysqlEntity say4(){
        return mysqlEntity;
    }

}

效果

运行成功后去浏览器输入方法对应的路径即可
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值