📄 mybookclass.java
字号:
/*
* Created on 2008-11-27
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package server.books;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.sql.*;
//引入ToJson类
import changeToJson.ToJson;
/**
* @author Owner
*调用readBooks方法
*/
public class MyBookClass {
/**
*
*/
public MyBookClass() {
super();
// TODO Auto-generated constructor stub
}
private HashMap[] book = new HashMap[10];//一次显示10本书
public final static String property[]={"name","id","author","publish","price","discount","PicURL"};
page page=new page();
operateDbBook op=new operateDbBook();
public final static String TABLE="Book";
private Integer wholePages;
final static int propertySize=7;
private String name;
private String id;
private String author;
private String publish;
private int price;
private float discount;
private int wholeResult;
public String readBooks(String sql,int instantpage)
//throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
{
try{
ResultSet rs=op.getRs(sql,instantpage);
int c=page.getContent();
int i = 0;
HashMap[] book_temp=new HashMap[10];
book=book_temp;
while(c>0&&rs.next()&& i<10)//一次显示10本书
{
c--;
HashMap temp = new HashMap();
for(int j = 0; j<propertySize; ++j){
temp.put(property[j],rs.getString(property[j]));
}
book[i++] = temp;
System.out.println(rs.getString("PicURL"));
}
}
catch(ClassNotFoundException e){System.out.print(e);}
catch(SQLException e){System.out.print(e);}
catch(InstantiationException e){System.out.print(e);}
catch(IllegalAccessException e){System.out.print(e);}
wholePages = new Integer(this.getWholeResult(sql));
Map bookJson = new HashMap();
bookJson.put("identifier","id");
bookJson.put("label","id");
bookJson.put("wholePage",wholePages.toString());
bookJson.put("books",book);
String Json = ToJson.toJson(bookJson);
//String Json = ToJson.toJson(book);
System.out.println(Json);
return Json;
}
public int getWholeResult(String sql)
//throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
{int i=0;
try
{i=page.getWholePage(sql);}
catch(ClassNotFoundException e){}
catch(SQLException e){}
catch(InstantiationException e){}
catch(IllegalAccessException e){}
return i;
}
/**
* @return
*/
public static String[] getProperty() {
return property;
}
/**
* @return
*/
public static int getPropertySize() {
return propertySize;
}
/**
* @return
*/
public static String getTABLE() {
return TABLE;
}
/**
* @return
*/
public HashMap[] getBook() {
return book;
}
/**
* @return
*/
public operateDbBook getOp() {
return op;
}
/**
* @return
*/
public page getPage() {
return page;
}
/**
* @return
*/
public Integer getWholePages() {
return wholePages;
}
/**
* @param maps
*/
public void setBook(HashMap[] maps) {
book = maps;
}
/**
* @param book
*/
public void setOp(operateDbBook book) {
op = book;
}
/**
* @param page
*/
public void setPage(page page) {
this.page = page;
}
/**
* @param integer
*/
public void setWholePages(Integer integer) {
wholePages = integer;
}
/**
* @return
*/
public String getAuthor() {
return author;
}
/**
* @return
*/
public float getDiscount() {
return discount;
}
/**
* @return
*/
public String getId() {
return id;
}
/**
* @return
*/
public String getName() {
return name;
}
/**
* @return
*/
public int getPrice() {
return price;
}
/**
* @return
*/
public String getPublish() {
return publish;
}
/**
* @param string
*/
public void setAuthor(String string) {
author = string;
}
/**
* @param f
*/
public void setDiscount(float f) {
discount = f;
}
/**
* @param string
*/
public void setId(String string) {
id = string;
}
/**
* @param string
*/
public void setName(String string) {
name = string;
}
/**
* @param i
*/
public void setPrice(int i) {
price = i;
}
/**
* @param string
*/
public void setPublish(String string) {
publish = string;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -