이 글은 이전 글에서 답변이되었지만 모든 해결책을 찾은 후에는이 문제를 해결할 수 없었습니다.라운드 3 BindingResult와 콩 이름 'user'에 대한 일반 대상 객체가 요청 속성으로 사용 가능하지 않습니다.
따라서 스프링 데이터베이스를 사용하여 최대 절전 모드 위에 스프링 & thymeleaf를 사용하고 있습니다. 간단한 폼을 사용하여 데이터베이스에 userlogin 개체를 등록하려고 시도했지만 실행 즉시 시스템이 중단되고 오류가 계속 표시됩니다.
BindingResult도 bean 이름 'user'의 일반 대상 개체도 요청으로 사용할 수 없습니다. 속성
참고 * 동일한 구현을 사용하여 데이터베이스에 클럽 개체를 추가 할 수 있으므로 userlogin 개체와 관련된 추가 변수와 관련이있을 수 있습니다.
첫 번째 글이므로 쉽게 가십시오!
<h3>Register</h3>
<form action="#" th:action="@{/}" th:object="${user}" method="post">
<table>
<tr>
<td>First name:</td>
<td><input type="text" th:field="*{firstName}" /></td>
</tr>
<tr>
<td>Last name:</td>
<td><input type="text" th:field="*{lastName}" /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="number" th:field="*{phone}" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" th:field="*{email}" /></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" th:field="*{address}" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" th:field="*{password}" /></td>
</tr>
<tr>
<td>UserType:</td>
<td><input type="text" th:field="*{userType}" /></td>
</tr>
<tr>
<td><button type="submit">Submit</button></td>
</tr>
</table>
</form>
</td>
: 여기
package com.FYP.Club.controller;
@Controller
public class HomeController {
@Autowired
UserLoginRepository userRepository;
@Autowired
ClubRepository clubRepository;
@RequestMapping(value="/registerclub", method=RequestMethod.GET)
public String index(Club club) {
return "clubindex";
}
@RequestMapping(value = "/club", method = RequestMethod.POST)
public String addNewPost(@Valid Club club, Model model) {
clubRepository.save(club);
model.addAttribute("clubName", club.getClubName());
return "clubresult";
}
@RequestMapping(value="/register", method=RequestMethod.GET)
public String index(UserLogin user) {
return "index";
}
@RequestMapping(value = "/", method = RequestMethod.POST)
public String addNewPost(@Valid UserLogin user, Model model) {
user.setUserStatus(true);
model.addAttribute("email", user.getEmail());
return "result";
}
}
사용자 양식을 갖는 index.html 페이지이다 : 여기
내 컨트롤러 코드 (제 두 가지 방법이 userlogin에 관련된 것들) 인
다음은 userlogin 모델입니다.
@Entity
public class UserLogin {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
private Long phone;
private String email;
private String address;
private String password;
private Boolean userStatus;
private String userType;
public UserLogin()
{
}
public UserLogin(Long id, String firstName, String lastName, Long phone,
String email, String address, String password, Boolean userStatus,
String userType) {
super();
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.phone = phone;
this.email = email;
this.address = address;
this.password = password;
this.userStatus = userStatus;
this.userType = userType;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Long getPhone() {
return phone;
}
public void setPhone(Long phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Boolean getUserStatus() {
return userStatus;
}
public void setUserStatus(Boolean userStatus) {
this.userStatus = userStatus;
}
}
조지 L. Morla 같은 당신의 도움을 주셔서 감사합니다! 그게 오류를 해결 –