html中调用controller里的函数 前端报302错误
Controller层
@Controller
public class KokyakuSearchController{
@Autowired
private KokyakuSearchService kokyakuSearchService;
@GetMapping("/kokyaku")
public String view(KokyakuForm form, RedirectAttributes attributes, Model model) {
Object size = model.getAttribute("size");
Object kokyaku = model.getAttribute("kokyaku");
System.out.println(kokyaku);
model.addAttribute("size",size);
model.addAttribute("kokyaku",kokyaku);
return "/kokyakuSearch";
}
/**
* 顧客検索
* @param form 画面から取得したフォーム
* @param attributes
* @param model
* @return
*/
@GetMapping("/kokyakuSearch")
public String kokyakuList(KokyakuForm form, RedirectAttributes attributes, Model model) {
List<MKokyakuTbl> list = kokyakuSearchService.searchKokyakuForm(form.getKokyakuNm(), form.getKokyakuCdFrom(),form.getKokyakuCdTo(),form.getSort(),form.getSortAd());
int count = list.size();
attributes.addFlashAttribute("size",count);
System.out.println(list.toString());
attributes.addFlashAttribute("kokyaku",list);
return "redirect:/kokyaku";
}
}
前端页面
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>顧客検索</title>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>
<link rel="stylesheet" href="./css/common.css" type="text/css">
<script>
var count = '$(size)'
function show(){
alert(count);
if(count != '0'){
$('#result').show();
}else{
$('#result').hide();
}
}
</script>
</head>
<body>
<form method="get" th:action="@{/kokyakuSearch}" th:object="${kokyakuForm}">
<span class="fontTitle">顧客検索</span>
<hr class="hrPopup1">
<div class="fontError">該当するデータがありません。</div>
<hr class="hrPopup1">
<fieldset class="windowWidth1x1">
<legend>検索条件</legend>
<table>
<tr>
<td><div class="item1 itemWidth0">顧客名</div></td>
<td colspan="2"><input type="text" class="input1 inputWidth2" th:value="*{kokyakuNm}" th:field="*{kokyakuNm}"></td>
</tr>
<tr>
<td><div class="item1 itemWidth0">顧客コード</div></td>
<td>
<input type="text" class="input1 inputWidth000" name="kokyakuCdFrom" th:value="*{kokyakuCdFrom}" th:field="*{kokyakuCdFrom}">
~
<input type="text" class="input1 inputWidth000" name="kokyakuCdTo" th:value="*{kokyakuCdTo}" th:field="*{kokyakuCdTo}">
</td>
<td><button class="button btnWidth2">検索(<span class="accessLetter">S</span>)</button></td>
</tr>
</table>
</fieldset>
<br>
<fieldset id="result" class="windowWidth1x1" style="height:522px; ">
<legend>検索結果</legend>
<div class="popupShowCnt">検索件数 <a id="size" th:text=${size}></a>件</div>
<table class="listViewTable">
<tr>
<th class="item2" style="width:90px;"><u>顧客コード</u></th>
<th class="item2" style="width:517px;"><u>顧客名</u></th>
</tr>
</table>
<div class="scrollOnY" style="height:462px;">
<table class="listViewTable windowWidth1">
<tr th:each="list : ${kokyaku}">
<td style="width:90px;" nowrap th:text="${list.kokyakuCd}"></td>
<td style="width:490px;" nowrap th:text="${list.kokyakuNm}"></td>
</tr>
</table>
</div>
</fieldset>
<br>
<div class="windowWidth1x1 alignRight">
<button class="button btnWidth2" onclick="window.close();">閉じる (<span class=accessLetter>E</span>)</button>
</div>
</form>
</body>
</html>