《springboot实战》 第十章 整合Mybatis(注解)

前言

在Mapper方法上加注解,废弃xml配置方式

@Select
@Mapper
public interface OrderMapper {
    /**
     * 订单查询
     * @return
     */
    @Select("SELECT\n" +
            "\ta.id,\n" +
            "\ta.orderNo\n" +
            "FROM\n" +
            "\tgoods_order a")
    @Results(id="orderMap",value = {
            @Result(column = "id",property = "id",id = true),
            @Result(column = "orderNo",property = "orderNo"),
            @Result(column = "id",property = "listOrderDetail",
            many = @Many(select = "getOrderDetailByOrderId",fetchType = FetchType.LAZY))

    })
    List<Order> queryOrder();

    @Select("select id orderDetailId,order_id orderId,good_name goodName from goods_order_detail where id = #{orderId}")
    List<OrderDetail> getOrderDetailByOrderId(@Param("orderId") Integer orderId);
}


@Update("")
int updateByPrimaryKeySelective(Employee record);

参考:http://www.yanhongzhi.com/post/mybatis-annotation.html#toc-ba6

你可能感兴趣的:(springboot,mybatis,spring,boot,java)