Spring Boot
官网:https://spring.io/projects


一、快速搭建SpringBoot项目
1. 在线创建:https://start.spring.io/
2. IDEA 工具创建
1.
2.
二、了解Spring Boot 项目
1.

2.
3.
4.

5spring boot底层源码注解.


三、简单应用Spring Boot 项目
1.目录结构:

2.pom.xml文件:

3.DemoController类:

4.application.properties配置文件:

5.LxApplication类:

6.执行结果:

三、源码:
1.DemoController类:
@RestController
public class DemoController {
@Autowired
private JdbcTemplate jdbcTemplate;
@RequestMapping("/demo1")
public Map<String ,Object> demo1(){
Map<String ,Object> map=new HashMap<>();
map.put("data","你好spring Boot");
map.put("spring","spring boot is so cool");
List<Map<String, Object>> maps = jdbcTemplate.queryForList( "select * from user" );
map.put("user",maps);
return map;
}
}
2.LxApplication类:
@SpringBootApplication
public class LxApplication {
public static void main(String[] args) {
SpringApplication.run(LxApplication.class, args);
}
}
3.application.properties配置文件:
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql:///test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8
4.pom.xml文件:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>lx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lx</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<!--web-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--text-->
<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>
<!--jdbc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<scope>annotationProcessor</scope>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>annotationProcessor</scope>
</dependency>
<!--jdbc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
</dependencies>
<!--插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

这篇博客介绍了如何快速搭建Spring Boot项目,从在线创建到IDEA工具的使用,详细讲解了Spring Boot的基本概念,并通过实例展示了项目目录结构、pom.xml配置、DemoController和LxApplication的代码,以及application.properties配置文件的设置,帮助初学者理解Spring Boot的应用。



522

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



