0
在我的網站中,我有一個從數據庫中提取的產品列表,結果被彙總到一個帶有選擇/選項的簡單列表中。現在我想用多詞搜索的形式改變這個詞,其中包含單詞自動完成。使用spring thymeleaf MVC進行表單搜索?
這是我的選擇/選項列表:
$("#Product").change(function(){
\t var webProductId = $(this).find(':selected').attr('data-webProductId');
\t var requestData = { webProductId: webProductId };
\t yada.ajax([[@{/product/list}]], requestData, function(responseText, responseHtml) {
\t $('div.sinVotoInner').replaceWith(responseHtml);
\t yada.initHandlersOn(responseHtml);
});
<select id="wsProduct">
<option value="Products" id="Product" selected>Product</option>
<option th:each="webProduct : ${webProducts}"
\t th:attr="data-webProductId=${webProduct.id}"
\t th:text="|${webProduct.name} ${webProduct.description}|">Product 1 Description 1</option>
\t \t \t </select>
這是我家的控制器:
@RequestMapping("/")
\t public String home(Model model) {
\t \t
\t \t List<WebProduct> webProducts = webProductRepository.findByEnabledTrueOrderByNameAsc();
\t \t model.addAttribute("webProducts", webProducts);
\t \t return "/home";
\t }
這是我的庫:
List<WebLocation> findByEnabledTrueOrderByNameAsc();
\t /**
\t * @param productId
\t * @return
\t */
\t @Query(value="select * from WebProduct wp where wp.product_id = :productId", nativeQuery = true)
\t WebProduct findByProductId(@Param("productId") long productId);
如何改變這種代碼,包括工作搜索表單?搜索必須適用於您輸入的任何單詞,並且搜索建議(例如Google)出現在搜索表單中。
搜索建議會使用到支持JavaScript和Ajax調用來完成。在這種情況下,我沒有看到thymeleaf在哪裏使用?您只需放入一個純文本框並監聽鍵盤事件,即可將異步REST調用到後端以獲取建議 –