Browse Source

写完了注册&登录

release/0.0.1
wyz 3 years ago
parent
commit
960584629d
31 changed files with 725 additions and 212 deletions
  1. +182
    -38
      README.md
  2. BIN
      image-20210108231726208.png
  3. BIN
      image-20210108231944550.png
  4. BIN
      image-20210108232120541.png
  5. BIN
      image-20210108232255322.png
  6. BIN
      image-20210108232403810.png
  7. BIN
      image-20210108232529868.png
  8. BIN
      image-20210108232612889.png
  9. BIN
      image-20210109000921900.png
  10. BIN
      image-20210109001010687.png
  11. BIN
      image-20210109102502329.png
  12. BIN
      image-20210109103550442.png
  13. +10
    -0
      src/main/java/com/wyz/demo/bo/UserBO.java
  14. +1
    -1
      src/main/java/com/wyz/demo/config/BasicConfig.java
  15. +65
    -10
      src/main/java/com/wyz/demo/controller/UserController.java
  16. +19
    -7
      src/main/java/com/wyz/demo/dao/UserRepository.java
  17. +2
    -2
      src/main/java/com/wyz/demo/dto/UserDTO.java
  18. +1
    -1
      src/main/java/com/wyz/demo/po/OrderPO.java
  19. +1
    -2
      src/main/java/com/wyz/demo/po/UserPO.java
  20. +21
    -5
      src/main/java/com/wyz/demo/service/UserService.java
  21. +104
    -9
      src/main/java/com/wyz/demo/service/impl/UserServiceImpl.java
  22. +10
    -0
      src/main/java/com/wyz/demo/vo/Message.java
  23. +4
    -4
      src/main/resources/mapper/UserMapper.xml
  24. +2
    -2
      src/main/resources/mybatis-config.xml
  25. +126
    -57
      src/main/resources/static/Index.html
  26. +79
    -8
      src/main/resources/static/Login.html
  27. +59
    -25
      src/main/resources/static/Register.html
  28. +2
    -0
      src/main/resources/static/jquery.js
  29. +0
    -4
      src/test/java/com/wyz/demo/ApplicationTests.java

+ 182
- 38
README.md View File

@ -1,39 +1,183 @@
# 快递代取系统-后端
#### 介绍
# 快递代取系统
## 介绍
前后端分离
后端使用springboot或者flask
提供json的api给前端
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
后端使用springboot
提供json的api给前端
## 软件架构
软件架构说明
## 安装教程
1. xxxx
2. xxxx
3. xxxx
## 使用说明
1. xxxx
2. xxxx
3. xxxx
## 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
# 开发日志
## 自定义Message码
### 错误码
-1 登录:用户名不存在
-2 登录:密码错误
-3 注册:用户名已存在
-4 检查session:用户还未登录
### 正确码
1 登录成功
2 注册成功
3 用户已经登录
## 后端接收ajax数据
2021/01/08
今天遇到了一个很坑爹的问题
jquery的ajax传给后端的数据springboot居然接收不到
### servlet接收ajax
因为springboot本质上是基于servlet的,所以看一下servlet接收ajax是什么样子的
用ajax的前端代码如下:
<img src="C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210108231726208.png" alt="image-20210108231726208" style="zoom:80%;" />
正常用表单提交的方法如下:
![image-20210108232120541](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210108232120541.png)
后端代码如下:
![image-20210108231944550](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210108231944550.png)
用ajax发数据,结果如下:(好像第二行最前面少了一个问号?不知道表单提交的有没有)
![image-20210108232255322](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210108232255322.png)
正常表单提交,结果如下:
![image-20210108232403810](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210108232403810.png)
第二行为null是因为流只能读取一次
修改以下后端代码,看看用表单提交的话InputStream是什么样的
![image-20210108232529868](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210108232529868.png)
输出!
![image-20210108232612889](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210108232612889.png)
fuck!我一开始还以为是最前面少了个问号的关系,结果正常用表单提交最前面也是没有问号的
这个问题我没找到解决方法(似乎只能自己解析InputStream了?)
ajax那边不管data的数据有没有加上JSON.stringify()都不行
**山穷水尽疑无路 ,柳暗花明又一村**
我又回头搜了一下springboot和ajax,有了重大发现
### springboot接收ajax
![image-20210109000921900](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210109000921900.png)
==注意画红框的这个类,这个类是需要可序列化的!!!==
![image-20210109001010687](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210109001010687.png)
==前端传json时,需要加上JSON.Stringify==
<img src="C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210109103550442.png" alt="image-20210109103550442" style="zoom:80%;" />
## ajax获取后端返回的数据
又碰到一个坑。。。
按理说ajax这么写就行了,我还特意加了async:false来取消异步
![image-20210109102502329](C:\Users\wyz\Desktop\云计算\期末大作业\DeliveryTakingSystem\image-20210109102502329.png)
结果前端执行的是error函数。。。
后来发现:
**前端设置了希望后端发来的类型(dataType:"application/json")**
**但是后端没有设置返回类型**
把dataType删了就行

BIN
image-20210108231726208.png View File

Before After
Width: 534  |  Height: 549  |  Size: 30 KiB

BIN
image-20210108231944550.png View File

Before After
Width: 1129  |  Height: 435  |  Size: 43 KiB

BIN
image-20210108232120541.png View File

Before After
Width: 1096  |  Height: 416  |  Size: 38 KiB

BIN
image-20210108232255322.png View File

Before After
Width: 1395  |  Height: 69  |  Size: 12 KiB

BIN
image-20210108232403810.png View File

Before After
Width: 1385  |  Height: 75  |  Size: 12 KiB

BIN
image-20210108232529868.png View File

Before After
Width: 1034  |  Height: 446  |  Size: 41 KiB

BIN
image-20210108232612889.png View File

Before After
Width: 1538  |  Height: 35  |  Size: 6.9 KiB

BIN
image-20210109000921900.png View File

Before After
Width: 557  |  Height: 313  |  Size: 18 KiB

BIN
image-20210109001010687.png View File

Before After
Width: 553  |  Height: 203  |  Size: 11 KiB

BIN
image-20210109102502329.png View File

Before After
Width: 719  |  Height: 704  |  Size: 43 KiB

BIN
image-20210109103550442.png View File

Before After
Width: 675  |  Height: 409  |  Size: 31 KiB

+ 10
- 0
src/main/java/com/wyz/demo/bo/UserBO.java View File

@ -0,0 +1,10 @@
package com.wyz.demo.bo;
import lombok.Data;
@Data
public class UserBO {
public String username;
public String password;
}

+ 1
- 1
src/main/java/com/wyz/demo/config/BasicConfig.java View File

@ -21,7 +21,7 @@ public class BasicConfig {
public SqlSession sqlSession(){
try{
InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
return new SqlSessionFactoryBuilder().build(inputStream).openSession();
return new SqlSessionFactoryBuilder().build(inputStream).openSession(true);
}catch (Exception e){
return null;
}

+ 65
- 10
src/main/java/com/wyz/demo/controller/UserController.java View File

@ -2,13 +2,16 @@ package com.wyz.demo.controller;
import com.wyz.demo.dto.UserDTO;
import com.wyz.demo.po.User;
import com.wyz.demo.service.UserService;
import com.wyz.demo.vo.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Slf4j
@RestController
@ -24,17 +27,69 @@ public class UserController {
}
@PostMapping(value = "/add", produces = "application/json")
public void f(UserDTO u){
User uu = new User();
uu.setId(u.getId());
uu.setUsername(u.getUsername());
uu.setPassword(u.getPassword());
uu.setPhone(u.getPhone());
/**
* 用户注册
*
* 情况1: 用户名已经被注册了
* 情况2: 正常注册
*
* @return
*/
@PostMapping(value = "/register")
public Message register(@RequestBody UserDTO u, HttpServletResponse resp, HttpSession sess){
log.info("this is userDTO: {}",u);
Message msg = userService.addUser(u,resp,sess);
return msg;
}
/**
* 用户登录: 需要返回
*
* 情况1: 用户名不存在
* 情况2: 用户名存在, 但是密码错误
* 情况3: 正确登录, 并注册一个session
*
* @param u
*/
@PostMapping(value = "/login")
public Message login(@RequestBody UserDTO u, HttpServletResponse resp, HttpSession sess){
log.info("this is userDTO: {}",u);
Message msg = userService.checkUser(u, resp, sess);
return msg;
}
/**
* 添加用户: 前端发个请求看看用户是否登录
*
* 情况1: 没有登录
* 情况2: 已经登录
*
* @return
*/
@RequestMapping(value = "/check")
public Message check(HttpSession sess){
Message msg = userService.checkStatus(sess);
return msg;
}
userService.addUser(u);
/**
* 添加用户: 前端发个请求注销
*
* 情况1:
*
* @return
*/
@RequestMapping(value = "/logout")
public void logout(HttpSession sess){
log.info("用户:{} 已经注销",sess.getAttribute("username"));
sess.invalidate();
}

+ 19
- 7
src/main/java/com/wyz/demo/dao/UserRepository.java View File

@ -1,8 +1,7 @@
package com.wyz.demo.dao;
import com.wyz.demo.po.User;
import org.springframework.stereotype.Repository;
import com.wyz.demo.po.UserPO;
import java.util.List;
@ -10,14 +9,27 @@ import java.util.List;
public interface UserRepository {
// 注册用户(添加)
public void addUser(User user);
public void addUser(UserPO user);
// 查找用户: 根据id
public User findUserById(int id);
/**
* 判断用户名是否存在
* @return
*/
public UserPO selectUserByUsername(String username);
// /**
// * 判断密码是否正确
// * @param username fw
// * @Param password e fe
// * @return
// */
// public UserPO checkPassword(String username, String password);
// 查找用户: 根据id
public UserPO findUserById(int id);
// 查找用户: 根据username
public List<User> findUserByName(String username);
}

+ 2
- 2
src/main/java/com/wyz/demo/dto/UserDTO.java View File

@ -1,10 +1,10 @@
package com.wyz.demo.dto;
import lombok.Data;
import java.io.Serializable;
@Data
public class UserDTO {
public int id;
public class UserDTO implements Serializable {
public String username;
public String password;
public String phone;

src/main/java/com/wyz/demo/po/Order.java → src/main/java/com/wyz/demo/po/OrderPO.java View File

@ -6,7 +6,7 @@ import lombok.Data;
import java.util.Date;
@Data
public class Order {
public class OrderPO {
public int orderId;
public String description;
public Date datetime;

src/main/java/com/wyz/demo/po/User.java → src/main/java/com/wyz/demo/po/UserPO.java View File

@ -4,10 +4,9 @@ package com.wyz.demo.po;
import lombok.Data;
@Data
public class User {
public class UserPO {
public int id;
public String username;
public String password;
public String phone;
}

+ 21
- 5
src/main/java/com/wyz/demo/service/UserService.java View File

@ -2,16 +2,32 @@ package com.wyz.demo.service;
import com.wyz.demo.dto.UserDTO;
import com.wyz.demo.po.User;
import org.springframework.stereotype.Service;
import com.wyz.demo.vo.Message;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public interface UserService {
/**
* 添加用户
* @param userDTO
* @return
*/
public Message addUser(UserDTO userDTO, HttpServletResponse resp, HttpSession sess);
public interface UserService {
public void addUser(UserDTO userDTO);
/**
* 检查用户是否可以登录
* @return
*/
public Message checkUser(UserDTO userDTO, HttpServletResponse resp, HttpSession sess);
/**
* 检查用户是否已经登录(检查session)
*/
public Message checkStatus(HttpSession sess);
}

+ 104
- 9
src/main/java/com/wyz/demo/service/impl/UserServiceImpl.java View File

@ -3,26 +3,121 @@ package com.wyz.demo.service.impl;
import com.wyz.demo.dao.UserRepository;
import com.wyz.demo.dto.UserDTO;
import com.wyz.demo.po.User;
import com.wyz.demo.po.UserPO;
import com.wyz.demo.service.UserService;
import com.wyz.demo.vo.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Service
@Slf4j
public class UserServiceImpl implements UserService {
@Autowired
private UserRepository userRepository;
/**
* 用户注册
* @param userDTO
* @param resp
* @param sess
* @return
*/
@Override
public Message addUser(UserDTO userDTO, HttpServletResponse resp, HttpSession sess) {
log.info("请求注册的用户名是:{}",userDTO.getUsername());
log.info("请求注册的密码是:{}",userDTO.getPassword());
log.info("请求注册的手机号是:{}",userDTO.getPhone());
Message msg = new Message();
UserPO userPO = userRepository.selectUserByUsername(userDTO.getUsername()); //判断用户名是否存在
if(userPO!=null){
msg.setFlag(-3);
msg.setMsg("该用户名已经注册");
}else{
msg.setFlag(2);
msg.setMsg("注册成功");
// 在数据库中加一个用户
UserPO u = new UserPO();
u.setUsername(userDTO.getUsername());
u.setPassword(userDTO.getPassword());
u.setPhone(userDTO.getPhone());
userRepository.addUser(u);
// 创建一个session, 把Jsessionid发给前端。前端会跳回首页, 首页会负责查看有没有session
sess.setAttribute("username",u.getUsername());
Cookie cookie = new Cookie("JSESSIONID",sess.getId());
resp.addCookie(cookie);
}
return msg;
}
/**
* 判断用户可否登录
* @param userDTO
* @param sess
* @return
*/
@Override
public void addUser(UserDTO userDTO) {
User u = new User();
u.setId(userDTO.getId());
u.setUsername(userDTO.getUsername());
u.setPassword(userDTO.getPassword());
u.setPhone(userDTO.getPhone());
userRepository.addUser(u);
public Message checkUser(UserDTO userDTO, HttpServletResponse resp, HttpSession sess) {
log.info("请求登录的用户名是:{}",userDTO.getUsername());
log.info("请求登录的密码是:{}",userDTO.getPassword());
Message msg = new Message();
UserPO userPO = userRepository.selectUserByUsername(userDTO.getUsername()); //判断用户名是否存在
if(userPO == null){
msg.setFlag(-1);
msg.setMsg("用户不存在");
}else if(!userDTO.getPassword().equals(userPO.getPassword())){
msg.setFlag(-2);
msg.setMsg("密码不正确");
}else{
msg.setFlag(1);
msg.setMsg("登录成功");
// 创建一个session, 把Jsessionid发给前端。前端会跳回首页, 首页会负责查看有没有session
sess.setAttribute("username",userPO.getUsername());
Cookie cookie = new Cookie("JSESSIONID",sess.getId());
resp.addCookie(cookie);
}
return msg;
}
/**
* 判断用户是否已经登录
* @param sess
* @return
*/
@Override
public Message checkStatus(HttpSession sess) {
Message msg = new Message();
if(sess.isNew()){
msg.setFlag(-4);
msg.setMsg("用户还未登录");
sess.invalidate();
}else{
msg.setFlag(3);
msg.setMsg("用户已经登录");
}
return msg;
}
}

+ 10
- 0
src/main/java/com/wyz/demo/vo/Message.java View File

@ -0,0 +1,10 @@
package com.wyz.demo.vo;
import lombok.Data;
@Data
public class Message {
int flag;
String msg;
}

+ 4
- 4
src/main/resources/mapper/UserMapper.xml View File

@ -6,17 +6,17 @@
<!-- 实现哪个Dao -->
<mapper namespace="com.wyz.demo.dao.UserRepository">
<insert id="addUser" parameterType="User">
insert into user (id,username,password,phone) values (#{id},#{username},#{password}, #{phone})
<insert id="addUser" parameterType="com.wyz.demo.po.UserPO">
insert into user (username,password,phone) values (#{username},#{password}, #{phone})
</insert>
<select id="findUserById" resultType="com.wyz.demo.po.User" parameterType="int">
<select id="findUserById" resultType="com.wyz.demo.po.UserPO" parameterType="int">
select * from user where id = #{id}
</select>
<select id="findUserByName" resultType="com.wyz.demo.po.User" parameterType="java.lang.String">
<select id="selectUserByUsername" resultType="com.wyz.demo.po.UserPO" parameterType="java.lang.String">
select * from user where username = #{username}
</select>

+ 2
- 2
src/main/resources/mybatis-config.xml View File

@ -14,8 +14,8 @@
<!-- 类的别名 -->
<typeAliases>
<!-- 手动一个个指定 -->
<typeAlias alias="User" type="com.wyz.demo.po.User"/>
<typeAlias alias="Order" type="com.wyz.demo.po.Order"/>
<typeAlias alias="User" type="com.wyz.demo.po.UserPO"/>
<typeAlias alias="Order" type="com.wyz.demo.po.OrderPO"/>
<!-- &lt;!&ndash; 直接扫描包,一次性处理里面的所有类 &ndash;&gt;-->
<!-- <package name="cn.test.ssm.po"></package>-->

+ 126
- 57
src/main/resources/static/Index.html View File

@ -8,27 +8,72 @@
<script src="bootstrap-3.3.4/dist/js/jquery-1.11.3.min.js"></script>
<script src="bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
<script src="Flat-UI-master/dist/js/flat-ui.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.0.js"></script>
<title>主页</title>
<style>
.row{
margin-top: 20px;;
.row {
margin-top: 20px;;
}
.center{
.center {
text-align: center;
}
.pagination{
.pagination {
background: #cccccc;
}
</style>
<script>
$(function(){
$('#myTabs a').click(function (e) {
$(this).tab('show')
});
})
</script>
</head>
<body>
<script>
$(function () {
// 发一个请求给后端, 让后端看看有没有session
$.ajax({
url:"/user/check",
success: function (data) {
if(data["flag"] < 0){
// 还没登录
$("#logout").hide();
}else{
// 已经登录了
$("#register").hide();
$("#login").hide();
}
},
error: function () {
console.log("error");
}
});
// 点了注销会发生什么
$("#logout").click(function () {
$("#logout").hide();
$("#register").show();
$("#login").show();
$.ajax({
url:"/user/logout",
success: function (data) {
console.log("log out success")
},
error: function () {
console.log("error");
}
});
});
})
</script>
<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
@ -46,16 +91,23 @@
<li><a href="FriendLink.html">友情链接</a></li>
</ul>
<ul class="nav navbar-nav navbar-right hidden-sm">
<li><a href="Login.html">登录</a></li>
<li><a href="Register.html">注册</a></li>
<li><a id="login" href="Login.html">登录</a></li>
<li><a id="register" href="Register.html">注册</a></li>
<li><a id="logout" href="#">注销</a></li>
<li>
<a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a></li>
<a href="Cart.html"><span class="glyphicon glyphicon-shopping-cart">购物车</span></a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<!--content-->
<div class="container">
<div class="jumbotron">
<h1>图书商城</h1>
<p>...</p>
@ -63,19 +115,24 @@
</div>
<ul class="nav nav-tabs" id="myTabs">
<li class="active"><a href="#" >计算机</a></li>
<li><a href="#">都市言情</a></li>
<li><a href="#">军事科技</a></li>
<li><a href="#">历史人文</a></li>
<li><a href="#">都市言情</a></li>
<li><a href="#">军事科技</a></li>
<li><a href="#">历史人文</a></li>
<li class="active"><a href="#">默认排序</a></li>
<li><a href="#">浏览量从高到低</a></li>
<li><a href="#">浏览量从低到高</a></li>
<li><a href="#">更新时间从新到老</a></li>
<li><a href="#">更新时间从老到新</a></li>
<li><a href="#">价格从小到大</a></li>
<li><a href="#">价格从大到小</a></li>
</ul>
<!-- 订单详情页 -->
<div class="row">
<div class="col-sm-4 col-md-3">
<div class="thumbnail" >
<div class="thumbnail">
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/100%x200" data-holder-rendered="true">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg=="
data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
@ -85,21 +142,25 @@
</div>
</div>
<div class="col-sm-4 col-md-3">
<div class="thumbnail" >
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
<p><span>价格:</span><span>100.00</span></p>
<p><a class="btn btn-primary btn-block" role="button" href="#">查看详情</a></p>
<div class="thumbnail">
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg=="
data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
<p><span>价格:</span><span>100.00</span></p>
<p><a class="btn btn-primary btn-block" role="button" href="#">查看详情</a></p>
</div>
</div>
</div>
</div>
<div class="col-sm-4 col-md-3">
<div class="thumbnail" >
<div class="thumbnail">
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/100%x200" data-holder-rendered="true">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg=="
data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
@ -109,9 +170,11 @@
</div>
</div>
<div class="col-sm-4 col-md-3">
<div class="thumbnail" >
<div class="thumbnail">
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/100%x200" data-holder-rendered="true">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg=="
data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
@ -121,32 +184,36 @@
</div>
</div>
<div class="col-sm-4 col-md-3">
<div class="thumbnail" >
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
<p><span>价格:</span><span>100.00</span></p>
<p><a class="btn btn-primary btn-block" role="button" href="#">查看详情</a></p>
<div class="thumbnail">
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg=="
data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
<p><span>价格:</span><span>100.00</span></p>
<p><a class="btn btn-primary btn-block" role="button" href="#">查看详情</a></p>
</div>
</div>
</div>
</div>
<div class="col-sm-4 col-md-3">
<div class="thumbnail" >
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg==" data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
<p><span>价格:</span><span>100.00</span></p>
<p><a class="btn btn-primary btn-block" role="button" href="#">查看详情</a></p>
<div class="thumbnail">
<a href="BookInfo.html">
<img style="width: 100%; height: 200px; display: block;" alt="100%x200"
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzNDggMjAwIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIG1lZXQiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIj48ZGVmcyAvPjxyZWN0IGZpbGw9IiNlZWVlZWUiIHdpZHRoPSIzNDgiIGhlaWdodD0iMjAwIiAvPjxnPjx0ZXh0IHN0eWxlPSJmb250LWZhbWlseTogQXJpYWwsIEhlbHZldGljYSwgT3BlbiBTYW5zLCBzYW5zLXNlcmlmLCBtb25vc3BhY2U7IGZvbnQtc2l6ZTogMjJweDsgZm9udC13ZWlnaHQ6IGJvbGQ7IGRvbWluYW50LWJhc2VsaW5lOiBjZW50cmFsOyBmaWxsOiAjYWFhYWFhOyIgeD0iMTMxLjE2IiB5PSIxMDAiPjM0OHgyMDA8L3RleHQ+PC9nPjwvc3ZnPg=="
data-src="holder.js/100%x200" data-holder-rendered="true">
</a>
<div class="caption center">
<h3>书名</h3>
<p><span>价格:</span><span>100.00</span></p>
<p><a class="btn btn-primary btn-block" role="button" href="#">查看详情</a></p>
</div>
</div>
</div>
</div>
</div>
<!-- 分页 -->
<nav class="center">
<ul class="pagination pagination-lg">
<li>
@ -169,9 +236,11 @@
</div>
<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
版权声明区
<p style="text-align: center">版权声明区</p>
</div>
</body>
</html>

+ 79
- 8
src/main/resources/static/Login.html View File

@ -8,15 +8,67 @@
<script src="bootstrap-3.3.4/dist/js/jquery-1.11.3.min.js"></script>
<script src="bootstrap-3.3.4/dist/js/bootstrap.min.js"></script>
<script src="Flat-UI-master/dist/js/flat-ui.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.0.js"></script>
<title>登录</title>
<style>
.row{
margin-left: 20px;
margin-right: 20px;;
}
</style>
</head>
<body>
<script>
$(function(){
$("button").click(function () {
// alert($("input#username").val());
// alert($("form").serialize());
$.ajax({
url:"/user/login",
data: JSON.stringify({
username: $("input#username").val(),
password: $("input#password").val()
}),
// data: $("form").serialize(),
contentType: "application/json; charset=utf-8",
// dataType: "application/json",
type: "POST",
async: false,
success: function(data){
if(data["flag"] < 0){
$("#common").children().first().text(data["msg"]);
$("#common").show();
} else {
$("#common").hide();
// 成功的话. 还要跳转到首页
location.assign("Index.html");
}
},
error: function () {
alert("登录错误!!!请联系开发者wyz解决问题")
}
});
})
});
</script>
<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
@ -42,6 +94,7 @@
</div><!--/.nav-collapse -->
</div>
</div>
<!--content-->
<div class="container">
<div class="row thumbnail center">
@ -49,19 +102,35 @@
<h1 class="text-center" style="margin-bottom: 30px">用户登录</h1>
</div>
<div class="col-sm-6">
<form class="form-horizontal caption">
<form class="form-horizontal caption" action="http://www.baidu.com" onsubmit="return false;"> <!-- 表单 form -->
<!-- 用户名 -->
<div class="form-group">
<label for="username" class="col-sm-3 control-label">用户名</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="username" placeholder="用户名">
<input type="text" class="form-control" id="username" placeholder="用户名"> <!-- username-->
</div>
<!-- 密码 -->
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">密码</label>
<div class="col-sm-8">
<input type="password" class="form-control" id="password" placeholder="密码">
<input type="password" class="form-control" id="password" placeholder="密码"> <!-- password -->
</div>
</div>
<!-- 提示信息: 用户不存在or密码错误 -->
<div class="form-group">
<div class="col-sm-offset-3 col-sm-8">
<p id="common" style="font-size: 10px; display: none;">&nbsp;&nbsp;&nbsp;<b>msg</b></p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<div class="checkbox">
@ -71,20 +140,22 @@
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-5">
<button type="submit" class="btn btn-success btn-block">登录</button>
<button type="submit" class="btn btn-success btn-block" onsubmit="return login();">登录</button>
</div>
</div>
</form>
</div>
<div class="col-sm-6">
<div class="caption">
<h3>免责声明</h3>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p>放心, 我们会负责的</p>
</div>
</div>
</div>
@ -93,7 +164,7 @@
<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
版权声明区
<p style="text-align: center">版权声明区</p>
</div>
</body>
</html>

+ 59
- 25
src/main/resources/static/Register.html View File

@ -16,23 +16,47 @@
}
</style>
</head>
<body>
<script>
$(function(){
var host = "http://localhost:8081";
// $("button").click(function(){
// console.log("注册了,向服务器发送数据");
// $.ajax(host+"/user/add",
// data:{
// });
// return false;
// })
});
function k(){
return false;
}
$(function(){
$("button").click(function () {
$.ajax({
url:"/user/register",
data: JSON.stringify({
username: $("input#username").val(),
password: $("input#password").val(),
phone: $("input#telephone").val()
}),
contentType: "application/json; charset=utf-8",
// dataType: "application/json",
type: "POST",
async: false,
success: function(data){
if(data["flag"]<0){
$("#common").children().first().text(data["msg"]);
$("#common").show();
} else {
$("#common").hide();
location.assign("Index.html");
}
},
error: function () {
alert("注册错误!!!请联系开发者wyz解决问题")
}
});
})
});
</script>
@ -70,10 +94,10 @@
<h1 class="text-center" style="margin-bottom: 30px">用户注册</h1>
</div>
<div class="col-sm-6">
<!-- 表单开始 -->
<form class="form-horizontal caption" action="http://localhost:8081/user/add" method="post">
<!-- 表单开始 -->
<form class="form-horizontal caption" action="https://www.baidu.com" method="post" onsubmit="return k();">
<div class="form-group">
<label for="username" class="col-sm-3 control-label">用户名</label>
<div class="col-sm-8">
@ -88,12 +112,12 @@
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">确认密码</label>
<div class="col-sm-8">
<input type="password" class="form-control" id="password2" placeholder="确认密码">
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label for="password" class="col-sm-3 control-label">确认密码</label>-->
<!-- <div class="col-sm-8">-->
<!-- <input type="password" class="form-control" id="password2" placeholder="确认密码">-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="form-group">
<label for="inlineRadio1" class="col-sm-3 control-label">性别</label>
@ -129,6 +153,15 @@
<input type="email" class="form-control" id="email" placeholder="邮箱">
</div>
</div> -->
<!-- 提示信息: 用户不存在or密码错误 -->
<div class="form-group">
<div class="col-sm-offset-3 col-sm-8">
<p id="common" style="font-size: 10px; display: none;">&nbsp;&nbsp;&nbsp;<b>msg</b></p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-5">
@ -137,6 +170,7 @@
</div>
</form>
</div>
<div class="col-sm-6">
<div class="caption">
<h3>免责声明</h3>
@ -152,7 +186,7 @@
<!--footer-->
<div class="navbar navbar-default navbar-static-bottom">
版权声明区
<p style="text-align: center">版权声明区</p>
</div>
</body>
</html>

+ 2
- 0
src/main/resources/static/jquery.js
File diff suppressed because it is too large
View File


+ 0
- 4
src/test/java/com/wyz/demo/ApplicationTests.java View File

@ -1,10 +1,6 @@
package com.wyz.demo;
import com.wyz.demo.po.User;
import com.wyz.demo.service.UserService;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

Loading…
Cancel
Save