Skip to content

Commit cbcc7fb

Browse files
author
sofn
committed
完成Demo项目-TodoList
1 parent 1b76a14 commit cbcc7fb

File tree

15 files changed

+190
-87
lines changed

15 files changed

+190
-87
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%@ page contentType="text/html;charset=UTF-8" %>
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title><sitemesh:write property='title'/></title>
6+
<sitemesh:write property='head'/>
7+
</head>
8+
<body>
9+
<sitemesh:write property='body'/>
10+
</body>
11+
</html>

deploy/src/main/webapp/WEB-INF/jsp/task/list.jsp

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,84 @@
44

55
<html>
66
<head>
7+
<script language="javascript" src="${ctx}/static/javascripts/pageutil.js"></script>
78
<title>任务管理</title>
89
</head>
910
<body>
1011
<div id="msg"></div>
11-
<div class="row">
12-
<div class="span4 offset7">
13-
<form class="form-search" action="#">
14-
<label>名称:</label>
15-
<input type="text" name="search_LIKE_title" class="input-medium" value="${param.search_LIKE_title}">
16-
<button type="submit" class="btn" id="search_btn">Search</button>
17-
</form>
18-
</div>
19-
</div>
20-
<br/>
2112
<table id="contentTable" class="table table-striped table-bordered table-condensed">
2213
<thead>
2314
<tr>
2415
<th>任务</th>
2516
<th>管理</th>
2617
</tr>
2718
</thead>
28-
<tbody>
29-
<c:forEach items="${tasks.content}" var="task">
30-
<tr>
31-
<td><a href="${ctx}/task/update/${task.id}">${task.title}</a></td>
32-
<td><a href="${ctx}/task/delete/${task.id}">删除</a></td>
33-
</tr>
34-
</c:forEach>
35-
</tbody>
19+
<tbody id="tasks"></tbody>
3620
</table>
3721

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

4024
<div><a class="btn btn-primary" href="${ctx}/web/task/save">创建任务</a></div>
4125
<script lang="javascript">
42-
var page = page || 1;
43-
//TODO
44-
$.ajax({
45-
url: '/task/list',
46-
type: 'post',
47-
data: {
48-
page: page
49-
},
50-
success: function (result) {
51-
var pageDom = $("#pageing");
52-
if (pageDom.length > 0) {
53-
pageDom.html(createPagination(result.counts, result.current, 5, result.pageSize, "pageclick", false, "page"));
26+
var page = 1;
27+
var pagesize = 10;
28+
var tasksDom = $("#tasks");
29+
function createTaskDom(id, title) {
30+
var new_task = $("<tr id='task_" + id + "'>");
31+
var td1 = $("<td>");
32+
td1.appendTo(new_task);
33+
$("<a href=\"${ctx}/web/task/save?id=" + id + "\">" + title + "</a>").appendTo(td1);
34+
var td2 = $("<td>");
35+
td2.appendTo(new_task);
36+
$("<a onclick=\"del_task(" + id + ")\">删除</a>").appendTo(td2);
37+
return new_task;
38+
}
39+
40+
pageclick(1);
41+
42+
function pageclick(to_page) {
43+
tasksDom.html(null);
44+
$.ajax({
45+
url: '/task/list',
46+
type: 'GET',
47+
data: {
48+
page: to_page,
49+
page_size: pagesize
50+
},
51+
success: function (json) {
52+
page = to_page;
53+
var result = json.result;
54+
for (var i = 0; i < result.content.length; i++) {
55+
var task = result.content[i];
56+
createTaskDom(task.id, task.title).appendTo(tasksDom);
57+
}
58+
var pageDom = $("#pageing");
59+
if (pageDom.length > 0) {
60+
pageDom.html(createPagination(result.totalElements, to_page, 5, pagesize, "pageclick"));
61+
}
62+
},
63+
error: function () {
64+
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>服务器错误')
5465
}
55-
},
56-
error: function (XMLHttpRequest, textStatus, errorMsg) {
57-
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>服务器错误')
58-
}
59-
});
66+
});
67+
}
6068
69+
function del_task(id) {
70+
$.ajax({
71+
url: '/task/delete',
72+
type: 'POST',
73+
data: {id: id, _method: "DELETE"},
74+
success: function (json) {
75+
if (json.result) {
76+
$("#task_" + id).remove();
77+
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>删除成功')
78+
}
79+
},
80+
error: function () {
81+
$("#msg").attr("class", "alert alert-success").html('<button data-dismiss="alert" class="close">×</button>服务器错误')
82+
}
83+
});
84+
}
6185
</script>
6286
</body>
6387
</html>

deploy/src/main/webapp/WEB-INF/jsp/task/save.jsp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
<body>
1313
<form id="inputForm" class="form-horizontal">
14+
<input type="hidden" id="task_id" name="title" value="${task.id}"/>
15+
1416
<div id="msg"></div>
1517
<fieldset>
1618
<legend>
@@ -20,14 +22,16 @@
2022
<label for="task_title" class="control-label">任务名称:</label>
2123

2224
<div class="controls">
23-
<input type="text" id="task_title" name="title" class="input-large required" minlength="3"/>
25+
<input type="text" id="task_title" name="title" value="${task.title}" class="input-large required"
26+
minlength="3"/>
2427
</div>
2528
</div>
2629
<div class="control-group">
2730
<label for="description" class="control-label">任务描述:</label>
2831

2932
<div class="controls">
30-
<textarea id="description" name="description" class="input-large required"></textarea>
33+
<textarea id="description" name="description"
34+
class="input-large required">${task.description}</textarea>
3135
</div>
3236
</div>
3337
<div class="form-actions">
@@ -43,6 +47,7 @@
4347
//为inputForm注册validate函数
4448
$("#inputForm").validate({
4549
submitHandler: function () {
50+
var id = $("#task_id").val() || 0;
4651
var title = $("#task_title").val();
4752
var desc = $("#description").val();
4853
$.ajax({
@@ -51,14 +56,14 @@
5156
//提交的网址
5257
url: "${ctx}/task/save",
5358
//提交的数据
54-
data: {"title": title, "desc": desc},
59+
data: {id: id, title: title, desc: desc},
5560
cache: false,
5661
crossDomain: true,
5762
dataType: 'json',
5863
xhrFields: {
5964
withCredentials: true
6065
},
61-
success: function (data) {
66+
success: function () {
6267
$("#msg").attr("class", "text-warning alert alert-error").html("创建成功");
6368
setInterval(function () {
6469
location.href = "${ctx}/web/task";

deploy/src/main/webapp/WEB-INF/sitemesh3.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<sitemesh>
33
<!-- 指明满足“/*”的页面,将被“/WEB-INF/views/decorators/decorator.html”所装饰 -->
4+
<mapping path="/index.html" decorator="/WEB-INF/decorator/none.jsp"/>
45
<mapping path="/*" decorator="/WEB-INF/decorator/default.jsp"/>
56

67
<!-- 指明满足“/exclude.jsp*”的页面,将被排除,不被装饰 -->

deploy/src/main/webapp/index.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,43 @@
55
<title>app-engine</title>
66
</head>
77
<body>
8-
<p>Access below management endpoint:
8+
<p>Demo示例-任务管理
9+
<ul>
10+
<li><a href="http://localhost:8080/web/login">http://localhost:8080/web/login</a></li>
11+
</ul>
12+
</p>
13+
14+
<p>Spring Boot自带监控:
915
<ul>
1016
<li><a href="http://localhost:7002/health">http://localhost:7002/health</a></li>
1117
<li><a href="http://localhost:7002/info">http://localhost:7002/info</a></li>
1218
<li><a href="http://localhost:7002/dump">http://localhost:7002/dump</a></li>
1319
<li><a href="http://localhost:7002/metrics">http://localhost:7002/metrics</a></li>
1420
<li><a href="http://localhost:7002/env">http://localhost:7002/env</a></li>
15-
<li>shutdown(disable by default, POST method)</li></ul>
21+
<li>shutdown(disable by default, POST method)</li>
22+
</ul>
1623
</p>
1724

18-
<p>JMX expose as Restful by jolokia. e.g. Tomcat's MBean:
25+
<p>Tomcat's MBean 监控:
1926
<ul>
20-
<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>
27+
<li><a href="http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080">http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080</a>
28+
</li>
2129
</ul>
2230
</p>
2331

24-
<p>H2 Console in development profile:
32+
<p>H2 Console:
2533
<ul>
2634
<li><a href="http://localhost:8080/h2">http://localhost:8080/h2/</a></li>
2735
</ul>
2836
</p>
2937

30-
<p>javasimon profile:
38+
<p>javasimon 性能监控:
3139
<ul>
3240
<li><a href="http://localhost:8080/javasimon">http://localhost:8080/javasimon</a></li>
3341
</ul>
3442
</p>
3543

36-
<p>druid profile:
44+
<p>Druid 数据监控:
3745
<ul>
3846
<li><a href="http://localhost:8080/druid">http://localhost:8080/druid</a></li>
3947
</ul>

deploy/src/main/webapp/static/javascripts/pageutil.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param pageclick 相应的方法
1313
* @returns {string}
1414
*/
15-
function createPagination(counts, current, itemnum, pagesize, pageclick, showitem, id) {
15+
function createPagination(counts, current, itemnum, pagesize, pageclick) {
1616
current = parseInt(current);
1717
var total = (counts % pagesize) == 0 ? (counts / pagesize) : (parseInt(counts / pagesize) + 1);
1818
var begin = Math.max(1, current - parseInt(itemnum / 2));
@@ -21,38 +21,30 @@ function createPagination(counts, current, itemnum, pagesize, pageclick, showite
2121
begin = begin < 1 ? 1 : begin;
2222
total = total < 1 ? 1 : total;
2323
end = end < begin ? begin : end;
24-
if (id) {
25-
var content = '<div class="pagination paging" id="' + id + '"><ul>';
26-
} else {
27-
var content = '<div class="pagination paging"><ul>';
28-
}
29-
if (!showitem) {
30-
var arr = ["首页", "上一页", "下一页", "尾页"];
31-
}
24+
var content = '<ul class="pagination">';
25+
var arr = ["首页", "上一页", "下一页", "尾页"];
3226
if (current != 1) {
33-
content += '<li><a class="wen" onclick="' + pageclick + '(1);">' + (arr ? arr[0] : '&lt;&lt;') + '</a></li>' +
34-
'<li><a class="wen" onclick="' + pageclick + '(' + (parseInt(current) - 1) + ');">' + (arr ? arr[1] : '&lt;') + '</a></li>';
27+
content += '<li><a onclick="' + pageclick + '(1);">' + arr[0] + '</a></li>' +
28+
'<li><a onclick="' + pageclick + '(' + (parseInt(current) - 1) + ');">' + arr[1] + '</a></li>';
3529
} else {
36-
content += '<li class="wen disabled"><a href="#">' + (arr ? arr[0] : '&lt;&lt;') + '</a></li>' +
37-
'<li class="wen disabled"><a href="#">' + (arr ? arr[1] : '&lt;') + '</a></li>';
30+
content += '<li class="disabled"><a href="#">' + arr[0] + '</a></li>' +
31+
'<li class="disabled"><a href="#">' + arr[1] + '</a></li>';
3832
}
3933
for (var item = begin; item <= end; item++) {
4034
if (item == current) {
41-
content += '<li class="num disabled"><a href="#">' + item + '</a></li>';
35+
content += '<li class="active"><a href="#">' + item + '</a></li>';
4236
} else {
43-
content += '<li><a class="num" onclick="' + pageclick + '(' + item + ');">' + item + '</a></li>';
37+
content += '<li><a onclick="' + pageclick + '(' + item + ');">' + item + '</a></li>';
4438
}
4539
}
4640
if (current != total) {
47-
content += '<li><a class="wen" onclick="' + pageclick + '(' + (current + 1) + ');">' + (arr ? arr[2] : '&gt;') + '</a></li>' +
48-
'<li><a class="wen" onclick="' + pageclick + '(' + total + ');">' + (arr ? arr[3] : '&gt;&gt;') + '</a></li>';
41+
content += '<li><a onclick="' + pageclick + '(' + (current + 1) + ');">' + arr[2] + '</a></li>' +
42+
'<li><a onclick="' + pageclick + '(' + total + ');">' + arr[3] + '</a></li>';
4943
} else {
50-
content += '<li class="wen disabled"><a href="#">' + (arr ? arr[2] : '&gt;') + '</a></li>' +
51-
'<li class="wen disabled"><a href="#">' + (arr ? arr[3] : '&gt;&gt;') + '</a></li>';
52-
}
53-
if (showitem != false) {
54-
content += '<li class="wen disabled"><a href="#">共' + total + '页</a></li></ul></div>'
44+
content += '<li class="disabled"><a href="#">' + arr[2] + '</a></li>' +
45+
'<li class="disabled"><a href="#">' + arr[3] + '</a></li>';
5546
}
47+
content += '<li class="disabled"><a href="#">共' + total + '页</a></li></ul>';
5648

5749
return content;
5850
}
223 Bytes
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Translated default messages for the jQuery validation plugin.
3+
* Locale: ZH (Chinese, 中文 (Zhōngwén), 汉语, 漢語)
4+
*/
5+
jQuery.extend(jQuery.validator.messages, {
6+
required: "必选字段",
7+
remote: "请修正该字段",
8+
email: "请输入正确格式的电子邮件",
9+
url: "请输入合法的网址",
10+
date: "请输入合法的日期",
11+
dateISO: "请输入合法的日期 (ISO).",
12+
number: "请输入合法的数字",
13+
digits: "只能输入整数",
14+
creditcard: "请输入合法的信用卡号",
15+
equalTo: "请再次输入相同的值",
16+
accept: "请输入拥有合法后缀名的字符串",
17+
maxlength: jQuery.validator.format("请输入一个长度最多是 {0} 的字符串"),
18+
minlength: jQuery.validator.format("请输入一个长度最少是 {0} 的字符串"),
19+
rangelength: jQuery.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
20+
range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
21+
max: jQuery.validator.format("请输入一个最大为 {0} 的值"),
22+
min: jQuery.validator.format("请输入一个最小为 {0} 的值")
23+
});
24+
25+
jQuery.extend(jQuery.validator.defaults, {
26+
errorElement: "span"
27+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
span.error {
2+
background:url("images/unchecked.gif") no-repeat 0px 0px;
3+
padding-left: 16px;
4+
margin-left: 1em;
5+
padding-bottom: 2px;
6+
font-weight: bold;
7+
color: #EA5200;
8+
}

frame/src/main/java/com/appengine/frame/help/resources/ErrorHandlerResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public String error(HttpServletRequest request) {
4343
int status = (int) request.getAttribute("javax.servlet.error.status_code");
4444

4545
Exception exception = (Exception) request.getAttribute(GlobalExceptionHandler.GlobalExceptionAttribute);
46+
if (exception == null) {
47+
exception = (Exception) request.getAttribute("javax.servlet.error.exception");
48+
}
4649
EngineException apiException;
4750
String pageError = "500 - System error.";
4851
if (exception != null && exception instanceof EngineException) {
@@ -62,7 +65,6 @@ public String error(HttpServletRequest request) {
6265
apiException = EngineExceptionHelper.localException(ExcepFactor.E_DEFAULT);
6366
log.error(errorMsg, exception);
6467
}
65-
log.error(errorMsg, apiException);
6668
if (MediaType.TEXT_HTML.equals(mediaType)) {
6769
return "<!DOCTYPE html>\n" +
6870
"<html>\n" +

0 commit comments

Comments
 (0)