SpringBoot快速搭建

SpringBoot快速搭建

导语

你好! 这是我第一次写 SpringBoot 的快速搭建。如果你想学习如何快速搭建SpringBoot, 可以仔细阅读这篇文章,了解一下SpringBoot的基本知识。

一.快速生成

访问链接: 快速生成SpringBoot.

步骤:Project中选择Maven Project
Language选择Java
Spring Boot版本选择,我这里选择2.26
Project Metadata根据自己的选择设置
最后点击 GENERATE CTRL 即可下载
解压到工作空间导入至idea

下面展示 SpringBootApplication

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"(controller包地址)","(service包地址)","(utils包地址)"})
@MapperScan(basePackages = {"(dao地址)"})
public class TyApplication {

	public static void main(String[] args) {
		SpringApplication.run(TyApplication.class, args);
		System.err.print("\033[34;4m" + "================================================Our Project-----Runing=====================================" + "\033[0m");
	}
}

连接数据库 application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/库名
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

依赖 pom.xml

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.30</version>
		</dependency>
		<!--访问静态资源图片-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
	</dependencies>

写一个Controller测试

@Controller
public class IndexController {

    @RequestMapping("/index")
    @ResponseBody
    public Map<String,String> index (){
        Map map = new HashMap<>();
        map.put("1","123");
        map.put("2","222");
        return map;
    }
}

网址输入http://localhost:8080/index

展示数据{"1":"耿耿","2":"程序员"}成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值