[springboot] 모바일,웹,테블릿 페이지 분리하기

- Goal

springboot을 이용하여 agent에 따른 웹,모바일,테블릿 페이지 분리 표시하기


- Time

10min


- Enviroment

java 1.8, STS3.7


- Tutorial

1. build.gradle에 dependency 추가

compile("org.springframework.boot:spring-boot-starter-mobile")


2. application.properties에 아래 내용 추가

spring.mobile.devicedelegatingviewresolver.enabled:true


3. view폴더에 mobile,table 폴더 생성


4. controller 생성

1
2
3
4
@RequestMapping("/jsp")
public String main(Model model){
    return "hello";
}
cs


5. 실제 페이지에서 제대로 표시되는지 확인.


실제 테스트해보면 간단하게 처리가 된다. springboot에는 없는게 없는듯.


추가..

tablet에서 들어온것도 mobile페이지로 보내고 싶다면 application.properties에 아래와 같이 추가한다. 

spring.mobile.devicedelegatingviewresolver.tablet-prefix=mobile/


그외에 기타 option..

spring.mobile.devicedelegatingviewresolver.enable-fallback=false - Enable support for fallback resolution.

spring.mobile.devicedelegatingviewresolver.enabled=false - Enable device view resolver

spring.mobile.devicedelegatingviewresolver.mobile-prefix=mobile/- Prefix that gets prepended to view names for mobile devices.

spring.mobile.devicedelegatingviewresolver.mobile-suffix=- Suffix that gets appended to view names for mobile devices.

spring.mobile.devicedelegatingviewresolver.normal-prefix= - Prefix that gets prepended to view names for normal devices.

spring.mobile.devicedelegatingviewresolver.normal-suffix=- Suffix that gets appended to view names for normal devices.

spring.mobile.devicedelegatingviewresolver.tablet-prefix=tablet/- Prefix that gets prepended to view names for tablet devices.

spring.mobile.devicedelegatingviewresolver.tablet-suffix=- Suffix that gets appended to view names for tablet devices.

spring.mobile.sitepreference.enabled=true- Enable SitePreferenceHandler.


참조사이트 : 

https://spring.io/guides/gs/serving-mobile-web-content/

http://stackoverflow.com/questions/37425606/detecting-a-mobile-device-with-spring-boot