今天老师讲了ArrayList<>所以,利用这点时间做个记录吧。希望对于初学者有些帮助。
导入测试类:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 package com.sqldemo.Test; 2 3 import java.util.Scanner; 4 5 import com.sqldemo.StudentDao; 6 import Entity.Student; 7 public class TestDemo { 8 9 public static void main(String[] args) { 10 Student stu = new Student(); 11 System.out.println("--------本程序执行数据入库操作---------"); 12 Scanner sc = new Scanner(System.in); 13 System.out.print("学生姓名:"); 14 String stuName = sc.nextLine(); 15 stu.setName(stuName); 16 System.out.print("学生性别:"); 17 String stuSex = sc.nextLine(); 18 stu.setSex(stuSex); 19 System.out.print("学生年龄:"); 20 int stuAge= sc.nextInt(); 21 stu.setAge(stuAge); 22 sc.close(); 23 new StudentDao().AddStudent(stu); 24 } 25 }
导出测试类:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 package com.sqldemo.Test; 2 3 4 import java.util.List; 5 6 import Entity.Student; 7 8 import com.sqldemo.studentAcquire; 9 10 public class AcquireTestDemo { 11 12 public static void main(String[] args) { 13 14 List<Student> students = new studentAcquire().getStudent(); 15 System.out.println("| ID | Name | sex | age|"); 16 for(Student stu:students){ 17 System.out.print("| "); 18 System.out.print(stu.getId()); 19 System.out.print("| "); 20 System.out.print(stu.getName()); 21 System.out.print("| "); 22 System.out.print(stu.getSex()); 23 System.out.print("| "); 24 System.out.print(stu.getAge()); 25 System.out.println("|"); 26 } 27 System.out.println("打印完毕"); 28 } 29 }
具体代码点击下载