数据库创建
创建如下表
创建springboot程序
注:spring boot 3.0以上版本需要jdk17
选中的五个删除
此处发现pom.xml右侧没有maven窗口,点击帮助,查找操作,搜索maven,添加maven项目,把pom.xml路径导入即可
在pom.xml文件中添加如下依赖
将application.properties文件改写为application.yml文件并添加如下配置
#tomcat端口号
server:
port: 8080
spring:
application:
#应用名称
name: takeout
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/food?useSSL=false
password: 123456
username: root
mybatis-plus:
configuration:
#在映射实体或者属性时,将数据库的表名和字段名的下划线去掉,按驼峰命名
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: ASSIGN_ID
在spring boot启动类上添加注解@Slf4j
后台登陆功能
创建实体类Employee,和employee表进行映射
package com.mjk.takeout.pojo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String name;
private String password;
private String phone;
private String sex;
private String idNumber;
private Integer status;
private LocalDateTime createTime;
private LocalDateTime updateTime;
@TableField(fill = FieldFill.INSERT)
private Long createUser;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateUser;
}