All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.table.model.Sql Maven / Gradle / Ivy

There is a newer version: 1.4.8
Show newest version
package com.litongjava.table.model;

import java.util.List;

import com.litongjava.table.constants.SqlTemplateConstants;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created by [email protected] on 2023/6/8_17:38
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Sql {
  private String columns = "*";
  private String tableName;
  private StringBuffer where = new StringBuffer();
  private List params;

  public Sql(StringBuffer where, List params) {
    this.where = where;
    this.params = params;
  }

  public void setColumns(String columns) {
    if (columns != null) {
      this.columns = columns;
    }
  }

  public String getsql() {
    // 拼接sql语句
    StringBuffer sql = new StringBuffer();
    String format = String.format(SqlTemplateConstants.SELECT_COLUMNS_FROM, columns, tableName);
    sql.append(format);
    sql.append(" " + where.toString());
    return sql.toString();
  }

  public String getSqlExceptSelect() {
    return "from " + tableName + " " + where.toString();
  }

  public String getSelectColumns() {
    return "select " + columns;
  }
}