2016-05-24 12 views
0

私のアプリケーションにモバイルデバイスを検出させてそのページをレンダリングしようとしていますが、応答がありませんが、index.htmlページがレンダリングされています。私のモバイルコントローラは完全に無視されています。スプリングブートでモバイルデバイスを検出する

@Controller 
public class DeviceDetection { 

    @RequestMapping("/") 
    public @ResponseBody String detectDevice(Device device) { 

     if (device.isNormal()) { 
      System.out.println("Inside isNormal()"); 
      return "index"; 

     } else if (device.isMobile()) { 
      System.out.println("Inside isMobile()"); 
      return "mobilePage"; 
     } else if (device.isTablet()) { 
      return "mobilePage"; 
     } 
     return "index"; 
    } 

} 

のpom.xml

 <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-mobile</artifactId> 
     </dependency> 

enter image description here

答えて

0

spring-boot-mobileあなたDeviceを検出するために設定する追加のプロパティが必要です。

プロパティがspring.mobile.devicedelegatingviewresolver.enabled: true

以下では、デフォルトのディレクトリ構造です:あなたが正しくあなたのテンプレートをマッピングする必要があり、あなたの場合は

 resources 
     └── templates 
      └── greeting.html 
      └── mobile 
       └── greeting.html 
      └── tablet 
       └── greeting.html 

。動作をカスタマイズする

春ブーツspring-mobileプロパティ:

spring.mobile.devicedelegatingviewresolver.enable-fallback=false - フォールバック解像度のサポートを有効にします。

spring.mobile.devicedelegatingviewresolver.enabled=false - モバイルデバイスの名前を表示する前に付加されますプレフィックス - デバイスビューリゾルバ

spring.mobile.devicedelegatingviewresolver.mobile-prefix=mobile/を有効にします。

spring.mobile.devicedelegatingviewresolver.mobile-suffix= - 携帯端末の名前を表示するための接尾辞。

spring.mobile.devicedelegatingviewresolver.normal-prefix= - 通常のデバイスの表示名の前に付加されるプレフィックス。

spring.mobile.devicedelegatingviewresolver.normal-suffix= - 通常のデバイスの名前を表示するために付ける接尾辞。

spring.mobile.devicedelegatingviewresolver.tablet-prefix=tablet/ - タブレットデバイスの表示名の前に付加されるプレフィックス。

spring.mobile.devicedelegatingviewresolver.tablet-suffix= - タブレットデバイスの名前を表示するために追加される接尾辞。

spring.mobile.sitepreference.enabled=true - SitePreferenceHandlerを有効にします。

また、@RequestMapping("/")を別のものに変更します。

+0

これは既に追加されています。申し訳ありませんが私の質問に追加することを忘れました – Drew1208

+0

@ Drew1208私の答えを更新しました。 –

+0

私は '@ RequestMapping'に/ indexを追加して動作させましたが、' mobilePage'という文字列をブラウザにレンダリングするだけです。私は 'resourceViewResolver'が必要だと思っていますが、わかりません。 – Drew1208

関連する問題