java组织。springframework。网状物绑定MissingServletRequestParameterException:所需的字符串参数“全文”不存在。我正在尝试添加博客
我试图理解它不起作用的原因,并修复它 这个问题在哪里。springframework。网状物绑定MissingServletRequestParameterException:所需的字符串参数“全文”不存在。如何解决这个问题
发帖。博客的java部分:
package com.example.itProger.models;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Post {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title, anons, full_text;
private int views;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAnons() {
return anons;
}
public void setAnons(String anons) {
this.anons = anons;
}
public String getFull_text() {
return full_text;
}
public void setFull_text(String full_text) {
this.full_text = full_text;
}
public int getViews() {
return views;
}
public void setViews(int views) {
this.views = views;
}
public Post(Long id) {
this.id = id;
}
public Post(String title, String anons, String full_text) {
this.title = title;
this.anons = anons;
this.full_text = full_text;
}
}
博客控制器。控制博客的java部分
package com.example.itProger.controllers;
import com.example.itProger.models.Post;
import com.example.itProger.repo.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class BlogController {
@Autowired
private PostRepository postRepository;
@GetMapping("/blog")
public String BlogMain(Model model){
Iterable<Post> posts = postRepository.findAll();
model.addAttribute("posts", posts);
return "blog-main";
}
@GetMapping("/blog/add")
public String BlogAdd(Model model){
return "blog-add";
}
@PostMapping("/blog/add")
public String blogPostAdd(@RequestParam String title, @RequestParam String anons, @RequestParam String full_text, Model model){
Post post = new Post(title,anons,full_text);
postRepository.save(post);
return "redirect:/blog";
}
}
HTML博客添加部分
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div th:insert="blocks/header :: header"></div>
<div class="container mt-5 mb-5">
<h1>Добавление статьи</h1>
<form action="/blog/add" method="post">
<input type="text" name="title" placeholder="Write the name of Blog" class="form-control">
<input type="text" name="anons" placeholder="Write anons of blog" class="form-control">
<textarea name="full-text" placeholder="Write full text of Blog" class="form-control"></textarea>
<button type="submit" class="btn btn-success">Add Blog</button>
</form>
</div>
<div th:insert="blocks/footer :: footer"></div>
</body>
</html>
共 (0) 个答案