动态多条件mysql模糊查询

sql拼接函数:

 1     public static String Instructor_sql_whole_study(String[] val_ids,String[] val_values)
 2     {
 3         String sql="SELECT * from student_1_score where";
 4         for(int i=0;i<val_ids.length;i++)
 5         {
 6             sql+=Instructor_sql_study(sql,val_ids[i])+" like '%"+val_values[i]+"%'";
 7         }
 8         return sql;
 9     }
10     public static String Instructor_sql_study(String sql,String id)
11     {
12         String str="";
13         String and_str=" and ";
14         if(sh.getExpString("where$",sql).size()>0)
15         {
16             and_str=" ";
17         }
18         switch (id)
19         {
20             case "1":
21                 str=and_str+"name_student";break;
22             case "2":
23                 str=and_str+"name_course";break;
24             case "3":
25                 str=and_str+"credit";break;
26             case "4":
27                 str=and_str+"term";break;
28             case "5":
29                 str=and_str+"class";break;
30         }
31         return str;
32     }

 

posted @ 2021-05-02 18:39  博二爷  阅读(112)  评论(0编辑  收藏  举报