for循环里面不要有查询数据库操作

for循环里面不要有查询数据库操作,因为每次循环都查询数据库会浪费数据库资源,查询效率降低,可以放在for循环外面全部查询出来,再再for循环中进行循环对比获取数据

例:

 1 public class ForDemo01 {
 2 
 3     public static void main(String[] args) {
 4 
 5         //列表查询
 6         List<String> strList = this.mapper();
 7     // 使用for循环输出100次:好好学习,天天向上
 8         User user = new User();
 9     for(int i =0;i<=100;i++){
10 
11 if
12                  for(int j = 0;j<= strList.size();j++){
13 
14 
15             }
16             System.out.println("第"+i+"遍:好好学习,天天向上");
17 
18         }
19 
20 
21         System.out.println("程序执行完毕");
22 
23     }

 

posted @ 2023-08-22 12:09  贩卖长江水  阅读(285)  评论(0编辑  收藏  举报