«HTTP Status 400» - в Spring MVC / Hibernate Form - PullRequest
0 голосов
/ 01 мая 2019

Я создавал приложение Spring MVC, которое использует SpringDataJPA и hibernate и использует MySQL.С какого-то момента я получаю HTTP Status 400 - Bad Request на одной из моих страниц, от которой я не смог избавиться.Можете ли вы показать мне, где моя конфигурация / код пошли не так?

Ошибка

Type Status Report

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Форма

<h5>Add Task</h5>
                <form:form method="POST" modelAttribute="main/tasks/add"
                    action="add/${project_id}">
                    <spring:bind path="tname">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="tname">Task Name:</form:label>
                            <form:input path="tname" placeholder="Enter Task Name" />
                        </div>
                    </spring:bind>
                    <spring:bind path="description">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="description">Description:</form:label>
                            <div>
                                <form:textarea path="description"
                                    placeholder="Enter Task Description" rows="5" cols="25" />
                            </div>
                        </div>
                    </spring:bind>
                    <spring:bind path="priority">
                        <div class="form-group ${status.error ? 'has-error' : ''}">
                            <form:label path="priority">Choose Priority:</form:label>
                            <form:select path="priority">
                                <option value="low">Low</option>
                                <option value="medium">Medium</option>
                                <option value="high">High</option>
                            </form:select>
                        </div>
                    </spring:bind>
                    <spring:bind path="sdate">
                        <div class="form-group"></div>
                        <form:label path="sdate">Choose Start Date:</form:label>
                        <form:input type="date" path="sdate" value="date" />
                    </spring:bind>
                    <spring:bind path="ddate">
                        <div class="form-group"></div>
                        <form:label path="ddate">Choose End Date:</form:label>
                        <form:input type="date" path="ddate" value="date" />
                    </spring:bind>
                    <div class="form-group">
                        <button class="btn btn-sm btn-primary" type="submit">Submit</button>
                        <button class="btn btn-sm btn-primary" type="reset">Clear</button>
                    </div>
                </form:form>

Контроллер

@RequestMapping(value = { "/main/tasks/{pid}" }, method = RequestMethod.GET)
    public String mTasks(Model model, @PathVariable("pid") int pid) {
        model.addAttribute("main/tasks/add", new Tasks());
        Authentication loggedInUser = SecurityContextHolder.getContext().getAuthentication();
        String username = loggedInUser.getName();
        model.addAttribute("myTasksList", tasksService.findByProject(pid));
        model.addAttribute("project_id", pid);
        model.addAttribute("myProjectList",
                projectService.getMyProjects(userRepository.findByUsername(username).getId()));

        return "main/tasks";
    }

    @RequestMapping(value = "/main/tasks/{pid}", method = RequestMethod.POST)
    public String addTask(@ModelAttribute("nTask") Tasks taskForm, BindingResult bindingResult, Model model,
            @RequestParam("sdate") Date sdate, @RequestParam("ddate") Date ddate, @PathVariable("pid") int pid) {
        taskForm.setProjects(projectsRepository.findById(pid));
        taskForm.setState("TASK_NEW");
        taskForm.setSdate(sdate);
        taskForm.setDdate(ddate);
        tasksRepository.save(taskForm);

        return "redirect:/main/tasks";
    }

Сущность

@Entity
@Table(name = "tasks", catalog = "ajwt")
public class Tasks implements java.io.Serializable {

    private int id;
    private Projects projects;
    private String tname;
    private Date sdate;
    private Date ddate;
    private String description;
    private String state;
    private String priority;

    public Tasks() {
    }

    public Tasks(int id, Projects projects, String tname, String description, String state, String priority) {
        this.id = id;
        this.projects = projects;
        this.tname = tname;
        this.description = description;
        this.state = state;
        this.priority = priority;
    }

    public Tasks(int id, Projects projects, String tname, Date sdate, Date ddate, String description, String state,
            String priority) {
        this.id = id;
        this.projects = projects;
        this.tname = tname;
        this.sdate = sdate;
        this.ddate = ddate;
        this.description = description;
        this.state = state;
        this.priority = priority;
    }

    @Id

    @Column(name = "id", unique = true, nullable = false)
    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pid", nullable = false)
    public Projects getProjects() {
        return this.projects;
    }

    public void setProjects(Projects projects) {
        this.projects = projects;
    }

    @Column(name = "tname", nullable = false, length = 45)
    public String getTname() {
        return this.tname;
    }

    public void setTname(String tname) {
        this.tname = tname;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "sdate", length = 10)
    public Date getSdate() {
        return this.sdate;
    }

    public void setSdate(Date sdate) {
        this.sdate = sdate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "ddate", length = 10)
    public Date getDdate() {
        return this.ddate;
    }

    public void setDdate(Date ddate) {
        this.ddate = ddate;
    }

    @Column(name = "description", nullable = false)
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "state", nullable = false, length = 45)
    public String getState() {
        return this.state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Column(name = "priority", nullable = false, length = 45)
    public String getPriority() {
        return this.priority;
    }

    public void setPriority(String priority) {
        this.priority = priority;
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...