1.实现后台登录代码。
---创建springboot项目进行环境搭建
导入数据库vhr
---pom文件中导入数据库驱动
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
---配置数据源和实体类,导入数据库之后进行逆向工程根据数据库文件,进行相关是实体类和接口数据库查询文件,
之后在springboot的启动类中配置mybatis
package com.liuboss.vhr;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan(basePackages = "com.liuboss.vhr.mapper")
public class VhrApplication {
public static void main(String[] args) {
SpringApplication.run(VhrApplication.class, args);
}
}
@MapperScan(basePackages = "com.liuboss.vhr.mapper")扫描所有接口和数据数据库文件
---在pom文件配置mapper的映射路径,正常应该放到resources文件目录下,将不会被扫描,配置扫描路径
<build>
<!--配置mapper映射路径-->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
application.properties 中配置数据库连接
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql:///vhr?useUnicode=true&characterEncoding=UTF-8
后端环境搭建完成
开发后端登录接口