1
'보기'버튼을 클릭하여 구체화 된 모달 창을 사용하여 특정 사용자를 표시하고 싶습니다. 컨트롤러에 ajax 쿼리를 사용하여이 작업을 수행하려고합니다. 또한 오류가 있습니다 : 예기치 않은 오류가 발생했습니다 (유형 = 내부 서버 오류, 상태 = 500). 예외 평가 SpringEL 식 "user.firstName"(사용자 : 190)ayax 쿼리로 thymeleaf 컨트롤러에서 엔티티별로 모달 창을 채우는 방법
테이블 :
<tr th:each="user : ${users}">
<td th:text="${user.firstName}"></td>
<td th:text="${user.lastName}"></td>
<td th:text="${user.username}"></td>
<td>
<a th:onclick="'javascript:viewUser(\'' + ${user.id} +'\');'" class="btn-floating waves-effect waves-light yellow"><i class="material-icons">visibility</i></a>
<a href="#updateUser" class="btn-floating waves-effect waves-light blue btn modal-trigger"><i class="material-icons">edit</i></a>
<a th:href="${'/users/delete/' + user.id}" class="btn-floating waves-effect waves-light red"><i class="material-icons">delete</i></a>
</td>
</tr>
모달 :
<div id="viewUser" class="modal modal-fixed-footer" th:fragment="view">
<div class="modal-content">
<h4>View User</h4>
<div class="row">
<div class="col s12">
<div class="row">
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>First Name: </td>
<td th:text="${user.firstName}"></td>
</tr>
<tr>
<td>Last Name: </td>
<td th:text="${user.lastName}"></td>
</tr>
<tr>
<td>Username</td>
<td th:text="${user.username}"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="modal-action modal-close waves-effect waves-light btn-floating red"><i class="material-icons">close</i></button>
</div>
</div>
JS 함수 :
function viewUser(id) {
$.ajax({
url: "https://stackoverflow.com/users/view/" + id,
success: function(response) {
console.log(response);
$('#viewUserHolder').html(response);
$('#viewUser').modal('open');
}
});
}
방법으로 컨트롤러 :
@RequestMapping(value = "/view/{id}")
public String view(@PathVariable("id") Integer id, ModelMap modelMap) {
User user = userRepository.findOne(id);
modelMap.addAttribute("user", user);
return "users :: view";
}
질문을 업데이트하고 전체 스택 추적을 게시하십시오. 문제가 귀하의 코드 어딘가에 있습니다. 그것은 사용자의 firstName을 얻으려고하지만 잘못된 것이 있습니다. 사용자가 null이거나 getFirstName() 메소드가 없거나 메소드에서 실패 할 수 있습니다. – StanislavL
나는이 오류에 대처할 수 있었다. 콘솔에서 올바른 데이터를 얻지 만, 모달 윈도우가 어떤 이유로 비어 있습니다. 이 문제를 해결할 수 있도록 도와 주시겠습니까? 업데이트 된 코드를 확인하십시오. 이 자습서를 사용하려고합니다. https://qtzar.com/2017/03/24/ajax-and-thymeleaf-for-modal-dialogs/ –