mybatis 注解的方式怎么使用别名
1个回答
展开全部
1、用script标签包围,然后像xml语法一样书写
@Select({"<script>",
"SELECT * FROM tbl_order",
"WHERE 1=1",
"<when test='title!=null'>",
"AND mydate = #{mydate}",
"</when>",
"</script>"})
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<Order> queryOrderByParam(OrderParam param);
}
@Select({"<script>",
"SELECT * FROM tbl_order",
"WHERE 1=1",
"<when test='title!=null'>",
"AND mydate = #{mydate}",
"</when>",
"</script>"})
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<Order> queryOrderByParam(OrderParam param);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询