[英]org.springframework.web.HttpRequestMethodNotSupportedException Request method 'POST' not supported
[英]Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
我有兩個列表,一個是用戶,另一個是團隊。 我可以從列表中選擇任何用戶以及任何團隊。 但無法將用戶添加到團隊。 當您按下按鈕時,錯誤已解決 [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
用戶
@Entity
@Table(name="users")
public class Users {
@Id
@Column(name="email",/*unique = true,*/ nullable = false,length = 200)
String email;
@Column(name="name",nullable = false,length = 200)
String name;
@Column(name="password",nullable = false,length = 128)
@JsonIgnore
String password;
@Column(name = "avatar", nullable = true)
String avatar;
@ManyToOne
@JoinColumn(name="team_id", nullable=true)
Team team;
團隊
Entity
@Table(name="team")
public class Team {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@Column
String name;
@Column
String url;
@Lob
@Column(name = "avatar",nullable = true,columnDefinition="BLOB")
String avatar;
@OneToMany(mappedBy="team",cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
Set<Users> users = new HashSet<>();
管理控制器
@RequestMapping(value = "/admin/team/user}", method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public String addUserToTeam(@PathVariable String userName, @PathVariable String teamName,Model model, @ModelAttribute("userTeamForm") @Validated UserTeamForm userTeamForm,
BindingResult result, final RedirectAttributes redirectAttributes) {
Team team = teamRepository.findTeamByName(teamName).orElseThrow(() -> new NoSuchTeamException("Team not found"));
Users user = userRpRepository.findUsersByName(userName)
.orElseThrow(() -> new NoSuchUserException("User not found"));
user.setTeam(team);
userRpRepository.save(user);
return "userTeam";
}
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String adminPage(Model model) {
model.addAttribute("userTeamForm",new UserTeamForm());
....
return "admin";
}
管理.html
<form th:action="@{/admin/team/user/}"th:object="${userTeamForm}" method="POST">
<div class="form-group blu-margin">
<select class="form-control" id="addUser">
<option value="0">select user</option>
<option th:each="user : ${users}" th:value="${user.name}" th:text="${user.name}"></option>
</select>
<select class="form-control" id="addTeam">
<option value="0">select team</option>
<option th:each="team : ${teams}" th:value="${team.name}" th:text="${team.name}"></option>
</select>
</div>
<br/>
<input type="submit" value="Add User to Team" />
</form>
用戶組表單
我需要使用 UserTeamForm 還是可以直接使用 Entity?
public class UserTeamForm {
private String userName;
private String teamName;
get/set
抱歉,我沒有注意到方法描述中的}。 我找了兩天的問題))
@RequestMapping(value = "/admin/team/user}", method = RequestMethod.POST,
用戶之后不應該有 }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.