authorization

master
bseayin 2019-09-26 21:40:40 +08:00
parent 65862d538b
commit 5840e5f8ac
34 changed files with 242 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package com.zz.controller;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -28,4 +29,9 @@ public class OrderController {
return orderService.addmaster(master); return orderService.addmaster(master);
} }
@RequestMapping("show/{id}")
public OrderMaster getById(@PathVariable("id") String id){
return orderService.getById(id);
}
} }

View File

@ -0,0 +1,60 @@
package com.zz.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
/**
* @Description: java
* @Author: Bsea
* @CreateDate: 2019/9/25$ 20:16$
*/
@Entity
public class OrderDetail {
@Id
@Column(length=50)
private String id;
private int num;
private String product_id;
@JsonIgnore
@ManyToOne
@JoinColumn(name="orderMaster_id")
private OrderMaster orderMaster;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getProduct_id() {
return product_id;
}
public void setProduct_id(String product_id) {
this.product_id = product_id;
}
public OrderMaster getOrderMaster() {
return orderMaster;
}
public void setOrderMaster(OrderMaster orderMaster) {
this.orderMaster = orderMaster;
}
}

View File

@ -1,10 +1,13 @@
package com.zz.entity; package com.zz.entity;
import java.sql.Date; import java.sql.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity @Entity
public class OrderMaster { public class OrderMaster {
@ -17,6 +20,17 @@ public class OrderMaster {
private double total; private double total;
private String address; private String address;
private Date createTime; private Date createTime;
@OneToMany(mappedBy = "orderMaster")
private Set<OrderDetail> orderDetailSet =new HashSet<OrderDetail>();
public Set<OrderDetail> getOrderDetailSet() {
return orderDetailSet;
}
public void setOrderDetailSet(Set<OrderDetail> orderDetailSet) {
this.orderDetailSet = orderDetailSet;
}
public String getId() { public String getId() {
return id; return id;
} }

View File

@ -1,11 +1,13 @@
package com.zz.entity; package com.zz.entity;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
@Entity @Entity
public class Product { public class Product {
@Id @Id
@Column(length=50)
private String id; private String id;
private String productName; private String productName;
private String productType; private String productType;

View File

@ -7,4 +7,6 @@ import com.zz.entity.OrderMaster;
public interface OrderMasterRepository extends CrudRepository<OrderMaster,String>{ public interface OrderMasterRepository extends CrudRepository<OrderMaster,String>{
} }

View File

@ -17,4 +17,10 @@ public class OrderService {
return masterRepository.save(master); return masterRepository.save(master);
} }
public OrderMaster getById(String id){
return masterRepository.findById(id).get();
}
} }

View File

@ -20,7 +20,7 @@ public class JwtUtil {
/** /**
* JWT EXPIRE_TIME * JWT EXPIRE_TIME
*/ */
private static final long EXPIRE_TIME = 30 * 60 * 1000; private static final long EXPIRE_TIME = 1 * 25 * 1000;
/** /**
* token * token
@ -82,8 +82,10 @@ public class JwtUtil {
public static void main(String[] args) { public static void main(String[] args) {
/** /**
* token * token
*/
String sign = sign("18888888888", "123456"); String sign = sign("18888888888", "123456");
log.warn("测试生成一个token\n"+sign); log.warn("测试生成一个token\n"+sign);
*/
log.warn(getUsername(null));
} }
} }

View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 实例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>基础表格</h2>
<p id="info"></p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$.post("/r/getlogin",
function(data){
console.log(data); // 2pm
var loginname=data.name;
$("#info").text(loginname);
}, "json");
</script>
</body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 实例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>堆叠表单</h2>
<form>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password">
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" name='rememberMe' type="checkbox"> Remember me
</label>
</div>
<button type="button" id="subtn" class="btn btn-primary">Submit</button>
</form>
</div>
<script type="text/javascript">
$("#subtn").click(function(){
var rememberMe =$("input[name='rememberMe']").is(':checked');
$.post("/r/login", { "username": $("#email").val(),"password": $("#pwd").val(),"rememberMe": rememberMe },
function(data){
console.log(data); //
window.location.href="index1.html";
}, "json");
});
</script>
</body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 实例</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>堆叠表单</h2>
<form>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password">
</div>
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" name='rememberMe' type="checkbox"> Remember me
</label>
</div>
<button type="button" id="subtn" class="btn btn-primary">Submit</button>
</form>
</div>
<script type="text/javascript">
$("#subtn").click(function(){
$.post("/r/user/register", { "username": $("#email").val(),"passwd": $("#pwd").val()},
function(data){
console.log(data); //
window.location.href="index1.html";
}, "json");
});
</script>
</body>
</html>