📄 getprosql.java
字号:
package com.tb.log.util.tools;
public class GetProSql {
String getSql = "";
String sql = "";
String getCateGory = "";
String getState = "";
String getEndDate = "";
String getStartDate = "";
String getProName = "";
public String toSql(String pro_category,String start_date,String end_date,String pro_state,String pro_name){
if(pro_category == null||pro_category.equals("")){
getCateGory = "";
}else {
getCateGory = " pro_category='"+pro_category+"' and";
}
if(start_date ==null || start_date.equals("")){
getStartDate = "";
}else{
getStartDate = " start_date>='"+start_date+"' and";
}
if(end_date ==null || end_date.equals("")){
getEndDate = "";
}else{
getEndDate = " start_date<='"+end_date+"' and";
}
if(pro_state ==null || pro_state.equals("")){
getState = "";
}else{
getState = " pro_state like '%"+pro_state+"%' and";
}
if(pro_name ==null || pro_name.equals("")){
getProName = "";
}else{
getProName = " pro_name like '%"+pro_name+"%'";
}
sql = getCateGory+getState+getStartDate+getEndDate+getProName;
if(sql==null||sql.equals("")){
getSql = "select * from (select row_.*, rownum rownum_ from (select * from t_project ) row_ where rownum <=?) where rownum_ >?";
}else{
//如果sql最后一个字符是","号将它去掉
if(sql.substring(sql.length()-4,sql.length()).equals(" and")){
sql = sql.substring(0,sql.length()-4);
}
getSql = "select * from (select row_.*, rownum rownum_ from (select * from t_project where"+sql+") row_ where rownum <=?) where rownum_ >?";
}
return getSql;
}
public String getSql(String pro_category,String start_date,String end_date,String pro_state,String pro_name){
if(pro_category == null || pro_category.equals("")){
getCateGory = "";
}else {
getCateGory = " pro_category='"+pro_category+"' and";
}
if(start_date ==null || start_date.equals("")){
getStartDate = "";
}else{
getStartDate = " start_date >='"+start_date+"' and";
}
if(end_date ==null || end_date.equals("")){
getEndDate = "";
}else{
getEndDate = " start_date<='"+end_date+"' and";
}
if(pro_state ==null || pro_state.equals("")){
getState = "";
}else{
getState = " pro_state like '%"+pro_state+"%' and";
}
if(pro_name ==null || pro_name.equals("")){
getProName = "";
}else{
getProName = " pro_name like '%"+pro_name+"%'";
}
sql = getCateGory+getState+getStartDate+getProName;
if(sql==null||sql.equals("")){
sql = "select count(*) from t_project ";
}else{
sql = "select count(*) from t_project where "+getCateGory+getEndDate+getState+getStartDate+getProName;
//如果sql最后一个字符是","号将它去掉
if(sql.substring(sql.length()-4,sql.length()).equals(" and")){
sql = sql.substring(0,sql.length()-4);
}
}
return sql;
}
public static void main(String[] args) {
//FindByConSql getsql = new FindByConSql();
String pro_category = "";
String start_date = "2008-01-01";
String end_date = "2009-01-01";
String pro_state = "kdl" ;
String pro_name = null;
//System.out.println(getsql.toSql(pro_category, start_date, end_date, pro_state, pro_name));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -