⼀个vue页⾯实现Mysql数据表(三表)的增删改查、分页、表连接实体类
Student.java
package com.sdbairui.demo.Entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.util.Date;
import java.util.Set;
@Table
@Entity(name="student")
public class Student {
@Id//主键
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int sid;
private String sname;
private int sex;
@DateTimeFormat(pattern="yyyy-MM-dd")//转换⽇期格式将前台⽇期字符串转换成Date格式mysql菜鸟教程增删改查
@JsonFormat(pattern="yyyy-MM-dd",timezone="GMT+8")//将服务器端Date⽇期转换成指定字符串格式
private Date birth;
private String classes;
@OneToMany//⼀对多关系
@JoinColumn(name="sid",referencedColumnName ="sid",insertable =false,updatable =false)
private Set<Score> score;
public Set<Score>getScore(){
return score;
}
public void setScore(Set<Score> score){
this.score=score;
}
public void setSid(int sid){
this.sid=sid;
}
public int getSid(){
return this.sid;
}计算机数字代码大全
public void setSname(String sname){
this.sname=sname;
}
public String getSname(){
return this.sname;
}
public void setSex(int sex){
this.sex=sex;
}
public int getSex(){
return this.sex;
}
public void setBirth(Date birth){
this.birth = birth;
}
public Date getBirth(){
return this.birth;
return this.birth;
}
public void setClasses(String classes){
this.classes=classes;
}
public String getClasses(){
return this.classes;
}
}
Score.java
@Table
@Entity(name="Score")
public class Score {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int scid;
private int sid;
private int coid;
private float grade;
@OneToOne//⼀对⼀关系
@JoinColumn(name="coid",referencedColumnName ="coid",insertable =false,updatable =false) private Course course;
public Course getCourse(){
return course;
}
public void setCourse(Course course){
}
public void setScid(int scid){
this.scid=scid;
}
public int getScid(){
return this.scid;
}
public void setSid(int sid){
this.sid=sid;
}
public int getSid(){
return this.sid;
}
linux安装vimplus
public void setCoid(int coid){
}
public int getCoid(){
id;
}
public void setGrade(float grade){
}
public float getGrade(){
ade;
selected天猫旗舰店}
}
Course.java
@Table
@Entity(name="Score")
public class Score {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int scid;
private int sid;
private int coid;
private float grade;
@OneToOne
@JoinColumn(name="coid",referencedColumnName ="coid",insertable =false,updatable =false) private Course course;
public Course getCourse(){
return course;
}
public void setCourse(Course course){
}
public void setScid(int scid){
this.scid=scid;
}
public int getScid(){
return this.scid;
}
public void setSid(int sid){
this.sid=sid;
}
public int getSid(){
return this.sid;
}
public void setCoid(int coid){
}
public int getCoid(){
id;
}
public void setGrade(float grade){
}
public float getGrade(){
ade;
}
}
Controller 控制器层 StudentController.java
package com.sdbairui.demo.Controller;
import com.sdbairui.demo.Dao.StudentDao;
import com.sdbairui.demo.Entity.Student;
import com.sdbairui.demo.Service.StudentService;
import com.sdbairui.demo.Utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
//控制器
@Controller//解析为路径
@RequestMapping("/stu")
public class StudentController {
@Autowired//⾃动注解功能
StudentService studentService;
@Autowired//⾃动注解功能
StudentDao studentDao;
@RequestMapping(value ="/vue")//vue页⾯
public String vue(Model model){
return"index";
}
@RequestMapping("/toto")
@ResponseBody
public JsonResult toindex(){//查询全部
List<Map<String, Object>> data = studentService.findAllDa();
return new JsonResult(data,"获取列表成功");
}
@RequestMapping("/doDel")//vue 删除数据
public String doDel(HttpServletRequest request){
int sid = Integer.Parameter("sid"));
Student student =new Student();flash素材网站哪个好
student.setSid(sid);
studentService.doDelete(student);
return"redirect:/stu/vue";
}
@RequestMapping("/totoadd")//跳转添加
public String totoAdd(Model model){
List<Student> list= studentService.findAllData();
model.addAttribute("student",list);
return"vue_add";
}
@RequestMapping("/dodoadd")//vue  添加数据
@ResponseBody
public String add(@Validated Student student, BindingResult error){ if(error.hasErrors()){
FieldError().getDefaultMessage();
}
studentService.doCreate(student);xml文件怎么运行的
return"保存成功";
}
@RequestMapping("/edit")//vue  获取数据
@ResponseBody
public JsonResult edit(HttpServletRequest request){
int sid = Integer.Parameter("sid"));
Student student = studentService.findBySid(sid);
return new JsonResult<>(student,"获取学⽣编号"+sid+"数据成功");

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。