public void display() { System.out.println("Name : " + student.getName()); System.out.println("Age : " + student.getAge()); System.out.println("Hobby : " + student.getHobby()); System.out.println("height : " + student.getHeight()); System.out.println("weight : " + student.getWeight()); }
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("StoredProcedureBeans.xml"); StudentJDBCTemplate studentJDBCTemplate = (StudentJDBCTemplate) context.getBean("studentJDBCTemplate"); System.out.println("------Records Creation--------"); studentJDBCTemplate.create("Zara", 11); studentJDBCTemplate.create("Nuha", 2); studentJDBCTemplate.create("Ayan", 15); System.out.println("------Listing Multiple Records--------"); List<Student> students = studentJDBCTemplate.listStudents(); for (Student record : students) { System.out.print("ID : " + record.getId()); System.out.print(", Name : " + record.getName()); System.out.println(", Age : " + record.getAge()); } System.out.println("----Listing Record with ID = 2 -----"); Student student = studentJDBCTemplate.getStudent(2); System.out.print("ID : " + student.getId()); System.out.print(", Name : " + student.getName()); System.out.println(", Age : " + student.getAge()); }
private boolean existsInGroup(Student st) { boolean result = false; for (Student grStudent : this.students) { if (grStudent != null) { if (grStudent.getSirname().equals(st.getSirname()) && grStudent.getName().equals(st.getName()) && grStudent.getGender() == st.getGender() && grStudent.getAge() == st.getAge()) { result = true; } } } return result; }
public void Show() { for (Student temp : student) { System.out.println("First Name:" + temp.getFName() + "\tLast Name :" + temp.getLName()); System.out.println("Age is :" + temp.getAge()); System.out.println("College :" + temp.getCollege()); } }
@RequestMapping(value = "/addStudent", method = RequestMethod.POST) public String addStudent(@ModelAttribute("SpringWeb") Student student, ModelMap model) { model.addAttribute("name", student.getName()); model.addAttribute("age", student.getAge()); model.addAttribute("id", student.getId()); return "result"; }
@SuppressWarnings("resource") public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext("annotationrequiredspring.xml"); Student student = (Student) context.getBean("student"); System.out.println("Name : " + student.getName()); System.out.println("Age : " + student.getAge()); }
/** 示例业务方法,用来测试 */ public void accessStudent() { // 获取当前线程的名字 String currentThreadName = Thread.currentThread().getName(); System.out.println(currentThreadName + " is running!"); // 产生一个随机数并打印 Random random = new Random(); int age = random.nextInt(100); System.out.println("thread " + currentThreadName + " set age to:" + age); // 获取一个Student对象,并将随机数年龄插入到对象属性中 Student student = getStudent(); student.setAge(age); System.out.println("thread " + currentThreadName + " first read age is:" + student.getAge()); try { Thread.sleep(500); } catch (InterruptedException ex) { ex.printStackTrace(); } System.out.println("thread " + currentThreadName + " second read age is:" + student.getAge()); }
public synchronized boolean equals(java.lang.Object obj) { if (!(obj instanceof Student)) return false; Student other = (Student) obj; if (obj == null) return false; if (this == obj) return true; if (__equalsCalc != null) { return (__equalsCalc == obj); } __equalsCalc = obj; boolean _equals; _equals = true && ((this.age == null && other.getAge() == null) || (this.age != null && this.age.equals(other.getAge()))) && ((this.id == null && other.getId() == null) || (this.id != null && this.id.equals(other.getId()))) && ((this.name == null && other.getName() == null) || (this.name != null && this.name.equals(other.getName()))); __equalsCalc = null; return _equals; }
public static void main(String[] args) { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("Beans.xml"); Student student = ctx.getBean(Student.class); System.out.println("Name: " + student.getName()); System.out.println("Age: " + student.getAge()); System.out.println("Message: " + student.getMessage()); // AnnotationConfigApplicationContext context = // new AnnotationConfigApplicationContext(); // context.register(HelloWorldConfiguration.class); // context.refresh(); // // HelloWorld helloWorld = context.getBean(HelloWorld.class); // helloWorld.setMessage("Hello World!"); // helloWorld.getMessage(); }
@Override public View getView(final int position, View convertView, ViewGroup parent) { /*每开一个新的student,就会重新跑一次这个方法*/ final Student student = getItem(position); ViewHolder viewholder; if (convertView == null) { /*convertView : 将之前加载好的布局,控件等等进行缓存,以便之后可以重用*/ convertView = LayoutInflater.from(getContext()) .inflate(resourceId, null); /*加载list的布局*/ /*将一个XML的格式转化成了一个view的我们能用的格式*/ viewholder = new ViewHolder(); viewholder.studentAge = (TextView) convertView.findViewById(R.id.student_age); viewholder.studentGrade = (TextView) convertView.findViewById(R.id.student_grade); viewholder.studentName = (TextView) convertView.findViewById(R.id.student_name); /*这样就只用找一次控件的位置了*/ convertView.setTag(viewholder); } else { viewholder = (ViewHolder) convertView.getTag(); /*将上次找到的控件的位置给这次的对象*/ } viewholder.studentName.setText(student.getName()); /*这里将得到的值给XML让它显示*/ viewholder.studentAge.setText(student.getAge() + ""); /*setView set的是一个字符串,如果要用数就得加""*/ viewholder.studentGrade.setText(student.getGrade() + ""); /*这里通过viewholder来存储,调用XML中的控件*/ convertView.setOnClickListener( new View.OnClickListener() { /*这里就代表我正在操作的position,可以直接在这里设置监听器*/ @Override /*一般来说,TextView跳转的界面都是同一个Activity*/ public void onClick(View v) { String data = "正在跳转"; /* Toast.makeText(StudentAdapter.this, data , Toast...)这样子用是错的,因为这里的Adapter不是个Activity,他只是个类,没有上下文。*/ Toast.makeText(getContext(), data, Toast.LENGTH_SHORT) .show(); /*Adapter不是context,getcontext得到的Activity才是context*/ Intent intent = new Intent(getContext(), Student1.class); /*每一个getContext()就是一个单独的活动 暂时这么理解*/ intent.putExtra("name", student.getName()); getContext() .startActivity( intent); /*这里在使用startActivity的时候必须用getContext来调用,否则编译器不知道你是在哪个上下文启动了intent*/ } }); return convertView; }