I would like to resolve the following errors:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
org.springframework.web.HttpRequestMethodNotSupportedException—Request method 'GET' not supported
When you log in on the login screen and click on the text box on the search screen, the browser hardens and the error above appears.
The environment is Mac, Eclipse 2020, MySQL
Thank you for your cooperation.
@Controller
public class UserController {
@Autowired
UserService sevi;
@Autowired
UserRepository rep;
// Initial Screen
@RequestMapping(value="/", method=RequestMethod.GET)
String login (@ModelAttributeUserForm) {
// List<User>list=sevi.findAll();
// UserForm form 1 = new UserForm();
// model.addAttribute("form", newUserForm());
// model.addAttribute("list", list);
return "login";
}
// Login
@ PostMapping ("yeah")
public String Login(
@RequestParam String id,
@RequestParam String pass,
@Validated @ModelAttribute UserForm form,
BindingResult result,
Model model
) {
if(result.hasErrors()){
return login (form);
}
User = sevi.Login(id, pass);
if(null==sevi.Login(u.getId(), u.getPass())){
return "login";
} else{
return "search";
}
}
// Search
@ PostMapping ("search")
publicModelAndViewsearch(@RequestParamStringname,
ModelAndView mav) {
List<User>list=sevi.findBynameLike(name);
mav.addObject("list", list);
mav.setViewName("/search");
return mav;
}```
@Getter
@Setter
public class UserForm {
@NotBlank
private String id;
@NotBlank
private String pass;
}
@Entity
@Table(name="user")
@Getter
@Setter
public class User {
@Id
@Column(name="id")
@GeneratedValue (strategy=GenerationType.IDENTITY)
private String id;
@Column(name="pass")
private String pass;
@Column(name="name")
private String name;
@Column(name="kana")
private String kana;
}
@Repository
public interface UserRepository extensions JpaRepository <User, String > {
List<User>findBynameLike (String name);
}
@Service
@Transactional
public class UserService {
@Autowired
UserRepository userRepository;
publicList<User>findBynameLike(String name){
return userRepository.findBynameLike(name+"%");
}
publicList<User>findAll(){
return userRepository.findAll();
}
public void insert (User user) {
userRepository.save(user);
}
public void update (User user) {
userRepository.save(user);
}
public void delete (String id) {
userRepository.deleteById(id);
}
public Optional <User>selectById(Stringid){
return userRepository.findById(id);
}
public User Login (String id, String pass) {
User = userRepository.getById(id);
if(null!=u){
if(u.getPass().equals(pass)){
return;
}
} else{
}
return null;
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<metacharset="utf-8"/>
<title>Login</title>
</head>
<body>
<h2>Login Screen</h2>
<form action="#"th:action="@{/yeah}"th:object="${userForm}"method="post">
<table>
<tr>
<td>id:</td>
<td><input type="text" name="id" th:field="*{id}"/>
<spanth:if="${#fields.hasErrors('id')}"th:errors="*{id}">/span></td>
</tr>
<tr>
<td>pass:</td>
<td><input type="text" name="pass"th:field="*{pass}"/>
<spanth:if="${#fields.hasErrors('pass')}"th:errors="*{pass}">/span></td>
</tr>
<tr>
<td><button type="submit">Submit</button></td>
</tr>
</table>
</form>
</body>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title> Search Screen </title>
</head>
<body>
<p>
<h2>Find Employee Information</h2>
<h3> 前方Search forward match</h3>
<form action="/search" method="post">
<p>
ID<input type="text" name="name"><br>
<!--- Name <input type="text" name="name"><br>
Kana <input type="text" name="name"><br>-->
<button type="submit">Search</button>
<button type="submit">New registration</button>
</form>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Kana</th>
</tr>
<trth:each="list:${list}"th:object="${list}">
<tdth:text="*{id}">/td>
<tdth:text="*{name}">/td>
<tdth:text="*{kana}">/td>
</tr>
</table>
</body>
</html>
spring.datasource.url=jdbc:mysql://localhost:3306/
spring.datasource.username=root
spring.datasource.password=
spring.jpa.database=MYSQL
spring.jpa.hibernate.ddl-auto=update
Isn't it because the DOCTYPE on the search screen is far away?
I can't find anything strange about the other processing.
© 2024 OneMinuteCode. All rights reserved.