springboot整合mybatis,在不使用xml的情况下

1. script标签

@Select({""})
2、用Provider去实现SQL拼接,例如:

public class OrderProvider {
    private final String TBL_ORDER = "tbl_order";

    public String queryOrderByParam(OrderPara param) {
        SQL sql = new SQL().SELECT("*").FROM(TBL_ORDER);
        String room = param.getRoom();
        if (StringUtils.hasText(room)) {
            sql.WHERE("room LIKE #{room}");
        }
        Date myDate = param.getMyDate();
        if (myDate != null) {
            sql.WHERE("mydate LIKE #{mydate}");
        }
        return sql.toString();
    }
}

public interface OrderDAO {
    
    @SelectProvider(type = OrderProvider.class, method = "queryOrderByParam")
    List queryOrderByParam(OrderParam param);

}

转载于:https://my.oschina.net/u/3580626/blog/1842977

你可能感兴趣的:(springboot整合mybatis,在不使用xml的情况下)