我是靠谱客的博主 幸福香烟,这篇文章主要介绍IDEA创建SpringBoot项目输出hello world——新手教程(1),现在分享给大家,希望可以做个参考。

  1. idea新建项目

在这里插入图片描述

  1. 点击next
    在这里插入图片描述
  2. 点击next
    在这里插入图片描述
  3. 点击next
    在这里插入图片描述
  4. 点击finish,看是否和我生成的一样
    在这里插入图片描述
  5. 新建web入口类
    在这里插入图片描述
  6. 配置pom.xml,所有的依赖文件都在里面配置,比如数据库驱动
    `
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?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.1.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.shaotianyou</groupId> <artifactId>springboot-first-project</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot-first-project</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.25</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
  1. 配置aplication.properties文件
复制代码
1
2
3
4
5
spring.datasource.url=jdbc:mysql://localhost:3306/schooltao?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true spring.datasource.username=xxx spring.datasource.password=xxx spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  1. HelloWorld.java
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.shaotianyou.springbootfirstproject; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @Component @RequestMapping("/springboot") public class HelloWorld { @RequestMapping(value = "hello",method = RequestMethod.GET) public String sayHello(){ return "Hello"; } }

启动项目
在这里插入图片描述最后在地址栏上输入localhost:8080/springboot/hello就能够看到方法中返回的字符串

最后

以上就是幸福香烟最近收集整理的关于IDEA创建SpringBoot项目输出hello world——新手教程(1)的全部内容,更多相关IDEA创建SpringBoot项目输出hello内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部