创建项目流程


添加需要的依赖(要用就钩)
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;
}
}
效果
运行成功后去浏览器输入方法对应的路径即可

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

被折叠的 条评论
为什么被折叠?



