Код класса контроллера:
@RequestMapping("/update-admin/{email}") public String
editUser(@PathVariable(value = "email") String email,@ModelAttribute User
user, HttpServletRequest request) { if
(userService.findByEmail(user.getEmail()) != null) {
request.setAttribute("users", userService.findByEmail(email));
request.setAttribute("name",user.getName());
request.setAttribute("mode","MODE_UPDATE"); return "homepage"; }
else { request.setAttribute("error", "404 Page not Found");
request.setAttribute("mode", "MODE_Page"); return "homepage"; }
}
Код для обслуживания пользователя:
public User findByEmail(String email) {
return userRepository.findByEmail(email);
}
Код репозитория пользователя:
public User findByEmail(String email);
Страница JSP:
<li><a href="/update-admin/${user.getEmail()}">Edit Detail</a></li>
<c:choose>
<c:when test="${mode=='MODE_UPDATE' }">
<div class="container text-center">
<hr>
<h3>Edit Detail</h3>
<hr>
<form class="form-horizontal" method="POST" action="saveadmin" >
<input type="hidden" name="email" value="${user.email }" />
<div class="form-group">
<label class="control-label col-md-3">First Name</label>
<div class="col-md-7">
<input type="text" class="form-control" name="name" value="${user.name }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Last Name</label>
<div class="col-md-7">
<input type="text" class="form-control" name="lastname" value="${user.lastname }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Email-id</label>
<div class="col-md-7">
<input type="email" class="form-control" name="email" value="${user.email }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Institute name</label>
<div class="col-md-7">
<input type="text" class="form-control" name="institute_name" value="${user.institute_name }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Institute Address</label>
<div class="col-md-7">
<input type="text" class="form-control" name="institute_add" value="${user.institute_add }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Qualification</label>
<div class="col-md-7">
<input type="text" class="form-control" name="qualification" value="${user.qualification }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">City</label>
<div class="col-md-7">
<input type="text" class="form-control" name="city" value="${user.city }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Area</label>
<div class="col-md-7">
<input type="text" class="form-control" name="area" value="${user.area }" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Contact Number</label>
<div class="col-md-7">
<input type="number" class="form-control" name="number" value="${user.number }" />
</div>
</div>
<div class="form-group ">
<input type="submit" class="btn btn-primary" value="Update" />
</div>
</form>
</div>
</c:when>
</c:choose>
Я не могу отобразить другое значение поля из базы данных mysql, кроме электронной почты для функции обновления, как показано вкартина.Пожалуйста помоги.