zmd50 5 years ago
parent f218d9c3c9
commit bd8a678259

@ -5,9 +5,7 @@ import com.book.demo.mapper.BookMapper;
import com.book.demo.services.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
@Controller
public class BookController {
@ -74,4 +72,39 @@ public class BookController {
}
return res;
}
//添加型图书 图书表结构更改
@ResponseBody
@PostMapping("/addbook")
public Result addBook(@RequestBody Book book){
int state=bookMapper.Insert(book);
if(state>0){
res.setCode(0);
res.setMsg("添加成功");
}
else{
res.setCode(-1);
res.setMsg("添加失败");
}
res.data=null;
return res;
}
//图书管理,删除
@ResponseBody
@GetMapping("/deletebook")
public Result addBook(@RequestParam("bookname")String bookname){
int state=bookMapper.deleteByBookName(bookname);
if(state>0){
res.setCode(0);
res.setMsg("删除成功");
}
else{
res.setCode(-1);
res.setMsg("删除失败");
}
res.data=null;
return res;
}
}

@ -1,4 +1,55 @@
package com.book.demo.controller;
import com.book.demo.entity.Cart;
import com.book.demo.mapper.CartMapper;
import com.book.demo.services.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
public class CartController {
@Autowired
CartMapper cartMapper;
@Autowired
Result res;
//添加商品进购物车 id为isbn
@ResponseBody
@GetMapping("/addintocart")
public Result AddBookIn(@RequestParam("username")String username,@RequestParam("id") int id){
//把数量默认都设为1
int state=cartMapper.insertItem(username,id);
if(state>0){
res.setCode(0);
res.setMsg("添加成功");
}
else{
res.setCode(-1);
res.setMsg("添加失败");
}
res.data=null;
return res;
}
//清空购物车
@ResponseBody
@GetMapping("/clearCart")
public Result clearCart(@RequestParam("username")String username){
cartMapper.clearCart(username);
Cart cart=cartMapper.queryByName(username);
if(cart==null){
res.setCode(0);
res.setMsg("清空成功");
}
else{
res.setCode(-1);
res.setMsg("清空失败");
}
res.data=null;
return res;
}
}

@ -83,7 +83,7 @@ public class UserController {
return res;
}
//用户管理>删除用户
//用户管理>删除用户 注销账号
@ResponseBody
@GetMapping("/delete")
public Result DeleteUserByName(@RequestParam("username") String username) {

@ -4,13 +4,7 @@ import lombok.Data;
@Data
public class Book {
private String ISBN;
private String bookname;
private String author;
private String press;
private String classify;
private String description;
private int stock;
private float price;
private String kind;
}

@ -0,0 +1,11 @@
package com.book.demo.entity;
import lombok.Data;
@Data
public class Cart {
private String username;
private String bookname;
private float price;
private int count;
}

@ -0,0 +1,5 @@
package com.book.demo.entity;
public class Order {
}

@ -0,0 +1,9 @@
package com.book.demo.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Repository
@Mapper
public interface CartMapper {
}
Loading…
Cancel
Save