一.
目录
hellowrold Spring boot
准备工作:
- jdk 1.8
- maven3.0+
- Idea
- 创建项目 File -->new -->project;
- 选择spring Initializr 点击next
- 确定项目名称 Java version选择8,点击next
- Web下勾选Spring Web Start,(网上创建springboot项目多是勾选Web选项,而较高版本的 Springboot没有此选项,勾选Spring Web Start即可,2.1.8版本是Spring Web);Template Englines勾选Thymeleaf;SQL勾选:MySQL Driver,JDBC API 和 MyBatis Framework三项;点击next;
- 刚创建好的项目结构
- 开始项目 再java->com.example.demo2下新增一个controller包,再在包下新建一个Controller类
- Controller里面内容
package com.example.demo2.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Controller {
@RequestMapping("/hello")
public String hellowrold(){
return "hellowrold Spring boot!";
}
}
- application.properties内容
#访问根路径
#应用名称
spring.application.name=springboot-demo
#访问端口号
server.port=8080
#编码格式
server.tomcat.uri-encoding=utf-8
#数据库相关配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/sql_test
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
#session生命周期
server.servlet.session.timeout=30m
- 运行Demo2Application
- 出现以下内容就成功了
- 打开浏览器,在导航栏输入 http://localhost:8080/hello就可显示输出结果。
输出成功!
二.一些参考链接
IDEA创建SpringBoot项目输出hello world——新手教程(1)
报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedd