Home
Pelin edited this page Jun 8, 2016
·
6 revisions
更新:5/31/2016 | 个人邮箱:mailto:penglong95.li@gmail.com | 尚未写完
具体使用请见: PBlog-releases
Note: 其中的release并不一定是最新的war包,如果想要获得最新的war包请clone源代码,然后在命令行执行:
mvn package -DskipTests
即可在target中生成PBlow.war文件
源码阅读在下边会以首页举例,其他内容与其类似。
Note: 在这个博客中,移动端与PC端是写了两套页面,在PC端使用了Angular,移动端并没有使用Angular。
- JDK: 1.7+
- MySql: 5.5+
- Tomcat 7+
- 用户访问 "/" 根目录,会首先经过GlobalInterceptor.java文件: 全局拦截器主要获得用户设备、IP、判断移动端与PC端、设置默认为夜间模式
- 然后通过Spring的Handler Mapping解析访问路径,进而访问IndexController.java,返回home.jsp视图:
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(HttpServletRequest request, Model model) {
Boolean mobile = (Boolean) request.getAttribute("mobile");
if(mobile) {
PageRequest pageRequest = new PageRequest(1, 10);
Pagination<ArticleInfoVO> pagination = articleInfoService.page(pageRequest, request);
ArticleInfoVO firstArticleInfoVO = null;
if(pagination.getItems().size() > 0){
firstArticleInfoVO = pagination.getItems().get(0);
}
model.addAttribute("pagination", pagination);
model.addAttribute("firstArticle", firstArticleInfoVO);
return "web/index/index_mobile";
}else {
return "web/home";
}
}
- 在home.jsp视图中加载AngularJS的模块,通过app.js的$routeProvider模块发送request请求获得视图和json数据: app.js:
$routeProvider.when('/index', {
templateUrl: '/index/layout',
controller: IndexController
});
IndexController.java:
$http.get('/topTenArticle.json').
success(function(data) {
$scope.detail = data.detail;
$scope.articleList = data.pagination.items;
$scope.f_article = data.firstArticle;
initializeIndex($scope.f_article.content);
})