1. 创建项目
File——>Spring Starter Project,
,这个页面应该都可以看懂。next——》
可以添加一些你需要的依赖,这里只是apache的maven架包。点击Finish。
2.引入依赖
在生成的都pom文件中引入依赖
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-thymeleaf
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
mysql
mysql-connector-java
runtime
com.alibaba
druid
1.1.6
org.springframework.boot
spring-boot-starter-tomcat
provided
com.alibaba
fastjson
1.2.4
com.gitee.sunchenbin.mybatis.actable
mybatis-enhance-actable
1.0.3
org.springframework.boot
spring-boot-starter-test
test
耐心等下方的进度条到100%,表示架包全部引入成功,
这时候项目初始化就完成了,可以点击运行(Spring Boot APP)
出现这个图标就表示项目运行成功了
3.写配置文件
虽然说spring帮你省去了很多繁琐的配置(约定大于配置),但关键的配置还是必不可少的:在application.properties中做如下配置
# 指定端口号
server.port=8081
#指定访问的前缀
server.servlet.context-path=/menu
# thymeleaf 静态资源配置
spring.thymeleaf.prefix=classpath:/templates/thymeleaf/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html; charset=utf-8
# 关闭缓存,及时刷新,上线生产环境需要改为true
spring.thymeleaf.cache=false
# 设置静态文件路径
spring.mvc.static-path-pattern=/static/**
# 数据源配置——druid数据源
spring.datasource.url=jdbc:mysql://localhost:3306/menu_v1
spring.datasource.username=你的数据库账号
spring.datasource.password=你的数据库密码
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.initial-size=1
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-active=20
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.stat-view.servlet.allow=true
# mybatis配置
mybatis.type-aliases-package=com.example.pojo
mybatis.mapper-locations=classpath:mapper/*.xml
在resources中建如下的文件夹。
mapper : mybatis的mapper文件(sql写在mapper中方便后期做数据库优化)
static:存放静态资源(js,css,图片等)
templates:存放系统前端页面

4.建包
java文件夹下建如下包,必须都在example包下,否则spring-boot找不到
在程序入口类做如下配置:就是加上两个标签
@SpringBootApplication
@MapperScan(basePackages="com.example.dao")
public class MenuV2Application {
public static void main(String[] args) {
SpringApplication.run(MenuV2Application.class, args);
}
}
到此,项目配置就全部完成了
5.写controller

service接口

service实现类

实体类在pojo包下创建
创建dao

写SQL

数据库表字段的创建略去。
到这里就全部完成了。