Skip to content

Commit

Permalink
添加显示新闻列表和新闻详情
Browse files Browse the repository at this point in the history
  • Loading branch information
Fireply committed May 31, 2016
1 parent 3cf92ba commit 28a57cb
Show file tree
Hide file tree
Showing 16 changed files with 423 additions and 37 deletions.
19 changes: 19 additions & 0 deletions WebRoot/css/enter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
body {
padding-top: 70px;
}

.enter-btn-detail {
width: 60%;
margin-top: 20%;
margin-left: 20%
}

.enter-center-vertical {
position: relative;
transform: translateY(40%);
}

.enter-scrollable {
max-height: 200px;
overflow-y: scroll;
}
10 changes: 5 additions & 5 deletions WebRoot/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<title>VR AR MR 企业网站</title>
<link rel="icon" href="favicon.ico">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/carousel.css" rel="stylesheet">
Expand Down Expand Up @@ -89,7 +89,7 @@
</div>
<div class="col-md-5">
<img class="featurette-image img-responsive center-block" src="images/CESA.jpg" alt="Generic placeholder image">
<p><a class="btn btn-success btn-lg btn-detail" href="#" role="button">查看详情</a></p>
<p><a class="btn btn-success btn-lg enter-btn-detail" href="#" role="button">查看详情</a></p>
</div>
</div>

Expand All @@ -102,7 +102,7 @@
</div>
<div class="col-md-5 col-md-pull-7">
<img class="featurette-image img-responsive center-block" src="images/car.jpg" alt="Generic placeholder image">
<p><a class="btn btn-success btn-lg btn-detail" href="#" role="button">查看详情</a></p>
<p><a class="btn btn-success btn-lg enter-btn-detail" href="#" role="button">查看详情</a></p>
</div>
</div>

Expand All @@ -115,7 +115,7 @@
</div>
<div class="col-md-5">
<img class="featurette-image img-responsive center-block" src="images/mr_global.jpg" alt="Generic placeholder image">
<p><a class="btn btn-success btn-lg btn-detail" href="#" role="button">查看详情</a></p>
<p><a class="btn btn-success btn-lg enter-btn-detail" href="#" role="button">查看详情</a></p>
</div>
</div>

Expand Down Expand Up @@ -151,7 +151,7 @@
</div><!-- /.container -->

<style type="text/css">
.btn-detail {
.enter-btn-detail {
width: 60%;
margin-top: 20%;
margin-left: 20%
Expand Down
25 changes: 5 additions & 20 deletions WebRoot/navbar.jsp
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>

<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
Expand Down Expand Up @@ -42,7 +28,7 @@
<li><a href="#">Magic leap</a></li>
</ul>
</li>
<li><a href="#">动态</a></li>
<li><a href="news">动态</a></li>
<li><a href="#">加入我们</a></li>
<li><a href="intro.jsp">关于我们</a></li>
</ul>
Expand All @@ -64,9 +50,8 @@
.navbar-brand-padding {
padding-top: 10px;
}
body {
padding-top: 70px;
}
</style>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>

</body>
</html>
43 changes: 43 additions & 0 deletions WebRoot/pages/join-us.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<base href="<%=basePath %>" />
<link rel="icon" href="favicon.ico">
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>

<body>

<jsp:include page="/navbar.jsp" />

<div class="container">
<div class="jumbotron">
<h1>加入我们吧</h1>
<p>成为我们的代理商,在 VR 元年</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">联系我们</a></p>
</div>
</div>


<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>

<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
43 changes: 43 additions & 0 deletions WebRoot/pages/news-detail.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新闻动态</title>
<base href="<%=basePath %>" />
<link rel="icon" href="favicon.ico">
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>

<body>

<jsp:include page="/navbar.jsp" />

<div class="container">

新闻 id: ${newsId }<br><br>
新闻标题 EL: ${news.title }<br><br>
新闻内容 EL: ${news.content }<br><br>

</div><!-- /.container -->

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>

<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
63 changes: 63 additions & 0 deletions WebRoot/pages/news.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<base href="<%=basePath %>" />
<link rel="icon" href="favicon.ico">
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
</head>

<body>

<jsp:include page="/navbar.jsp" />

<div class="container">

<div class="page-header">
<h1>新闻动态</h1>
</div>

<s:iterator value="newsList" var="news">

<div class="panel panel-default">
<div class="panel-heading">
<h3><a href="news!detail?newsId=${news.id }">${news.title }</a></h3>
</div>
<div class="panel-body enter-scrollable">
<div><s:property value="#news.content" /></div>
</div>
</div>

</s:iterator>

</div><!-- /.container -->

<style>
.enter-scrollable {
max-height: 200px;
overflow-y: scroll;
}
</style>

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>

<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions WebRoot/signin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<div class="container">

<form class="form-signin center-vertical" action="login" method="post">
<form class="form-signin enter-center-vertical" action="login" method="post">
<h2 class="form-signin-heading">登陆</h2>
<label for="userId" class="sr-only">用户 ID</label>
<input type="text" id="userId" name="userId" class="form-control" placeholder="用户 ID" required autofocus />
Expand All @@ -40,9 +40,9 @@
</div> <!-- /container -->

<style type="text/css">
.vertical {
.enter-center-vertical {
position: relative;
transform: translateX(40%);
transform: translateY(40%);
}
</style>

Expand Down
92 changes: 92 additions & 0 deletions src/main/java/org/fireply/enter/action/NewsAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.fireply.enter.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.fireply.enter.model.News;
import org.fireply.enter.service.NewsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

@Controller
public class NewsAction extends ActionSupport implements RequestAware, SessionAware {

@Autowired
@Qualifier("newsServiceImpl")
private NewsService newsService;

private Map<String, Object> request;
private Map<String, Object> session;

private List<News> newsList; // 请求新闻列表时将数据库查询结果存放在 newsList
private String newsId; // 请求新闻详情时传递过来的 id
private News news; // 请求新闻详情时将数据库查询结果存放在 news

private static final Logger logger = LoggerFactory.getLogger(NewsAction.class);

@Override
public String execute() throws Exception {
newsList = newsService.getAllNews();

if (newsList == null || newsList.size() <= 0) {
logger.warn("从数据库查询不到任意一条新闻");
return ERROR;
} else {
logger.debug("从数据库查询新闻列表成功");
return "news";
}
}

public String detail() throws Exception {
news = newsService.getNews(newsId);
if (news == null) {
logger.warn("从数据库查询 id={} 的新闻失败", newsId);
return ERROR;
} else {
logger.debug("从数据库查询到了 id={} 的新闻", newsId);
return "news-detail";
}
}

@Override
public void setRequest(Map<String, Object> request) {
this.request = request;
}

@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}

public List<News> getNewsList() {
return newsList;
}

public void setNewsList(List<News> newsList) {
this.newsList = newsList;
}

public String getNewsId() {
return newsId;
}

public void setNewsId(String newsId) {
this.newsId = newsId;
}

public News getNews() {
return news;
}

public void setNews(News news) {
this.news = news;
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/fireply/enter/dao/impl/DaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List get(Class<?> clazz, Map<String, Object> fieldsMap) {

@Override
public List<?> getAll(Class<?> clazz) {
String hql = "from" + clazz.getSimpleName();
String hql = "from " + clazz.getSimpleName();
return executeQuery(hql);
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/fireply/enter/model/News.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public News(String id, User user, String title, String content, Date createTime,
this.commits = commits;
}

@Override
public String toString() {
return "News [id=" + id + ", user=" + user + ", title=" + title + ", content=" + content + ", createTime="
+ createTime + "]";
}

public String getId() {
return this.id;
}
Expand Down
Loading

0 comments on commit 28a57cb

Please sign in to comment.