文章目录
注:本节是针对 订单表 的操作
1. 表结构分析
2. 订单-查询所有
2.1 思路分析
查询所有订单时,每一条订单内都有一个产品 Product ,一个产品可以对应多个订单。
所以 订单与产品是 多对一 关系。
2.2 OrdersController
@Controller
@RequestMapping(path = "/orders")
public class OrdersController {
@Autowired
private IOrdersService ordersService;
//未分页
@RequestMapping(path = "/findAll.do")
public ModelAndView findAll() throws Exception {
ModelAndView mv = new ModelAndView();
List<Orders> ordersList = ordersService.findAll();
mv.addObject("ordersList",ordersList);
mv.setViewName("orders-list");
for (Orders orders:ordersList){
System.out.println(orders);
}
return mv;
}
}
2.3 业务层 IOrdersService
public interface IOrdersService {
List<Orders> findAll() throws Exception;
}
@Service("orderService")
@Transactional
public class OrdersServiceImpl implements IOrdersService {
@Autowired
private IOrderDao orderDao;
@Override
public List<Orders> findAll() throws Exception {
return orderDao.findAll();
}
}
2.4 持久层 IOrderDao
订单表—产品表
多对一的多表查询,这里使用了 @One
注解
public interface IOrderDao {
@Select("select * from orders")
@Results({
@Result(id = true,property ="id",column = "id"),
@Result(property = "orderNum",column = "orderNum"),
@Result(property = "orderTime",column = "orderTime"),
@Result(property = "orderStatus",column = "orderStatus"),
@Result(property = "peopleCount",column = "peopleCount"),
@Result(property = "payType",column = "payType"),
@Result(property = "orderDesc",column = "orderDesc"),
@Result(property = "product",column = "productId",javaType = Product.class,one =