JSP第九周作业
1.做一个图书类Book id,name,price ,get,set访问器,构造方法2个,1个无参,1个有参做一个测试类,在main中创建3个图书对象,放到list集合中。做一个菜单,可以添加,删除,修改,查询
package com.cn; import java.util.ArrayList; import java.util.List; public class books { private String id; private String name; private double price; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public books(String id, String name, double price) { super(); this.id = id; this.name = name; this.price = price; } }
package com.cn; public class booksbest { public static void main(String[] args) { // TODO Auto-generated method stub books b1=new books("a","aa",10); books b2=new books("b","bb",20); books b3=new books("c","cc",30); books b4=new books("d","dd",40); books b=new books(); b.add(b1); b.add(b2); b.add(b3); b.showAll(); b.set(b4, 0); System.out.println("=============="); b.showAll(); System.out.println("=============="); b.remove(b4); b.showAll(); } }
2.上题的类,在一个JSP页面中,创建一个集合,里面放3个图书,集合循环遍历显示在页面上。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> </head> <%@ page import="books.book" %> <body> <% List<book> list=new ArrayList<book>(); book b1=new book(); b1.setId("a"); b1.setName("中华小当家"); b1.setPrice(10); book b2=new book(); b2.setId("b"); b2.setName("三国演义"); b2.setPrice(20); list.add(b1); list.add(b2); for(int i=0;i<list.size();i++){ out.print("ID:"+list.get(i).getId()+",NAME:"+list.get(i).getName()+",PRICE:"+list.get(i).getPrice()+"<br>"); } %> </body> </html>
3.在MySQL中创建Book表,里面id,name,price,
用命令实现,
添加一个图书,
根据名称删除图书,
把所有名称是“我”开头的图书删除,
删除全部图书,
把20元以上的图书价格都修改为18.8,
查看全部图书,
查看价格高于10块钱的全部图书