学习进度条
今日所花时间:一小时
今日代码量:100行
博客量:一篇
了解到的知识点: 继续学习androidStudio 完成学习记录APP的开发
使用springboot作为后端
数据库设计
create table user
(
id bigint auto_increment comment '用户ID'
primary key,
student_id varchar(20) not null comment '学号',
username varchar(50) not null comment '用户名',
phone varchar(20) not null comment '手机号',
class_name varchar(100) not null comment '班级名称',
unit varchar(100) null comment '单位/ 学院',
password varchar(255) not null comment '用户密码',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
constraint idx_phone
unique (phone),
constraint idx_student_id
unique (student_id)
)
comment '用户表';
ALTER TABLE `user`
ADD COLUMN `password` varchar(255) NOT NULL COMMENT '用户密码' AFTER `unit`;
DESCRIBE `user`;
create table daily_summary
(
id bigint auto_increment
primary key,
user_id bigint not null comment '用户ID',
summary_date date not null comment '总结日期',
blog_url varchar(255) not null comment '博客链接',
create_time datetime default CURRENT_TIMESTAMP not null,
constraint idx_user_date
unique (user_id, summary_date)
)
comment '每日总结表';
create table programming_record
(
id bigint auto_increment
primary key,
user_id bigint not null comment '用户ID',
record_date date not null comment '记录日期',
psp_stage varchar(50) not null comment 'PSP阶段',
content text null comment '填写内容',
time_spent int null comment '花费时间(分钟)',
create_time datetime default CURRENT_TIMESTAMP not null
)
comment '编程记录表';
create index idx_user_date
on programming_record (user_id, record_date);
create table weekly_goal
(
id bigint auto_increment
primary key,
user_id bigint not null comment '用户ID',
goal_content text not null comment '目标内容',
week_start_date date not null comment '周开始日期(周一)',
create_time datetime default CURRENT_TIMESTAMP not null,
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP
)
comment '每周目标表';
create index idx_user_week
on weekly_goal (user_id, week_start_date);
实体类的构建
User
package com.example.searchdemo.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.persistence.*;
import java.util.Date;
@Entity
@Table(name = "user")
@Data
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "student_id", nullable = false, unique = true)
private String studentId;
@Column(name = "username", nullable = false)
private String username;
@Column(name = "phone", nullable = false, unique = true)
private String phone;
@Column(name = "class_name", nullable = false)
private String className;
@Column(name = "unit")
private String unit;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "create_time", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
@Column(name = "update_time", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
ProgrammingRecord
package com.example.searchdemo.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.persistence.*;
import java.util.Date;
@Entity
@Table(name = "programming_record")
@Data
public class ProgrammingRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "record_date", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date recordDate;
@Column(name = "psp_stage", nullable = false)
private String pspStage;
@Column(name = "content", columnDefinition = "text")
private String content;
@Column(name = "time_spent")
private Integer timeSpent;
@Column(name = "create_time", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Date getRecordDate() {
return recordDate;
}
public void setRecordDate(Date recordDate) {
this.recordDate = recordDate;
}
public String getPspStage() {
return pspStage;
}
public void setPspStage(String pspStage) {
this.pspStage = pspStage;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Integer getTimeSpent() {
return timeSpent;
}
public void setTimeSpent(Integer timeSpent) {
this.timeSpent = timeSpent;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
WeekGoal
package com.example.searchdemo.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.persistence.*;
import java.util.Date;
@Entity
@Table(name = "weekly_goal")
@Data
public class WeeklyGoal {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "goal_content", nullable = false, columnDefinition = "text")
private String goalContent;
@Column(name = "week_start_date", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date weekStartDate;
@Column(name = "create_time", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
@Column(name = "update_time", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getGoalContent() {
return goalContent;
}
public void setGoalContent(String goalContent) {
this.goalContent = goalContent;
}
public Date getWeekStartDate() {
return weekStartDate;
}
public void setWeekStartDate(Date weekStartDate) {
this.weekStartDate = weekStartDate;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
DailySumary
package com.example.searchdemo.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.persistence.*;
import java.util.Date;
@Entity
@Table(name = "daily_summary")
@Data
public class DailySummary {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id", nullable = false)
private Long userId;
@Column(name = "summary_date", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date summaryDate;
@Column(name = "blog_url", nullable = false)
private String blogUrl;
@Column(name = "create_time", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Date getSummaryDate() {
return summaryDate;
}
public void setSummaryDate(Date summaryDate) {
this.summaryDate = summaryDate;
}
public String getBlogUrl() {
return blogUrl;
}
public void setBlogUrl(String blogUrl) {
this.blogUrl = blogUrl;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
依赖导入
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>searchdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>searchdemo</name>
<description>searchdemo</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>3.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

浙公网安备 33010602011771号