需要关于在Spring boot中使用数据库关系向mysql发送数据的完整信息吗

需要关于在Spring boot中使用数据库关系向mysql发送数据的完整信息吗,mysql,spring,hibernate,spring-boot,Mysql,Spring,Hibernate,Spring Boot,我是Spring boot新手,计划使用Spring boot和Mysql构建学校管理网应用程序。但是,在将学生数据发送到他的类别时,我遇到了问题。有一个单独的表叫做“Faculty”,我将从表“student”发送数据。问题在于表格中有“选择选项”为特定教员发送数据。但是,显示未知错误,我不明白为什么?如果您使用表单中的选择选项向我发送有关将数据发送到类别的完整信息,我将不胜感激。下面是我尝试过的: StudentController.class package io.adu.Contro

我是Spring boot新手,计划使用Spring boot和Mysql构建学校管理网应用程序。但是,在将学生数据发送到他的类别时,我遇到了问题。有一个单独的表叫做“Faculty”,我将从表“student”发送数据。问题在于表格中有“选择选项”为特定教员发送数据。但是,显示未知错误,我不明白为什么?如果您使用表单中的选择选项向我发送有关将数据发送到类别的完整信息,我将不胜感激。下面是我尝试过的:

StudentController.class


package io.adu.Controllers;

  import java.lang.reflect.Method; import java.util.Arrays; import
  java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired; import
  org.springframework.stereotype.Controller; import
  org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import
  org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import
  org.springframework.web.bind.annotation.PathVariable; import
  org.springframework.web.bind.annotation.PostMapping; import
  org.springframework.web.bind.annotation.RequestBody; import
 org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import io.adu.DAO.Faculty; 
  import io.adu.DAO.Student;
import io.adu.DAO.User;
import io.adu.Repository.FacultyRepository; 
  import  io.adu.Repository.StudentRepository; 
  import io.adu.Service.StudentService;

  @Controller 
  public class StudentController {

  @Autowired 
  StudentService service;

  @Autowired 
  FacultyRepository repository;
  @Autowired
 StudentRepository studentRepository;    

  @GetMapping("/addStudent")
  public String viewStudentsList(Model model) {
      List<Student>students = studentRepository.findAll();
      List<Faculty>faculties = repository.findAll();
      model.addAttribute("addstudent",true);
      model.addAttribute("students",students);
      model.addAttribute("faculties",faculties);
      return "addStudent";

  }

  @PostMapping("/addStudent")
  public String showStudents(@Valid @ModelAttribute("addStudent")Student student,BindingResult result,ModelMap model){
      Student student = new Student();
      List<Faculty>faculties = repository.findAll();

      model.addAttribute("Student",student);
        model.addAttribute("faculty",new faculty());
          model.addAttribute("addstudent",true);
         service.addStudent(student);
      return "addStudent";
  }





 StudentEntity.class

    @Entity
    @Table(name="student")
    public class Student implements Serializable {

        private static final long serialVersionUID = 1L;

        @Id
        @Column(name="student_id")
        private int id;
        @Column(name="student_name")
        private String name;
        @Column(name="student_email")
        private String email;
        //@Column(name="student_name")
        //private String faculty;
        @Column(name="paid_amount")
        private String paidamount;


        @GeneratedValue(strategy=GenerationType.IDENTITY)


         @ManyToOne
            @JoinTable(name = "faculty_students",
                        joinColumns =  @JoinColumn(name = "student_id"),
                        inverseJoinColumns = @JoinColumn(name = "faculty_id"))
        private Faculty faculty;

        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getEmail() {
            return email;
        }
        public void setEmail(String email) {
            this.email = email;
        }
        public String getFaculty() {
            return faculty;
        }
        public void setFaculty(String faculty) {
            this.faculty = faculty;
        }
        public String getPaidamount() {
            return paidamount;
        }
        public void setPaidamount(String paidamount) {
            this.paidamount = paidamount;
        }




    }
StudentController.class
组件io.adu.Controller;
导入java.lang.reflect.Method;导入java.util.array;进口
java.util.List;
导入javax.validation.Valid;
导入org.springframework.beans.factory.annotation.Autowired;进口
org.springframework.stereotype.Controller;进口
org.springframework.ui.Model;
导入org.springframework.ui.ModelMap;
导入org.springframework.validation.BindingResult;
进口
org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.bind.annotation.ModelAttribute;
进口
org.springframework.web.bind.annotation.PathVariable;进口
org.springframework.web.bind.annotation.PostMapping;进口
org.springframework.web.bind.annotation.RequestBody;进口
org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入io.adu.DAO.Faculty;
导入io.adu.DAO.Student;
导入io.adu.DAO.User;
导入io.adu.Repository.FacultyRepository;
导入io.adu.Repository.StudentRepository;
导入io.adu.Service.StudentService;
@控制器
公共班级学生控制员{
@自动连线
学生服务;
@自动连线
实验室存储库;
@自动连线
StudentRepository StudentRepository;
@GetMapping(“/addStudent”)
公共字符串viewStudentsList(模型){
ListStudentRespository.findAll();
Listfaculties=repository.findAll();
model.addAttribute(“addstudent”,true);
model.addAttribute(“学生”,学生);
添加属性(“学院”,学院);
返回“addStudent”;
}
@后映射(“/addStudent”)
公共字符串showStudents(@Valid@modeldattribute(“addStudent”)Student Student,BindingResult,ModelMap model){
学生=新生();
Listfaculties=repository.findAll();
model.addAttribute(“学生”,学生);
model.addAttribute(“faculty”,新faculty());
model.addAttribute(“addstudent”,true);
服务。添加学生(学生);
返回“addStudent”;
}
学生人数
@实体
@表(name=“student”)
公共类学生实现可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@列(name=“student\u id”)
私有int-id;
@列(name=“学生姓名”)
私有字符串名称;
@列(name=“学生电子邮件”)
私人字符串电子邮件;
//@列(name=“学生姓名”)
//私人弦乐学院;
@列(name=“已付金额”)
私有字符串paidamount;
@GeneratedValue(策略=GenerationType.IDENTITY)
@许多酮
@JoinTable(name=“教员\学生”,
joinColumns=@JoinColumn(name=“student\u id”),
inverseJoinColumns=@JoinColumn(name=“faculty\u id”))
私人教师;
公共int getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共字符串getEmail(){
回复邮件;
}
公用电子邮件(字符串电子邮件){
this.email=电子邮件;
}
公共字符串getFaculty(){
返回教师;
}
公共无效设置功能(字符串功能){
这个。系=系;
}
公共字符串getPaidamount(){
返回paidamount;
}
公共void setPaidamount(字符串paidamount){
this.paidamount=paidamount;
}
}
StudentForm.html

 <form th:action="@{/addStudent}"  th:Object="${addStudent}" method="post">
                                <div class="card-body card-block">
                                    <div class="form-group">
                                        <label for="company" class=" form-control-label">Ismi</label>
                                        <input type="text" id="company" placeholder="Talaba ismini kiriting" class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <label for="vat" class=" form-control-label">To'langan summa</label>
                                        <input type="text" id="vat" class="form-control">
                                    </div>
                                    <div class="form-group">
                                        <label for="street" class=" form-control-label">fakulteti</label>
                                    <select class="form-control"  th:field="${addStudent.faculties}" th:disabled="${disableFields}">
            <option th:each="faculty :${faculties}" th:value="${faculty.facultyId}" th:text="${faculty.FacultyName}">
            </option>
            </select>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col-8">
                                            <div class="form-group">
                                                <label for="city" class=" form-control-label">Elektron pochtasi</label>
                                                <input type="text"  class="form-control">
                                            </div>
                                        </div>
                                        <div class="col-8">
                                            <div class="form-group">
                                                <label for="postal-code" class=" form-control-label">Status</label>
                                                <input type="text" placeholder="Budjed-Kontrakt" class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="country" class=" form-control-label">Tugilgan Sana</label>
                                        <input type="text" id="country" class="form-control">
                                    </div>
                                        <button type="submit" class="btn btn-primary btn-sm">
                                        <i class="fa fa-dot-circle-o"></i> Submit
                                    </button>

                                </div> </form>

伊斯米
托兰干summa酒店
法库尔蒂
波希塔西电子公司
地位
图吉尔根萨那
提交
日志错误

Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringSelectFieldTagProcessor' (template: "addStudent" - line 299, col 71)
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleOpenElementEnd(TemplateHandlerAdapterMarkupHandler.java:304) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:278) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleOpenElementEnd(OutputExpressionInlinePreProcessorHandler.java:186) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleOpenElementEnd(InlinedOutputExpressionMarkupHandler.java:124) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.attoparser.HtmlElement.handleOpenElementEnd(HtmlElement.java:109) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.attoparser.HtmlMarkupHandler.handleOpenElementEnd(HtmlMarkupHandler.java:297) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.attoparser.MarkupEventProcessorHandler.handleOpenElementEnd(MarkupEventProcessorHandler.java:402) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.attoparser.ParsingElementMarkupUtil.parseOpenElement(ParsingElementMarkupUtil.java:159) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:710) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    ... 85 common frames omitted
Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'addStudent' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:258) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    ... 98 common frames omitted

2020-02-03 21:02:59.704 ERROR 13336 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/addStudent.html]")] with root cause

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'addStudent' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:258) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
    at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleOpenElementEnd(TemplateHandlerAdapterMarkupHandler.java:304) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
原因:org.thymeleaf.exceptions.temp