2

我是新來的Twitter Typeahead(typeahead.js 0.11.1),我試圖用Thymeleaf + Spring MVC使用遠程選項來配置它。Twitter Typeahead Bloodhound遠程Spring MVC字符解碼失敗

這裏是我的控制器類:

@Controller 
public class AutocompleteController { 

    @Autowired 
    private IRefDataService refDataService; 

    @RequestMapping(value = "/get_user_firstname_suggestions.json", method = RequestMethod.GET) 
    public @ResponseBody List<String> getUserFirstNameSuggestions(@RequestParam("searchTerm") String searchTerm) { 
     return refDataService.getUserFirstNameSuggestions(searchTerm); 
    } 
} 

這裏是我的javascript代碼:

// constructs the suggestion engine 
var firstNames = new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 

    remote:{ 
     url: "/hub/get_user_firstname_suggestions.json?searchTerm=%QUERY"   
    } 
}); 

//Initialize the Bloodhound suggestion engine 
firstNames.initialize(); 

$([[${'#' + heading.fieldName}]]).typeahead({ 
    hint: true, 
    highlight: true, 
    minLength: 2 
}, 
{ 
    name: 'firstNames', 
    display: 'value', 
    source: firstNames.ttAdapter() 
}); 

當我嘗試運行我的申請,我收到以下消息:

INFO: Character decoding failed. Parameter [searchTerm] with value [%QUERY] has been ignored. Note that the name and value quoted here may be corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values. 
Note: further occurrences of Parameter errors will be logged at DEBUG level. 

任何想法如何解決這個問題?

回答

3

好的。在做了大量的搜索和挖掘之後,我設法解決了這個問題。 '通配符'選項丟失。

var firstNames = new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.whitespace, 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
    remote: { 
     url: '/hub/get_user_firstname_suggestions.json?searchTerm=%QUERY', 
     wildcard: '%QUERY' 
    }  
}); 

因此,我添加了如上所示的'通配符'選項,這就做了竅門。