Skip to content

Commit

Permalink
完成Demo项目-TodoList
Browse files Browse the repository at this point in the history
  • Loading branch information
sofn committed Oct 23, 2015
1 parent 1b76a14 commit cbcc7fb
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 87 deletions.
11 changes: 11 additions & 0 deletions deploy/src/main/webapp/WEB-INF/decorator/none.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title><sitemesh:write property='title'/></title>
<sitemesh:write property='head'/>
</head>
<body>
<sitemesh:write property='body'/>
</body>
</html>
94 changes: 59 additions & 35 deletions deploy/src/main/webapp/WEB-INF/jsp/task/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,84 @@

<html>
<head>
<script language="javascript" src="${ctx}/static/javascripts/pageutil.js"></script>
<title>任务管理</title>
</head>
<body>
<div id="msg"></div>
<div class="row">
<div class="span4 offset7">
<form class="form-search" action="#">
<label>名称:</label>
<input type="text" name="search_LIKE_title" class="input-medium" value="${param.search_LIKE_title}">
<button type="submit" class="btn" id="search_btn">Search</button>
</form>
</div>
</div>
<br/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>任务</th>
<th>管理</th>
</tr>
</thead>
<tbody>
<c:forEach items="${tasks.content}" var="task">
<tr>
<td><a href="${ctx}/task/update/${task.id}">${task.title}</a></td>
<td><a href="${ctx}/task/delete/${task.id}">删除</a></td>
</tr>
</c:forEach>
</tbody>
<tbody id="tasks"></tbody>
</table>

<div id="pageing"></div>

<div><a class="btn btn-primary" href="${ctx}/web/task/save">创建任务</a></div>
<script lang="javascript">
var page = page || 1;
//TODO
$.ajax({
url: '/task/list',
type: 'post',
data: {
page: page
},
success: function (result) {
var pageDom = $("#pageing");
if (pageDom.length > 0) {
pageDom.html(createPagination(result.counts, result.current, 5, result.pageSize, "pageclick", false, "page"));
var page = 1;
var pagesize = 10;
var tasksDom = $("#tasks");
function createTaskDom(id, title) {
var new_task = $("<tr id='task_" + id + "'>");
var td1 = $("<td>");
td1.appendTo(new_task);
$("<a href=\"${ctx}/web/task/save?id=" + id + "\">" + title + "</a>").appendTo(td1);
var td2 = $("<td>");
td2.appendTo(new_task);
$("<a onclick=\"del_task(" + id + ")\">删除</a>").appendTo(td2);
return new_task;
}
pageclick(1);
function pageclick(to_page) {
tasksDom.html(null);
$.ajax({
url: '/task/list',
type: 'GET',
data: {
page: to_page,
page_size: pagesize
},
success: function (json) {
page = to_page;
var result = json.result;
for (var i = 0; i < result.content.length; i++) {
var task = result.content[i];
createTaskDom(task.id, task.title).appendTo(tasksDom);
}
var pageDom = $("#pageing");
if (pageDom.length > 0) {
pageDom.html(createPagination(result.totalElements, to_page, 5, pagesize, "pageclick"));
}
},
error: function () {
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>服务器错误')
}
},
error: function (XMLHttpRequest, textStatus, errorMsg) {
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>服务器错误')
}
});
});
}
function del_task(id) {
$.ajax({
url: '/task/delete',
type: 'POST',
data: {id: id, _method: "DELETE"},
success: function (json) {
if (json.result) {
$("#task_" + id).remove();
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>删除成功')
}
},
error: function () {
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>服务器错误')
}
});
}
</script>
</body>
</html>
13 changes: 9 additions & 4 deletions deploy/src/main/webapp/WEB-INF/jsp/task/save.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<body>
<form id="inputForm" class="form-horizontal">
<input type="hidden" id="task_id" name="title" value="${task.id}"/>

<div id="msg"></div>
<fieldset>
<legend>
Expand All @@ -20,14 +22,16 @@
<label for="task_title" class="control-label">任务名称:</label>

<div class="controls">
<input type="text" id="task_title" name="title" class="input-large required" minlength="3"/>
<input type="text" id="task_title" name="title" value="${task.title}" class="input-large required"
minlength="3"/>
</div>
</div>
<div class="control-group">
<label for="description" class="control-label">任务描述:</label>

<div class="controls">
<textarea id="description" name="description" class="input-large required"></textarea>
<textarea id="description" name="description"
class="input-large required">${task.description}</textarea>
</div>
</div>
<div class="form-actions">
Expand All @@ -43,6 +47,7 @@
//为inputForm注册validate函数
$("#inputForm").validate({
submitHandler: function () {
var id = $("#task_id").val() || 0;
var title = $("#task_title").val();
var desc = $("#description").val();
$.ajax({
Expand All @@ -51,14 +56,14 @@
//提交的网址
url: "${ctx}/task/save",
//提交的数据
data: {"title": title, "desc": desc},
data: {id: id, title: title, desc: desc},
cache: false,
crossDomain: true,
dataType: 'json',
xhrFields: {
withCredentials: true
},
success: function (data) {
success: function () {
$("#msg").attr("class", "text-warning alert alert-error").html("创建成功");
setInterval(function () {
location.href = "${ctx}/web/task";
Expand Down
1 change: 1 addition & 0 deletions deploy/src/main/webapp/WEB-INF/sitemesh3.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 -->
<mapping path="/index.html" decorator="/WEB-INF/decorator/none.jsp"/>
<mapping path="/*" decorator="/WEB-INF/decorator/default.jsp"/>

<!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 -->
Expand Down
22 changes: 15 additions & 7 deletions deploy/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,43 @@
<title>app-engine</title>
</head>
<body>
<p>Access below management endpoint:
<p>Demo示例-任务管理
<ul>
<li><a href="http://localhost:8080/web/login">http://localhost:8080/web/login</a></li>
</ul>
</p>

<p>Spring Boot自带监控:
<ul>
<li><a href="http://localhost:7002/health">http://localhost:7002/health</a></li>
<li><a href="http://localhost:7002/info">http://localhost:7002/info</a></li>
<li><a href="http://localhost:7002/dump">http://localhost:7002/dump</a></li>
<li><a href="http://localhost:7002/metrics">http://localhost:7002/metrics</a></li>
<li><a href="http://localhost:7002/env">http://localhost:7002/env</a></li>
<li>shutdown(disable by default, POST method)</li></ul>
<li>shutdown(disable by default, POST method)</li>
</ul>
</p>

<p>JMX expose as Restful by jolokia. e.g. Tomcat's MBean:
<p>Tomcat's MBean 监控:
<ul>
<li><a href="http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080">http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080</a></li>
<li><a href="http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080">http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080</a>
</li>
</ul>
</p>

<p>H2 Console in development profile:
<p>H2 Console:
<ul>
<li><a href="http://localhost:8080/h2">http://localhost:8080/h2/</a></li>
</ul>
</p>

<p>javasimon profile:
<p>javasimon 性能监控:
<ul>
<li><a href="http://localhost:8080/javasimon">http://localhost:8080/javasimon</a></li>
</ul>
</p>

<p>druid profile:
<p>Druid 数据监控:
<ul>
<li><a href="http://localhost:8080/druid">http://localhost:8080/druid</a></li>
</ul>
Expand Down
36 changes: 14 additions & 22 deletions deploy/src/main/webapp/static/javascripts/pageutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param pageclick 相应的方法
* @returns {string}
*/
function createPagination(counts, current, itemnum, pagesize, pageclick, showitem, id) {
function createPagination(counts, current, itemnum, pagesize, pageclick) {
current = parseInt(current);
var total = (counts % pagesize) == 0 ? (counts / pagesize) : (parseInt(counts / pagesize) + 1);
var begin = Math.max(1, current - parseInt(itemnum / 2));
Expand All @@ -21,38 +21,30 @@ function createPagination(counts, current, itemnum, pagesize, pageclick, showite
begin = begin < 1 ? 1 : begin;
total = total < 1 ? 1 : total;
end = end < begin ? begin : end;
if (id) {
var content = '<div class="pagination paging" id="' + id + '"><ul>';
} else {
var content = '<div class="pagination paging"><ul>';
}
if (!showitem) {
var arr = ["首页", "上一页", "下一页", "尾页"];
}
var content = '<ul class="pagination">';
var arr = ["首页", "上一页", "下一页", "尾页"];
if (current != 1) {
content += '<li><a class="wen" onclick="' + pageclick + '(1);">' + (arr ? arr[0] : '&lt;&lt;') + '</a></li>' +
'<li><a class="wen" onclick="' + pageclick + '(' + (parseInt(current) - 1) + ');">' + (arr ? arr[1] : '&lt;') + '</a></li>';
content += '<li><a onclick="' + pageclick + '(1);">' + arr[0] + '</a></li>' +
'<li><a onclick="' + pageclick + '(' + (parseInt(current) - 1) + ');">' + arr[1] + '</a></li>';
} else {
content += '<li class="wen disabled"><a href="#">' + (arr ? arr[0] : '&lt;&lt;') + '</a></li>' +
'<li class="wen disabled"><a href="#">' + (arr ? arr[1] : '&lt;') + '</a></li>';
content += '<li class="disabled"><a href="#">' + arr[0] + '</a></li>' +
'<li class="disabled"><a href="#">' + arr[1] + '</a></li>';
}
for (var item = begin; item <= end; item++) {
if (item == current) {
content += '<li class="num disabled"><a href="#">' + item + '</a></li>';
content += '<li class="active"><a href="#">' + item + '</a></li>';
} else {
content += '<li><a class="num" onclick="' + pageclick + '(' + item + ');">' + item + '</a></li>';
content += '<li><a onclick="' + pageclick + '(' + item + ');">' + item + '</a></li>';
}
}
if (current != total) {
content += '<li><a class="wen" onclick="' + pageclick + '(' + (current + 1) + ');">' + (arr ? arr[2] : '&gt;') + '</a></li>' +
'<li><a class="wen" onclick="' + pageclick + '(' + total + ');">' + (arr ? arr[3] : '&gt;&gt;') + '</a></li>';
content += '<li><a onclick="' + pageclick + '(' + (current + 1) + ');">' + arr[2] + '</a></li>' +
'<li><a onclick="' + pageclick + '(' + total + ');">' + arr[3] + '</a></li>';
} else {
content += '<li class="wen disabled"><a href="#">' + (arr ? arr[2] : '&gt;') + '</a></li>' +
'<li class="wen disabled"><a href="#">' + (arr ? arr[3] : '&gt;&gt;') + '</a></li>';
}
if (showitem != false) {
content += '<li class="wen disabled"><a href="#">共' + total + '页</a></li></ul></div>'
content += '<li class="disabled"><a href="#">' + arr[2] + '</a></li>' +
'<li class="disabled"><a href="#">' + arr[3] + '</a></li>';
}
content += '<li class="disabled"><a href="#">共' + total + '页</a></li></ul>';

return content;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Translated default messages for the jQuery validation plugin.
* Locale: ZH (Chinese, 中文 (Zhōngwén), 汉语, 漢語)
*/
jQuery.extend(jQuery.validator.messages, {
required: "必选字段",
remote: "请修正该字段",
email: "请输入正确格式的电子邮件",
url: "请输入合法的网址",
date: "请输入合法的日期",
dateISO: "请输入合法的日期 (ISO).",
number: "请输入合法的数字",
digits: "只能输入整数",
creditcard: "请输入合法的信用卡号",
equalTo: "请再次输入相同的值",
accept: "请输入拥有合法后缀名的字符串",
maxlength: jQuery.validator.format("请输入一个长度最多是 {0} 的字符串"),
minlength: jQuery.validator.format("请输入一个长度最少是 {0} 的字符串"),
rangelength: jQuery.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
max: jQuery.validator.format("请输入一个最大为 {0} 的值"),
min: jQuery.validator.format("请输入一个最小为 {0} 的值")
});

jQuery.extend(jQuery.validator.defaults, {
errorElement: "span"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
span.error {
background:url("images/unchecked.gif") no-repeat 0px 0px;
padding-left: 16px;
margin-left: 1em;
padding-bottom: 2px;
font-weight: bold;
color: #EA5200;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public String error(HttpServletRequest request) {
int status = (int) request.getAttribute("javax.servlet.error.status_code");

Exception exception = (Exception) request.getAttribute(GlobalExceptionHandler.GlobalExceptionAttribute);
if (exception == null) {
exception = (Exception) request.getAttribute("javax.servlet.error.exception");
}
EngineException apiException;
String pageError = "500 - System error.";
if (exception != null && exception instanceof EngineException) {
Expand All @@ -62,7 +65,6 @@ public String error(HttpServletRequest request) {
apiException = EngineExceptionHelper.localException(ExcepFactor.E_DEFAULT);
log.error(errorMsg, exception);
}
log.error(errorMsg, apiException);
if (MediaType.TEXT_HTML.equals(mediaType)) {
return "<!DOCTYPE html>\n" +
"<html>\n" +
Expand Down
10 changes: 5 additions & 5 deletions task/src/main/java/com/appengine/task/dao/TaskDao.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.appengine.task.dao;

import com.appengine.task.domain.Task;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface TaskDao extends PagingAndSortingRepository<Task, Long>, JpaSpecificationExecutor<Task> {

@Modifying
@Query("delete from Task task where task.userId=?1")
void deleteByUserId(Long id);
@Query("delete from Task task where task.uid=?1")
void deleteByUid(Long id);

List<Task> findAllByUserId(long uid);
Page<Task> findByUid(long uid, Pageable request);
}
Loading

0 comments on commit cbcc7fb

Please sign in to comment.