现在mysql里建了一个数据库毕业设计资料管理系统bs里面有如下表 学生表 create table student (sno varchar(10) primary key,sname varchar(20),spassword varbinary(20) not null); 管理员表 create table manager (mno varchar(10) primary key,mname varchar(20),mpassword varbinary(20) not null); 学生毕业设计表 create table gradu_design (gid int(10) AUTO_INCREMENT primary key,sno varchar(10),job_book TEXT,open_report TEXT,interim_report TEXT,week_report TEXT,gradu_paper TEXT,comment TEXT,FOREIGN KEY(sno) REFERENCES student(sno))AUTO_INCREMENT = 1; 管理员任务发布表 create table task (tid int(10) AUTO_INCREMENT primary key,mno int(10),title TEXT,content TEXT,subtime date,FOREIGN KEY(mno) REFERENCES manager(mno))AUTO_INCREMENT = 1; 请用idea里entity包中编写相应实体类和在dao包、bean包编写相应的东西,主要想实现以下功能管理员能发布任务,能查看学生毕设里的所有如(job_book、开题报告open_report、中期报告interim_report、周报week_report、毕业论文gradu_paper、文献翻译document),管理员有能对学生类实现增删改查的权限
时间: 2024-02-13 09:02:46 浏览: 206
学生成绩管理系统-数据库设计资料.pdf
好的,根据您提供的数据库表结构,我可以给您提供以下实体类和相关代码:
首先是实体类:
1. 学生表对应的实体类 Student.java
```java
@Entity
@Table(name = "student")
public class Student {
@Id
@Column(name = "sno")
private String sno;
@Column(name = "sname")
private String sname;
@Column(name = "spassword")
private byte[] spassword;
// getters and setters
}
```
2. 管理员表对应的实体类 Manager.java
```java
@Entity
@Table(name = "manager")
public class Manager {
@Id
@Column(name = "mno")
private String mno;
@Column(name = "mname")
private String mname;
@Column(name = "mpassword")
private byte[] mpassword;
// getters and setters
}
```
3. 学生毕业设计表对应的实体类 GraduDesign.java
```java
@Entity
@Table(name = "gradu_design")
public class GraduDesign {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "gid")
private int gid;
@Column(name = "sno")
private String sno;
@Lob
@Column(name = "job_book")
private String jobBook;
@Lob
@Column(name = "open_report")
private String openReport;
@Lob
@Column(name = "interim_report")
private String interimReport;
@Lob
@Column(name = "week_report")
private String weekReport;
@Lob
@Column(name = "gradu_paper")
private String graduPaper;
@Lob
@Column(name = "comment")
private String comment;
// getters and setters
}
```
4. 管理员任务发布表对应的实体类 Task.java
```java
@Entity
@Table(name = "task")
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "tid")
private int tid;
@Column(name = "mno")
private String mno;
@Column(name = "title")
private String title;
@Lob
@Column(name = "content")
private String content;
@Column(name = "subtime")
private Date subtime;
// getters and setters
}
```
接下来是DAO层的代码:
1. 学生表对应的DAO层 StudentDao.java
```java
@Repository
public interface StudentDao extends JpaRepository<Student, String> {
Student findBySno(String sno);
}
```
2. 管理员表对应的DAO层 ManagerDao.java
```java
@Repository
public interface ManagerDao extends JpaRepository<Manager, String> {
Manager findByMno(String mno);
}
```
3. 学生毕业设计表对应的DAO层 GraduDesignDao.java
```java
@Repository
public interface GraduDesignDao extends JpaRepository<GraduDesign, Integer> {
List<GraduDesign> findBySno(String sno);
GraduDesign findByGid(int gid);
}
```
4. 管理员任务发布表对应的DAO层 TaskDao.java
```java
@Repository
public interface TaskDao extends JpaRepository<Task, Integer> {
List<Task> findByMno(String mno);
Task findByTid(int tid);
}
```
最后是服务层的代码,即对学生表实现增删改查的权限:
1. 学生服务层 StudentService.java
```java
@Service
public class StudentService {
@Autowired
private StudentDao studentDao;
public List<Student> findAll() {
return studentDao.findAll();
}
public Student findBySno(String sno) {
return studentDao.findBySno(sno);
}
public void save(Student student) {
studentDao.save(student);
}
public void deleteBySno(String sno) {
studentDao.deleteById(sno);
}
public void update(Student student) {
studentDao.save(student);
}
}
```
以上就是根据您提供的数据库表结构给出的实体类、DAO层和服务层的代码,您可以根据需要进行调整和修改。
阅读全文