本周工作为针对课程功能,进行后端实体类的编写和数据库的构建
一、后端实体类的编写
这里的工作主要为编写课程信息,课程分类,课程章节信息,课时信息,用户课程评论,课程用户学习日志等实体类的编写,主要为设置各属性,并为属性编写get(),set()方法,下面展示其中课程信息的实体类代码:
public class Course implements Serializable {
private Long id;
private LocalDateTime gmtCreate;
private LocalDateTime gmtModified;
private Integer statusId;
private Integer sort;
private Long lecturerId;
private String lecturerName;
private Long categoryId;
private String courseName;
private String courseLogo;
private Integer isFree;
private BigDecimal rulingPrice;
private BigDecimal coursePrice;
private Integer isPutaway;
private Integer courseSort;
private Integer countBuy;
private Integer countStudy;
private String introduce;
private String schoolName;
private Integer courseId;
private Integer courseType;
private Integer inviteNum;
private static final long serialVersionUID = 1L;
public String getLecturerName() {
return lecturerName;
}
public void setLecturerName(String lecturerName) {
this.lecturerName = lecturerName;
}
public Integer getInviteNum() {
return inviteNum;
}
public void setInviteNum(Integer inviteNum) {
this.inviteNum = inviteNum;
}
public Integer getCourseId() {
return courseId;
}
public void setCourseId(Integer courseId) {
this.courseId = courseId;
}
public Integer getCourseType() {
return courseType;
}
public void setCourseType(Integer courseType) {
this.courseType = courseType;
}
public String getSchoolName() {return schoolName;}
public void setSchoolName(String schoolName) {this.schoolName = schoolName;}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public LocalDateTime getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(LocalDateTime gmtCreate) {
this.gmtCreate = gmtCreate;
}
public LocalDateTime getGmtModified() {
return gmtModified;
}
public void setGmtModified(LocalDateTime gmtModified) {
this.gmtModified = gmtModified;
}
public Integer getStatusId() {
return statusId;
}
public void setStatusId(Integer statusId) {
this.statusId = statusId;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Long getLecturerId() {
return lecturerId;
}
public void setLecturerId(Long lecturerId) {
this.lecturerId = lecturerId;
}
public Long getCategoryId() {
return categoryId;
}
public void setCategoryId(Long categoryId) {
this.categoryId = categoryId;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName == null ? null : courseName.trim();
}
public String getCourseLogo() {
return courseLogo;
}
public void setCourseLogo(String courseLogo) {
this.courseLogo = courseLogo == null ? null : courseLogo.trim();
}
public Integer getIsFree() {
return isFree;
}
public void setIsFree(Integer isFree) {
this.isFree = isFree;
}
public BigDecimal getRulingPrice() {
return rulingPrice;
}
public void setRulingPrice(BigDecimal rulingPrice) {
this.rulingPrice = rulingPrice;
}
public BigDecimal getCoursePrice() {
return coursePrice;
}
public void setCoursePrice(BigDecimal coursePrice) {
this.coursePrice = coursePrice;
}
public Integer getIsPutaway() {
return isPutaway;
}
public void setIsPutaway(Integer isPutaway) {
this.isPutaway = isPutaway;
}
public Integer getCourseSort() {
return courseSort;
}
public void setCourseSort(Integer courseSort) {
this.courseSort = courseSort;
}
public Integer getCountBuy() {
return countBuy;
}
public void setCountBuy(Integer countBuy) {
this.countBuy = countBuy;
}
public Integer getCountStudy() {
return countStudy;
}
public void setCountStudy(Integer countStudy) {
this.countStudy = countStudy;
}
public String getIntroduce() {
return introduce;
}
public void setIntroduce(String introduce) {
this.introduce = introduce == null ? null : introduce.trim();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", gmtCreate=").append(gmtCreate);
sb.append(", gmtModified=").append(gmtModified);
sb.append(", statusId=").append(statusId);
sb.append(", sort=").append(sort);
sb.append(", lecturerId=").append(lecturerId);
sb.append(", categoryId=").append(categoryId);
sb.append(", courseName=").append(courseName);
sb.append(", courseLogo=").append(courseLogo);
sb.append(", isFree=").append(isFree);
sb.append(", rulingPrice=").append(rulingPrice);
sb.append(", coursePrice=").append(coursePrice);
sb.append(", isPutaway=").append(isPutaway);
sb.append(", courseSort=").append(courseSort);
sb.append(", countBuy=").append(countBuy);
sb.append(", countStudy=").append(countStudy);
sb.append(", introduce=").append(introduce);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append(",schoolName=").append(schoolName);
sb.append(",courseId=").append(courseId);
sb.append(",courseType").append(courseType);
sb.append(",inviteNum").append(inviteNum);
sb.append("]");
return sb.toString();
}
}
二、各实体类的mapper接口
各个实体类的mapper接口描述了对课程对象进行数据库操作的方法。这样的接口是由持久化框架(比如MyBatis)根据配置文件自动生成的,这些方法对应了对数据库表中课程数据的增删改查等操作。
public interface CourseMapper {
int countByExample(CourseExample example);
int deleteByExample(CourseExample example);
int deleteByPrimaryKey(Long id);
int insert(Course record);
int insertSelective(Course record);
List<Course> selectByExampleWithBLOBs(CourseExample example);
List<Course> selectByExample(CourseExample example);
Course selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") Course record, @Param("example") CourseExample example);
int updateByExampleWithBLOBs(@Param("record") Course record, @Param("example") CourseExample example);
int updateByExample(@Param("record") Course record, @Param("example") CourseExample example);
int updateByPrimaryKeySelective(Course record);
int updateByPrimaryKeyWithBLOBs(Course record);
int updateByPrimaryKey(Course record);
}