Compare commits
20 Commits
5399b6eb75
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 44b64aa9df | |||
| 97ad9f1bbb | |||
| 25d2148d8e | |||
| 37e942c0c9 | |||
| 429a2c6f9e | |||
| 7a7c2e85e3 | |||
| 84206e653d | |||
| a788440b3b | |||
| ba0ad95e8d | |||
| f1abd66657 | |||
| 3dacb0022f | |||
| 4c470ac721 | |||
| bcd373a21d | |||
| a7b92e1331 | |||
| 05460ae359 | |||
| 98dfe79bcd | |||
| 29ec339e8f | |||
| ed0204aae5 | |||
| 7134e6c5ff | |||
| 9f18c47514 |
5
pom.xml
5
pom.xml
@@ -60,6 +60,11 @@
|
|||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-core</artifactId>
|
||||||
|
<version>3.5.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
74
src/main/java/com/gao/finalhw/controller/APIController.java
Normal file
74
src/main/java/com/gao/finalhw/controller/APIController.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package com.gao.finalhw.controller;
|
||||||
|
|
||||||
|
import com.gao.finalhw.model.Address;
|
||||||
|
import com.gao.finalhw.model.Orders;
|
||||||
|
import com.gao.finalhw.model.UserInfo;
|
||||||
|
import com.gao.finalhw.response.ServerResponseEntity;
|
||||||
|
import com.gao.finalhw.service.AddrService;
|
||||||
|
import com.gao.finalhw.service.CartService;
|
||||||
|
import com.gao.finalhw.service.OrderService;
|
||||||
|
import com.gao.finalhw.service.UserInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
public class APIController {
|
||||||
|
@Autowired
|
||||||
|
private CartService cartService;
|
||||||
|
@Autowired
|
||||||
|
private UserInfoService userInfoService;
|
||||||
|
@Autowired
|
||||||
|
private OrderService orderService;
|
||||||
|
@Autowired
|
||||||
|
private AddrService addrService;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/get_cart_count")
|
||||||
|
public ServerResponseEntity<Integer> getCartCount(@RequestParam("user_id") int userId) {
|
||||||
|
try {
|
||||||
|
int cartCount = cartService.getCartCount(userId);
|
||||||
|
return ServerResponseEntity.success(cartCount);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 处理异常,例如用户 ID 不存在的情况
|
||||||
|
return ServerResponseEntity.fail("server error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@GetMapping("/get_user_info")
|
||||||
|
public ServerResponseEntity<UserInfo> get_userInfo(@RequestParam("user_id") int userId){
|
||||||
|
UserInfo userInfo = userInfoService.getUserInfo(userId);
|
||||||
|
if (userInfo != null){
|
||||||
|
return ServerResponseEntity.success(userInfo);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("don't query user info by id.");
|
||||||
|
}
|
||||||
|
@GetMapping("/get_order_info")
|
||||||
|
public ServerResponseEntity<Orders> get_OrderInfo(@RequestParam("order_id") int orderId){
|
||||||
|
Orders order = orderService.getOrderInfo(orderId);
|
||||||
|
if (order != null){
|
||||||
|
return ServerResponseEntity.success(order);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("don't query order info by id.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get_order_info/user")
|
||||||
|
public ServerResponseEntity<Orders> get_OrderInfoByUserId(@RequestParam("user_id") int userId){
|
||||||
|
Orders order = orderService.getOrderInfoByUserId(userId);
|
||||||
|
if (order != null){
|
||||||
|
return ServerResponseEntity.success(order);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("don't query order info by id.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get_addr_info")
|
||||||
|
public ServerResponseEntity<Address> get_AddrInfo(@RequestParam("user_id") int userId){
|
||||||
|
Address addressInfo = addrService.getAddrById(userId);
|
||||||
|
if (addressInfo != null){
|
||||||
|
return ServerResponseEntity.success(addressInfo);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("don't query addr info by id.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ public class CartPageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/cart_oder_success")
|
@GetMapping("/cart_order_success")
|
||||||
public String cartOrderSuccessPage() {
|
public String cartOrderSuccessPage() {
|
||||||
return "cart_order_success";
|
return "cart_order_success";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.gao.finalhw.controller;
|
||||||
|
|
||||||
|
import com.gao.finalhw.model.Orders;
|
||||||
|
import com.gao.finalhw.response.ServerResponseEntity;
|
||||||
|
import com.gao.finalhw.service.OrderService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RequestMapping("/order")
|
||||||
|
@RestController
|
||||||
|
public class OrderController {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(OrderController.class);
|
||||||
|
@Autowired
|
||||||
|
OrderService orderService;
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public ServerResponseEntity<Boolean> addOrder(@RequestBody Orders orders) {
|
||||||
|
logger.info("start add order.");
|
||||||
|
if (orders != null) {
|
||||||
|
if (orderService.addOrder(orders)) {
|
||||||
|
return ServerResponseEntity.success(true);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("insert fail.");
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("order data error.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public ServerResponseEntity<Boolean> updateOrder(@RequestBody Orders orders) {
|
||||||
|
logger.info("start update order.");
|
||||||
|
if (orders != null) {
|
||||||
|
if (orderService.updateOrder(orders)) {
|
||||||
|
return ServerResponseEntity.success(true);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("update fail.");
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("order data error.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public ServerResponseEntity<Boolean> deleteOrder(@RequestBody Orders orders) {
|
||||||
|
logger.info("start delete order by id.");
|
||||||
|
if (orders != null) {
|
||||||
|
if (orderService.deleteById(orders)) {
|
||||||
|
return ServerResponseEntity.success(true);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("delete fail.");
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("order data error.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete1")
|
||||||
|
public ServerResponseEntity<Boolean> deleteOrderByUserId(@RequestBody Orders orders) {
|
||||||
|
logger.info("start delete order by user id.");
|
||||||
|
if (orders != null) {
|
||||||
|
if (orderService.deleteByUserId(orders)) {
|
||||||
|
return ServerResponseEntity.success(true);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("delete fail.");
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("order data error.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
package com.gao.finalhw.controller;
|
package com.gao.finalhw.controller;
|
||||||
|
|
||||||
|
import com.gao.finalhw.model.PasswordData;
|
||||||
import com.gao.finalhw.model.User;
|
import com.gao.finalhw.model.User;
|
||||||
import com.gao.finalhw.pojo.LoginRequest;
|
import com.gao.finalhw.pojo.LoginRequest;
|
||||||
import com.gao.finalhw.response.ServerResponseEntity;
|
import com.gao.finalhw.response.ServerResponseEntity;
|
||||||
import com.gao.finalhw.service.UserService;
|
import com.gao.finalhw.service.UserService;
|
||||||
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -16,19 +21,56 @@ public class UserController {
|
|||||||
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
private final Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public ServerResponseEntity<User> login(@RequestBody LoginRequest loginRequest) {
|
public ServerResponseEntity<User> login(@RequestBody LoginRequest loginRequest, HttpSession session, HttpServletResponse response) {
|
||||||
logger.info("username: {},password: {}", loginRequest.getUsername(), loginRequest.getPassword());
|
logger.info("username: {},password: {}", loginRequest.getUsername(), loginRequest.getPassword());
|
||||||
User user = userService.getUserByUsernameAndPassword(loginRequest.getUsername(), loginRequest.getPassword());
|
User user = userService.getUserByUsernameAndPassword(loginRequest.getUsername(), loginRequest.getPassword());
|
||||||
logger.info("user: {}",user.toString());
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
logger.info("user: {}", user);
|
||||||
// 隐藏密码
|
// 隐藏密码
|
||||||
user.setPassword("null");
|
user.setPassword("null");
|
||||||
|
Cookie cookie = new Cookie("user_id", String.valueOf(user.getUserId()));
|
||||||
|
response.addCookie(cookie);
|
||||||
|
session.setAttribute("user", user);
|
||||||
// 如果验证成功
|
// 如果验证成功
|
||||||
return ServerResponseEntity.success("1", user);
|
return ServerResponseEntity.success(0, user);
|
||||||
} else {
|
} else {
|
||||||
// 如果验证失败
|
// 如果验证失败
|
||||||
return ServerResponseEntity.fail("username or password error.");
|
return ServerResponseEntity.fail("username or password error.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/register")
|
||||||
|
public ServerResponseEntity<Boolean> register(@RequestBody User user) {
|
||||||
|
if (userService.register(user)) {
|
||||||
|
return ServerResponseEntity.success(true);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("register fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/user/update")
|
||||||
|
public ServerResponseEntity<Boolean> updatePassword(@RequestBody PasswordData passwordData) {
|
||||||
|
logger.info("request passwordData: {}",passwordData);
|
||||||
|
if(passwordData != null){
|
||||||
|
boolean isSuccess = userService.updateUserPasswordByUserId(passwordData);
|
||||||
|
if (isSuccess) {
|
||||||
|
return ServerResponseEntity.success(true);
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("update password fail");
|
||||||
|
}
|
||||||
|
return ServerResponseEntity.fail("data error");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/logout")
|
||||||
|
public ServerResponseEntity<Boolean> logout(HttpSession session) {
|
||||||
|
try {
|
||||||
|
session.removeAttribute("user");
|
||||||
|
return ServerResponseEntity.success(true);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("server error", e);
|
||||||
|
return ServerResponseEntity.fail("server error");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main/java/com/gao/finalhw/model/PasswordData.java
Normal file
10
src/main/java/com/gao/finalhw/model/PasswordData.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package com.gao.finalhw.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PasswordData {
|
||||||
|
private String userId;
|
||||||
|
private String newPassword;
|
||||||
|
private String oldPassword;
|
||||||
|
}
|
||||||
17
src/main/java/com/gao/finalhw/service/AddrService.java
Normal file
17
src/main/java/com/gao/finalhw/service/AddrService.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.gao.finalhw.service;
|
||||||
|
|
||||||
|
import com.gao.finalhw.mapper.AddressMapper;
|
||||||
|
import com.gao.finalhw.model.Address;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AddrService {
|
||||||
|
@Autowired
|
||||||
|
AddressMapper addressMapper;
|
||||||
|
|
||||||
|
public Address getAddrById(int id) {
|
||||||
|
Address result = addressMapper.selectById(id);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/main/java/com/gao/finalhw/service/CartService.java
Normal file
17
src/main/java/com/gao/finalhw/service/CartService.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.gao.finalhw.service;
|
||||||
|
|
||||||
|
import com.gao.finalhw.mapper.ShoppingCartMapper;
|
||||||
|
import com.gao.finalhw.model.ShoppingCart;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CartService {
|
||||||
|
@Autowired
|
||||||
|
ShoppingCartMapper shoppingCartMapper;
|
||||||
|
public int getCartCount(int id){
|
||||||
|
ShoppingCart result = shoppingCartMapper.selectById(id);
|
||||||
|
return result.getCartId();
|
||||||
|
}
|
||||||
|
}
|
||||||
53
src/main/java/com/gao/finalhw/service/OrderService.java
Normal file
53
src/main/java/com/gao/finalhw/service/OrderService.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package com.gao.finalhw.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.gao.finalhw.mapper.OrdersMapper;
|
||||||
|
import com.gao.finalhw.model.Orders;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OrderService {
|
||||||
|
@Autowired
|
||||||
|
OrdersMapper ordersMapper;
|
||||||
|
|
||||||
|
public Orders getOrderInfo(int orderId) {
|
||||||
|
Orders orderInfo = ordersMapper.selectById(orderId);
|
||||||
|
return orderInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Orders getOrderInfoByUserId(int userId) {
|
||||||
|
QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("user_id", userId);
|
||||||
|
|
||||||
|
return ordersMapper.selectOne(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addOrder(Orders orders) {
|
||||||
|
int result = ordersMapper.insert(orders);
|
||||||
|
return result > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean updateOrder(Orders orders) {
|
||||||
|
|
||||||
|
UpdateWrapper<Orders> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("user_id", orders.getUserId());
|
||||||
|
|
||||||
|
return ordersMapper.update(orders, updateWrapper) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteById(Orders orders) {
|
||||||
|
QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("id", orders.getOrderId());
|
||||||
|
return ordersMapper.delete(queryWrapper) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteByUserId(Orders orders) {
|
||||||
|
QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("user_id", orders.getUserId());
|
||||||
|
return ordersMapper.delete(queryWrapper) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
28
src/main/java/com/gao/finalhw/service/UserInfoService.java
Normal file
28
src/main/java/com/gao/finalhw/service/UserInfoService.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package com.gao.finalhw.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.gao.finalhw.controller.UserController;
|
||||||
|
import com.gao.finalhw.mapper.UserInfoMapper;
|
||||||
|
import com.gao.finalhw.model.Orders;
|
||||||
|
import com.gao.finalhw.model.UserInfo;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserInfoService {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(UserInfoService.class);
|
||||||
|
@Autowired
|
||||||
|
UserInfoMapper userInfoMapper;
|
||||||
|
|
||||||
|
public UserInfo getUserInfo(int id){
|
||||||
|
logger.info("id: {}",id);
|
||||||
|
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("user_id", id);
|
||||||
|
UserInfo result = userInfoMapper.selectOne(queryWrapper);
|
||||||
|
logger.info("select user info result: {}",result);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.gao.finalhw.service;
|
package com.gao.finalhw.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.gao.finalhw.mapper.UserMapper;
|
import com.gao.finalhw.mapper.UserMapper;
|
||||||
|
import com.gao.finalhw.model.PasswordData;
|
||||||
import com.gao.finalhw.model.User;
|
import com.gao.finalhw.model.User;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -22,7 +24,36 @@ public class UserService {
|
|||||||
.eq("password", password); // 假设字段名为 'password'
|
.eq("password", password); // 假设字段名为 'password'
|
||||||
|
|
||||||
User result = userMapper.selectOne(wrapper);
|
User result = userMapper.selectOne(wrapper);
|
||||||
logger.info("query result: {}",result.toString());
|
logger.info("query result: {}", result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean register(User user) {
|
||||||
|
int result = userMapper.insert(user);
|
||||||
|
return result > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean updateUserPasswordByUserId(PasswordData passwordData) {
|
||||||
|
String currentPassword = queryPasswordByUserId(passwordData.getUserId());
|
||||||
|
logger.info("currentPassword: {}, oldPassword: {}.",currentPassword,passwordData.getOldPassword());
|
||||||
|
if (currentPassword.equals(passwordData.getOldPassword())) {
|
||||||
|
logger.info("start update password.");
|
||||||
|
UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("user_id", passwordData.getUserId())
|
||||||
|
.set("password", passwordData.getNewPassword());
|
||||||
|
|
||||||
|
return userMapper.update(null, updateWrapper) > 0;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String queryPasswordByUserId(String userId) {
|
||||||
|
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.select("password").eq("user_id", userId);
|
||||||
|
|
||||||
|
User user = userMapper.selectOne(queryWrapper);
|
||||||
|
return user != null ? user.getPassword() : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,9 +52,7 @@
|
|||||||
|
|
||||||
function toPay() {
|
function toPay() {
|
||||||
var nu = '1';
|
var nu = '1';
|
||||||
|
window.location = "/cart_agreement";
|
||||||
window.location = "cart_agreement.html";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<!--内容-->
|
<!--内容-->
|
||||||
|
|||||||
@@ -58,12 +58,14 @@
|
|||||||
var nu = '1';
|
var nu = '1';
|
||||||
|
|
||||||
if (check()) {
|
if (check()) {
|
||||||
$("#aspnetForm").submit();
|
// $("#aspnetForm").submit();
|
||||||
|
window.location.href = "/cart_order";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$(function() {
|
$(function() {
|
||||||
$("#aspnetForm").attr("action", "/cart_order");
|
$("#aspnetForm").attr("action", "/cart_order");
|
||||||
|
// window.location.href = "/cart_order";
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<!--真爱协议中的内容-->
|
<!--真爱协议中的内容-->
|
||||||
|
|||||||
@@ -179,15 +179,16 @@
|
|||||||
//check
|
//check
|
||||||
if ($(".shop_adress-top:not(:last) :radio:checked").length == 0) {
|
if ($(".shop_adress-top:not(:last) :radio:checked").length == 0) {
|
||||||
alert("请先选择一个地址。");
|
alert("请先选择一个地址。");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
var nu = '1';
|
var nu = '1';
|
||||||
|
|
||||||
$("#aspnetForm").submit();
|
// $("#aspnetForm").submit();
|
||||||
|
window.location.href = "/cart_order_success";
|
||||||
|
|
||||||
}
|
}
|
||||||
$(function() {
|
$(function() {
|
||||||
$("#aspnetForm").attr("action", "/cart_order_success");
|
// window.location.href = "/cart_order_success";
|
||||||
|
// $("#aspnetForm").attr("action", "/cart_order_success");
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<!--内容-->
|
<!--内容-->
|
||||||
|
|||||||
@@ -30,7 +30,8 @@
|
|||||||
<div id="ucheader1_pllogin1">
|
<div id="ucheader1_pllogin1">
|
||||||
<li><a rel="nofollow" href="/login">登录</a><em>|</em></li>
|
<li><a rel="nofollow" href="/login">登录</a><em>|</em></li>
|
||||||
<li><a rel="nofollow" href="/reg">注册</a></li>
|
<li><a rel="nofollow" href="/reg">注册</a></li>
|
||||||
<li class="headed"><em class="icon shooping"></em><a target="black" rel="nofollow" href="/cart">购物车</a><i>(0)</i>
|
<li class="headed"><em class="icon shooping"></em><a target="black" rel="nofollow"
|
||||||
|
href="/cart">购物车</a><i>(0)</i>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -643,6 +644,12 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<script th:inline="javascript">
|
||||||
|
/*<![CDATA[*/
|
||||||
|
var isUserLoggedIn = [[${session.user != null}]];
|
||||||
|
console.log("isUserLoggedIn: " + isUserLoggedIn);
|
||||||
|
/*]]>*/
|
||||||
|
</script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function showMask() {
|
function showMask() {
|
||||||
$("#masks").css("height", $(document).height());
|
$("#masks").css("height", $(document).height());
|
||||||
@@ -665,6 +672,51 @@
|
|||||||
$("#masks").fadeOut("slow");
|
$("#masks").fadeOut("slow");
|
||||||
$("#mask").fadeOut("slow");
|
$("#mask").fadeOut("slow");
|
||||||
}
|
}
|
||||||
|
function getCartCountFromSession() {
|
||||||
|
var cartCount = 0;
|
||||||
|
|
||||||
|
var userId = getCookie('user_id');
|
||||||
|
console.log("user id: " + userId)
|
||||||
|
if (userId == null){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/get_cart_count',
|
||||||
|
type: 'GET',
|
||||||
|
data: { userId: userId },
|
||||||
|
success: function(response) {
|
||||||
|
var cartCount = response.cartCount;
|
||||||
|
console.log("购物车数量: " + cartCount);
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error("Error fetching cart count:", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cartCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
if (isUserLoggedIn) {
|
||||||
|
var userName = getUserFromSession();
|
||||||
|
var cartCount = getCartCountFromSession();
|
||||||
|
|
||||||
|
$('#ucheader1_pllogin1').hide();
|
||||||
|
$('#ctl00_ucheader_lit').text('你好!' + userName);
|
||||||
|
$('.shopping-cart-count').text(cartCount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getCookie(name) {
|
||||||
|
var cookies = document.cookie.split(';');
|
||||||
|
for(var i = 0; i < cookies.length; i++) {
|
||||||
|
var cookie = cookies[i].trim();
|
||||||
|
var cookieParts = cookie.split('=');
|
||||||
|
if (cookieParts[0] === name) {
|
||||||
|
return cookieParts[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -137,12 +137,18 @@
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
data: JSON.stringify({username: email, password: password}),
|
data: JSON.stringify({username: email, password: password}),
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
// 处理响应
|
if (response.code === "0" && response.msg === 'ok') {
|
||||||
console.log(response);
|
window.location.href = '/index'; // 确保这是正确的重定向 URL
|
||||||
|
} else {
|
||||||
|
alert("账号或密码错误");
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.href = '/login';
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
// 处理错误
|
window.location.href = '/error';
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -152,6 +158,11 @@
|
|||||||
$('#login span').eq(1).click();
|
$('#login span').eq(1).click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('.left').click(function() {
|
||||||
|
window.location.href = '/reg'; // 将 '/register' 替换为您的注册页面 URL
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<div class="head clearfix">
|
<div class="head clearfix">
|
||||||
<!--头部左边-->
|
<!--头部左边-->
|
||||||
<div class="topLeft left">
|
<div class="topLeft left">
|
||||||
<a href="index.html" title="Darry Ring">
|
<a href="/index" title="Darry Ring">
|
||||||
<img width="186" height="42" src="../images/logo_01.png ">
|
<img width="186" height="42" src="../images/logo_01.png ">
|
||||||
</a>
|
</a>
|
||||||
<span>求婚钻戒领导品牌</span>
|
<span>求婚钻戒领导品牌</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user