zmd50 5 years ago
parent 5dcf891496
commit 54ba911a01

@ -0,0 +1,72 @@
package com.book.demo.controller;
import com.book.demo.entity.Order;
import com.book.demo.mapper.CartMapper;
import com.book.demo.mapper.OrderMapper;
import com.book.demo.services.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
@Controller
@Repository
public class OrderController {
@Autowired
private OrderMapper orderMapper;
@Autowired
private CartMapper cartMapper;
@Autowired
private Result res;
//获取用户订单
@ResponseBody
@GetMapping("/getOrder")
public Result getOrderbyName(@RequestParam("username")String username){
Order []orders=orderMapper.getOrderByName("username");
if(orders.length>0){
res.setCode(0);
res.setMsg("获取成功");
res.data.clear();
for (Order order : orders) {
res.data.add(order);
}
}
else{
res.setCode(-1);
res.setMsg("暂无订单");
res.data=null;
}
return res;
}
//更新订单
//生成订单>>主键设为自增state默认设为0
@ResponseBody
@GetMapping("/createOrder")
public Result createOrder(@RequestParam("username")String username){
Date date=new Date();
int state=orderMapper.createOrder(username,date);
if(state>0){
res.setCode(0);
res.setMsg("生成订单成功");
cartMapper.clearCart(username);
}
else{
res.setCode(-1);
res.setMsg("生成订单失败");
}
res.data=null;
return res;
}
//删除订单
}

@ -1,5 +1,13 @@
package com.book.demo.entity;
public class Order {
import lombok.Data;
import java.util.Date;
@Data
public class Order {
String id;
String username;
Date ortime;
int state;
}

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