diff --git a/tamguo-tms/src/main/java/com/tamguo/utils/BrowserUtils.java b/tamguo-tms/src/main/java/com/tamguo/utils/BrowserUtils.java new file mode 100644 index 0000000..0390fde --- /dev/null +++ b/tamguo-tms/src/main/java/com/tamguo/utils/BrowserUtils.java @@ -0,0 +1,34 @@ +package com.tamguo.utils; + +import java.util.regex.Pattern; + +public class BrowserUtils { + + // \b 是单词边界(连着的两个(字母字符 与 非字母字符) 之间的逻辑上的间隔), + // 字符串在编译时会被转码一次,所以是 "\\b" + // \B 是单词内部逻辑间隔(连着的两个字母字符之间的逻辑上的间隔) + private static final String phoneReg = "\\b(ip(hone|od)|android|opera m(ob|in)i" + +"|windows (phone|ce)|blackberry" + +"|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp" + +"|laystation portable)|nokia|fennec|htc[-_]" + +"|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b"; + + private static final String tabletReg = "\\b(ipad|tablet|(Nexus 7)|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b"; + + //移动设备正则匹配:手机端、平板 + private static Pattern phonePat = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE); + private static Pattern tabletPat = Pattern.compile(tabletReg, Pattern.CASE_INSENSITIVE); + + /** + * 检测是否是移动设备访问 + * + * @param userAgent 浏览器标识 + * @return true:移动设备接入,false:pc端接入 + */ + public static boolean isMobile(String userAgent){ + if(null == userAgent){ + userAgent = ""; + } + return phonePat.matcher(userAgent).find() || tabletPat.matcher(userAgent).find(); + } +} \ No newline at end of file diff --git a/tamguo-tms/src/main/java/com/tamguo/web/tiku/CourseController.java b/tamguo-tms/src/main/java/com/tamguo/web/tiku/CourseController.java index 0f5e758..1a6c4c3 100644 --- a/tamguo-tms/src/main/java/com/tamguo/web/tiku/CourseController.java +++ b/tamguo-tms/src/main/java/com/tamguo/web/tiku/CourseController.java @@ -2,6 +2,9 @@ package com.tamguo.web.tiku; import java.util.Arrays; import java.util.List; + +import javax.servlet.http.HttpServletRequest; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; @@ -39,7 +42,7 @@ public class CourseController { @SuppressWarnings("unchecked") @RequestMapping(value = {"course/{uid}.html"}, method = RequestMethod.GET) - public ModelAndView index(@PathVariable String uid , ModelAndView model) { + public ModelAndView index(HttpServletRequest request , @PathVariable String uid , ModelAndView model) { try { CourseEntity course = iCourseService.selectById(uid); List bookList = iBookService.selectList(Condition.create().eq("course_id", uid)); @@ -58,8 +61,6 @@ public class CourseController { model.addObject("subject", subject); model.addObject("bookList", bookList); model.addObject("book" , book); - - model.setViewName("chapter"); return model; } catch (Exception e) { model.setViewName("404"); diff --git a/tamguo-tms/src/main/java/com/tamguo/web/tiku/PaperController.java b/tamguo-tms/src/main/java/com/tamguo/web/tiku/PaperController.java index c7bd29c..948cf25 100644 --- a/tamguo-tms/src/main/java/com/tamguo/web/tiku/PaperController.java +++ b/tamguo-tms/src/main/java/com/tamguo/web/tiku/PaperController.java @@ -1,6 +1,9 @@ package com.tamguo.web.tiku; import java.util.List; + +import javax.servlet.http.HttpServletRequest; + import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -21,6 +24,7 @@ import com.tamguo.modules.tiku.service.ICourseService; import com.tamguo.modules.tiku.service.IPaperService; import com.tamguo.modules.tiku.service.IQuestionService; import com.tamguo.modules.tiku.service.ISubjectService; +import com.tamguo.utils.BrowserUtils; import com.tamguo.utils.PageUtils; /** @@ -45,11 +49,9 @@ public class PaperController { @SuppressWarnings("unchecked") @RequestMapping(value = {"paperlist/{subjectId}-{courseId}-{paperType}-{year}-{area}-{pageNum}.html"}, method = RequestMethod.GET) - public ModelAndView indexAction(@PathVariable String subjectId , @PathVariable String courseId , @PathVariable String paperType, + public ModelAndView indexAction(HttpServletRequest request , @PathVariable String subjectId , @PathVariable String courseId , @PathVariable String paperType, @PathVariable String year , @PathVariable String area , @PathVariable Integer pageNum, ModelAndView model) { try { - model.setViewName("paperlist"); - CourseEntity course = iCourseService.selectById(courseId); List courseList = iCourseService.selectList(Condition.create().eq("subject_id", subjectId)); SubjectEntity subject = iSubjectService.selectById(subjectId); @@ -84,6 +86,13 @@ public class PaperController { model.addObject("paperType", paperType); model.addObject("year", year); model.addObject("area", area); + + + if(BrowserUtils.isMobile(request.getHeader("user-agent"))) { + model.setViewName("mobile/paperlist"); + }else { + model.setViewName("paperlist"); + } return model; } catch (Exception e) { model.setViewName("404"); @@ -94,7 +103,7 @@ public class PaperController { @SuppressWarnings("unchecked") @RequestMapping(value = {"/paper/{paperId}.html"}, method = RequestMethod.GET) - public ModelAndView indexAction(@PathVariable String paperId , ModelAndView model){ + public ModelAndView indexAction(HttpServletRequest request , @PathVariable String paperId , ModelAndView model){ try { model.setViewName("paper"); PaperEntity paper = iPaperService.selectById(paperId); @@ -108,6 +117,13 @@ public class PaperController { model.addObject("moniPaperList", iPaperService.selectList(Condition.create().eq("subject_id", paper.getSubjectId()).eq("type",SystemConstant.MONI_PAPER_ID))); model.addObject("yatiPaperList", iPaperService.selectList(Condition.create().eq("subject_id", paper.getSubjectId()).eq("type",SystemConstant.YATI_PAPER_ID))); model.addObject("hotPaperList", iPaperService.selectList(Condition.create().eq("subject_id", paper.getSubjectId()).eq("course_id", paper.getCourseId()))); + + + if(BrowserUtils.isMobile(request.getHeader("user-agent"))) { + model.setViewName("mobile/paper"); + }else { + model.setViewName("paper"); + } return model; } catch (Exception e) { model.setViewName("404"); diff --git a/tamguo-tms/src/main/java/com/tamguo/web/tiku/SubjectController.java b/tamguo-tms/src/main/java/com/tamguo/web/tiku/SubjectController.java index 6607042..72defd8 100644 --- a/tamguo-tms/src/main/java/com/tamguo/web/tiku/SubjectController.java +++ b/tamguo-tms/src/main/java/com/tamguo/web/tiku/SubjectController.java @@ -2,6 +2,9 @@ package com.tamguo.web.tiku; import java.util.Arrays; import java.util.List; + +import javax.servlet.http.HttpServletRequest; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -24,6 +27,7 @@ import com.tamguo.modules.tiku.service.IBookService; import com.tamguo.modules.tiku.service.IChapterService; import com.tamguo.modules.tiku.service.ICourseService; import com.tamguo.modules.tiku.service.ISubjectService; +import com.tamguo.utils.BrowserUtils; /** * Controller - 考试(高考,建造师,医药师) @@ -46,11 +50,10 @@ public class SubjectController { private ICourseService iCourseService; @Autowired private IBookService iBookService; - @SuppressWarnings("unchecked") @RequestMapping(value = {"subject/{subjectId}.html"}, method = RequestMethod.GET) - public ModelAndView indexAction(@PathVariable String subjectId , ModelAndView model) { + public ModelAndView indexAction(@PathVariable String subjectId , HttpServletRequest request , ModelAndView model) { try { SubjectEntity subject = iSubjectService.selectById(subjectId); List courseList = iCourseService.selectList(Condition.create().eq("subject_id", subjectId).orderAsc(Arrays.asList("sort"))); @@ -63,12 +66,17 @@ public class SubjectController { BookEntity book = bookList.get(0); chapterList = iChapterService.selectList(Condition.create().eq("book_id", book.getId())); } - model.setViewName("subject"); model.addObject("subject", subject); model.addObject("course" , course); model.addObject("courseList", courseList); model.addObject("chapterList" , chapterList); model.addObject("areaList", iSysAreaService.selectList(Condition.create().eq("tree_level", "0"))); + if(BrowserUtils.isMobile(request.getHeader("user-agent"))) { + model.setViewName("mobile/subject"); + }else { + model.setViewName("subject"); + } + return model; } catch (Exception e) { logger.error(e.getMessage() , e); diff --git a/tamguo-tms/src/main/resources/templates/include/footer.html b/tamguo-tms/src/main/resources/templates/include/footer.html index ff98a79..150d76d 100644 --- a/tamguo-tms/src/main/resources/templates/include/footer.html +++ b/tamguo-tms/src/main/resources/templates/include/footer.html @@ -5,7 +5,7 @@
探果题库

- 探果题库旨在为用户提供高效的备考服务,让知识能无障碍传播,老用户价值,助您不断前行! + 探果题库旨在为用户提供高效的备考服务,让知识能无障碍传播,为用户创造价值,助您不断前行!

diff --git a/tamguo-tms/src/main/resources/templates/mobile/paper.html b/tamguo-tms/src/main/resources/templates/mobile/paper.html new file mode 100644 index 0000000..a5addad --- /dev/null +++ b/tamguo-tms/src/main/resources/templates/mobile/paper.html @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + +
+
+
+ 关于 + +

+
+ +
+
+
试卷
+
+
+
题干
+
这是一个用纯文本的简单卡片。但卡片可以包含自己的页头,页脚,列表视图,图像,和里面的任何元素。
+
+
+
答案
+
这是一个用纯文本的简单卡片。但卡片可以包含自己的页头,页脚,列表视图,图像,和里面的任何元素。
+
+
+
解析
+
这是一个用纯文本的简单卡片。但卡片可以包含自己的页头,页脚,列表视图,图像,和里面的任何元素。
+
+ +
+
+
+
+ + +
+ +
+
+

这是一个侧栏

+

+ +

+ 关闭 +

+
+
+
+
+

探果题库

+

+ +

+ 关闭 +

+
+
+
+ + \ No newline at end of file diff --git a/tamguo-tms/src/main/resources/templates/mobile/paperlist.html b/tamguo-tms/src/main/resources/templates/mobile/paperlist.html new file mode 100644 index 0000000..cf49e2f --- /dev/null +++ b/tamguo-tms/src/main/resources/templates/mobile/paperlist.html @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+
+

这是一个侧栏

+

+ +

+ 关闭 +

+
+
+
+
+

探果题库

+

+ +

+ 关闭 +

+
+
+
+ + \ No newline at end of file diff --git a/tamguo-tms/src/main/resources/templates/mobile/subject.html b/tamguo-tms/src/main/resources/templates/mobile/subject.html new file mode 100644 index 0000000..5e93cb4 --- /dev/null +++ b/tamguo-tms/src/main/resources/templates/mobile/subject.html @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + +
+
+
+ 关于 + +

+
+ + +
+
+
科目
+ +
历年试卷
+ + +
模拟试卷
+ + +
热门试卷
+ +
+
+
+ + +
+ +
+
+

这是一个侧栏

+

+ +

+ 关闭 +

+
+
+
+
+

探果题库

+

+ +

+ 关闭 +

+
+
+
+ + \ No newline at end of file