目录
一、一对多关联关系
1、实体类
首先先用逆向生成工具生成t_hibernate_order、t_hibernate_order_item
这两张表对应的model与mapper
①Order
package com.chenchen.ssm.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
//t_hibernate_order
//相当于添加了set/get方法,同时添加tostring
//@NoArgsConstructor
//@AllArgsConstructor
@Data
public class Order {
private Integer orderId;
private String orderNo;
}
②OrderItem
package com.chenchen.ssm.model;
import lombok.Data;
import lombok.ToString;
@ToString
public class OrderItem {
private Integer orderItemId;
private Integer productId;
private Integer quantity;
private Integer oid;
public OrderItem(Integer orderItemId, Integer productId, Integer quantity, Integer oid) {
this.orderItemId = orderItemId;
this.productId = productId;
this.quantity = quantity;
this.oid = oid;
}
public OrderItem() {
super();
}
public Integer getOrderItemId() {
return orderItemId;
}
public void setOrderItemId(Integer orderItemId) {
this.orderItemId = orderItemId;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public Integer getOid() {
return oid;
}
public void setOid(Integer oid) {
this.oid = oid;
}
}
2、Biz层
①OrderBiz
package com.chenchen.ssm.biz;
import com.chenchen.ssm.model.Book;
import com.chenchen.ssm.model.BookVo;
import com.chenchen.ssm.model.Order;
import com.chenchen.ssm.model.vo.OrderVo;
import com.chen.ssm.util.PageBean;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface OrderBiz {
int deleteByPrimaryKey(Integer orderId);
int insert(Order record);
int insertSelective(Order record);
Order selectByPrimaryKe