2017-09-13 5 views
0

これを読んでいただきありがとうございます。 私は多言語とオートコンプリートを使ってプロジェクトをやっています。 複数言語では、私はSpring MVCを使用していますが、オートコンプリートではJQueryを使用しています。 この2つの機能はうまく動作しますが、同時に使用しようとすると機能します。私は問題がある。<mvc:annotation-driven>

オートコンプリート機能を使用するには、XMLファイルが必要ですが、ArrayListエラーが発生します。しかし、私はその行を入れて、複数言語はもはや実行することはできません、私は言語を変更することはできません、プログラムはデフォルトのものを使用します。私は何の誤りもありません。

あなたは私の問題の原因を教えてください。mvcアノテーション駆動型のものを置き換えるために使用できるものがありますか?ありがとうございました。

  • オートコンプリート機能:

コントローラー:

@RequestMapping(value = "/motsach/find", method = RequestMethod.GET) 
    public @ResponseBody List<Book> findBook(@RequestParam("tensach") String tensach) { 
     return simulateSearchResult(tensach); 
    } 

private List<Book> simulateSearchResult(String tensach) { 
     List<Book> result = new ArrayList<Book>(); 
     data = (List<Book>) bookService.findAll(); 
     for (Book book : data) { 
      if (book.getTensach().contains(tensach)) { 
       result.add(book); 
      } 
     } 
     return result; 
    } 

Javascriptを:

<div> 
    <input type="text" id="book-search" placeholder="Add Book Name" style="width: 1050px;"> <span> 
    <button id="button-id" type="button">Search</button> 
    </span> 
</div> 

<script> 
$(document).ready(function() { 
    $('#book-search').autocomplete({ 
     serviceUrl: '${pageContext.request.contextPath}/motsach/find', 
     paramName: "tensach",   
     delimiter: ",", 
     transformResult: function(response) { 
      return {   
       suggestions: $.map($.parseJSON(response), function(item) { 
        val = item.tensach + " " + '-' + " " + item.tacgia 
        return { value: val}; 
       })     
      };    
     }   
    });    
}); 

</script> 

(ここでの問題) 春-ウェブ-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd"> 

<!-- Scan the JavaConfig --> 

<context:component-scan base-package="com.project.form.config" /> 

//THIS IS THE PROBLEM! 
<mvc:annotation-driven> 
    <mvc:message-converters> 
     <bean class="org.springframework.http.converter.StringHttpMessageConverter" /> 
     <bean 
      class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" /> 
    </mvc:message-converters> 
</mvc:annotation-driven> 

  • 複数言語の機能:

SpringWebConfig

@Bean 
    public ResourceBundleMessageSource messageSource() { 
     ResourceBundleMessageSource rb = new ResourceBundleMessageSource(); 
     rb.setBasenames(new String[] { "messages/messages", "messages/validation","messages/messages_vi","messages/messages_en" }); 
     return rb; 
    } 

    @Bean(name="localeResolver") 
    public LocaleResolver getLocaleResolver() { 
     CookieLocaleResolver resolver = new CookieLocaleResolver(); 
     resolver.setCookieDomain("myAppLocaleCookie"); 
     // 60 minutes 

     resolver.setCookieMaxAge(60 * 60); 
     return resolver; 
    } 

WebMVCConfig

@Override 
public void addInterceptors(InterceptorRegistry registry) { 
    LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor(); 
    localeInterceptor.setParamName("lang"); 
    registry.addInterceptor(localeInterceptor).addPathPatterns("/*"); 
} 

JSPファイル:

<div 
     style="text-align: right; padding: 5px; margin: 5px 0px; background: #aaa;"> 
     <a href="${pageContext.request.contextPath}/motsach?lang=en">English</a> 
     <a href="${pageContext.request.contextPath}/motsach?lang=vi">Vietnamese</a> 
    </div> 

     <thead> 
      <tr> 
       <th><spring:message code="label.ID" /></th> 
       <th><spring:message code="label.name" /></th> 
       <th><spring:message code="label.author" /></th> 
       <th><spring:message code="label.genre" /></th> 
       <th><spring:message code="label.action" /></th> 
      </tr> 
     </thead> 

答えて

0

ohこれを修正する方法を知っていましたが、xmlファイルから削除してアノテーションJavaクラスに追加する必要があります。

StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(); 
stringConverter 
     .setSupportedMediaTypes(Arrays.asList(MediaType.ALL, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN)); 
stringConverter.setDefaultCharset(UTF8); 
converters.add(stringConverter); 
関連する問題