Skip to content

Commit

Permalink
Spring MVC practise with bootstrap-update
Browse files Browse the repository at this point in the history
  • Loading branch information
BG317958 committed Apr 17, 2018
1 parent 61e2d2d commit d520e4f
Show file tree
Hide file tree
Showing 614 changed files with 72,696 additions and 506 deletions.
1,467 changes: 991 additions & 476 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ log4j.rootLogger=info,stdout,D
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} %d %-5p %m%n

log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File=logs/log.log
log4j.appender.D.Append=true
log4j.appender.D.Threshold=INFO
log4j.appender.D.layout=org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} %d %-5p %m%n
36 changes: 30 additions & 6 deletions src/main/java/controller/LoginController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package controller;

import com.alibaba.fastjson.JSON;
import domain.UserInfo;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import service.LoginService;

import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -38,7 +37,7 @@ public String get(HttpSession session) {
//public String login(@RequestParam("name") String name, String password, ModelMap model){
//public String login(String name, String password, ModelMap model){

@RequestMapping(value = "/loginHere", method = RequestMethod.POST)
@RequestMapping(value = "/loginHere")
public String login(@RequestParam("name") String name, String password, ModelMap model) {
logger.info("Login controller begin service");

Expand All @@ -54,7 +53,7 @@ public String login(@RequestParam("name") String name, String password, ModelMap
user.setPassword("");
model.addAttribute("user", user);

return "redirect:homePage";
return "redirect:/homePage";
} else {
return "login";
}
Expand All @@ -72,4 +71,29 @@ public String visitStaticPage() {
}


//Return to previous path
@ResponseBody
@RequestMapping(value = "/getUserSession")
public String getUserSession( HttpSession session) {
String result="";

Object obj=session.getAttribute("user");
if (obj instanceof String){
result= (String) obj;
}else if (obj instanceof UserInfo){
result=((UserInfo) obj).getName();
}

result= JSON.toJSONString(result);

return result;
}

@RequestMapping("/logOut")
@ResponseBody
public String logout( SessionStatus status){
status.setComplete();
return "logout";
}

}
8 changes: 8 additions & 0 deletions src/main/webapp/WEB-INF/js/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function checkrst(data) {
dataobj=JSON.parse(data);
if(dataobj.rst_code === 0){
return dataobj.rst_data;
}
$.messager.alert('Warning', dataobj.rst_msg);
return false;
}
7 changes: 1 addition & 6 deletions src/main/webapp/WEB-INF/jsp/homePage.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,8 @@
</body>
<!-- Bootstrap core JavaScript================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"
integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n"
crossorigin="anonymous"></script>

<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"
integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script>
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</html>
98 changes: 82 additions & 16 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,54 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./lib/jQuery/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="./lib/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<%--<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">--%>
<%--<link href="https://static.bootcss.com/www/assets/css/site.min.css?1517600071369" rel="stylesheet">--%>
<script src="./lib/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script>
$(function () {
checkLogin();
});
function checkLogin() {
$.ajax("/getUserSession", {
data: null,
async: false,
success: function (d) {
var data = d;
if (data != "" && data != "\"\"") {
$("#login").html("注销");
}
},
error: function (a, b, c) {
console.log(a, b, c);
}
});
}
function logControl() {
var currentStatus = $("#login").html();
if (currentStatus == "登录") {
$('#myModal').modal('show');
} else {
$.ajax({
url: 'logOut',
data: null,
async: false,
success: function (d) {
$("#login").html("登录");
$("#alert").modal('show');
console.log("User log off success!");
}
});
}
}
</script>

</head>

Expand Down Expand Up @@ -40,12 +83,12 @@
<li><a href="eastAlabo/home">中东站</a></li>
</ul>
</li>
<li><a href="#">我的旅行</a></li>
<li><a href="/homePage">我的旅行</a></li>
</ul>


<p class="navbar-text navbar-right" style="margin-right: 10px">
<button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal">登录</button>
<button class="btn btn-primary btn-xs" data-toggle="modal" id="login" onclick="logControl()">登录</button>
</p>

<ul class="nav navbar-nav navbar-right">
Expand All @@ -60,32 +103,36 @@
</nav>

<div class="container">
<div class="jumbotron " style="text-align: center">
<div class="jumbotron blue" style="text-align: center">
<h1>Horizon Index Page</h1>
<p class="lead">CL'aube arrive, l'horizon sera partout. Les rivières et les lacs, selon le soleil et la lune sont tous des sols Han.
<p class="lead">CL'aube arrive, l'horizon sera partout. Les rivières et les lacs, selon le soleil et la lune
sont tous des sols Han.
Dawn is coming, horizon is everywhere</p>
<p><a class="btn btn-lg btn-success" href="#" role="button">Get started today</a></p>
</div>
<div class="row">
<div class="col-sm-4">
<div class="col-md-4">
<h3>大漠孤烟</h3>
<p>再牛逼的梦想,也抵不住你傻逼似的坚持!</p>
</div>
<div class="col-sm-4">
<div class="col-md-4">
<h3>极地风情</h3>
<p>再牛逼的梦想,也抵不住你傻逼似的坚持!</p>
</div>
<div class="col-sm-4">
<div class="col-md-4">
<h3>星辰大海</h3>
<p>再牛逼的梦想,也抵不住你傻逼似的坚持!</p>
</div>
</div>



</div>

<!-- 模态框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 120px">
<form class="bs-example bs-example-form" role="form" action="/loginHere" method="post">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
style="margin-top: 120px">
<form class="bs-example bs-example-form" role="form" action="/loginHere" method="get">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -108,15 +155,17 @@
<br>
<div class="input-group">
<span class="input-group-addon">密码</span>
<input type="password" id="password" name="password" class="form-control" placeholder="Your password">
<input type="password" id="password" name="password" class="form-control"
placeholder="Your password">
</div>
<br>
</div>
</div>

<div class="modal-footer">
<input type="button" class="btn btn-primary" value="注册" style="text-align: left">
<input type="submit" value="登录" class="btn btn-primary" style="margin-right: 10px"/>
<input type="button" class="btn btn-primary" value="注册" style="margin-right: 10px">
<input type="submit" value="登录" class="btn btn-primary" style="margin-right: 10px"
/>
<button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
</div>
</div><!-- /.modal-content -->
Expand All @@ -126,6 +175,23 @@

</div>

<div class="modal fade" id="alert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true"
style="margin-top: 120px" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<p >提示</p>
</div>

<div class="modal-body">
<br>
<p><h3 class="text-success text-center bg-success">Logout 成功!</h3></p>
<br>
</div>
</div>
</div>
</div>


</body>
<%--<script src="/lib/jQuery/jquery-3.2.1.min.js"/>--%>
Expand Down
Loading

0 comments on commit d520e4f

Please sign in to comment.