QueryCondition.java 770 B

1234567891011121314151617181920212223
  1. package com.xjrsoft.module.form.entity;
  2. import lombok.Data;
  3. @Data
  4. public class QueryCondition {
  5. private String fieldName;
  6. private Object value;
  7. private String operator; // "=", ">=", "<=", "LIKE"等
  8. private boolean isDate;
  9. private int index; // 添加索引字段
  10. public String toSqlSnippet() {
  11. if (isDate && "BETWEEN".equals(operator)) {
  12. return String.format("%s BETWEEN #{conditions[%d].value[0]} AND #{conditions[%d].value[1]}",
  13. fieldName, index, index);
  14. }
  15. if ("LIKE".equals(operator)) {
  16. return String.format("%s LIKE #{conditions[%d].value}", fieldName, index);
  17. }
  18. return String.format("%s %s #{conditions[%d].value}", fieldName, operator, index);
  19. }
  20. }