工具
- IDEA
- Maven
项目创建
1. 通过IDEA创建SpringBoot项目
2. 结构目录和JAVA版本选择
3. 添加MySQL和MyBatis支持
4. 添加Lombok插件,简化GET、SET方法
5. WEB支持和启动类
6. 项目名和路径
启动类
package com.attendance;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.attendance.mapper")
public class ProjectApplication {
public static void main(String[] args) {
SpringApplication.run(ProjectApplication.class, args);
}
}
@MapperScan注解指明同一扫描路径
基于XML
1. application.yml(采用更简洁的yml文件配置方式,与properties大同小异)
数据库配置
server:
port: 7070
spring:
datasource:
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/attendance?useUnicode=true&useSSL=false&characterEncoding=UTF-8
MyBatis配置
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.attendance.entity
mapper-locations:指明MyBatis的xml文件所在位置
type-aliases-package: 指明实体类所在位置