如题
1)新建一个项目:
2)选择【Spring Initializr】,然后点击【Next】:
3)把项目信息写好,【Next】:
4)依次勾选所需设置,然后【Next】:
5)修改项目名和项目地址,【Finish】:
6)点击加载Maven(右下角):
7)等待Maven自动加载完成后,最初的项目结构如下图。在Springboot属性文件application.properties中,把数据库连接属性加上,同时可以设置服务端口:
spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
#页面热加载
spring.thymeleaf.cache = false
#端口
server.port=8888
8)【resources】目录下,【static】文件夹是放置各种静态资源,如css,js,img等文件的。【templates】文件夹则是默认放置网页的。当然也可以更改。PS.不晓得为啥没有,手动新建。
【static】下新建一个测试test.css,【templates】下新建一个hello.html:
9)写一个controller:
package com.qingqiuyue.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("index")
public String index() {
return "hello";
}
}
10)启动,完事~
PS.简单的小demo,但没跟数据库做交互
原文链接
idea+springboot+Mybatis搭建web项目:https://www.cnblogs.com/legoo/p/7646920.html