📄 bakmusicaction.java
字号:
package hibernate;
import hibernate.iml.Bakmusic;
import hibernate.iml.BakmusicOperation;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import common.TextHandle;
import net.sf.hibernate.HibernateException;
public class BakmusicAction {
/** title property */
private String title;
/** detail property */
private String detail;
/** page property */
private String page;
/** accessory property */
private String accessory;
/** size property */
private Integer size;
/** sysdate property */
private String sysdate;
/** method property */
private String method;
/** id property */
private String id;
/** pagestr property */
private String pagestr;
/** condition property */
private String condition;
private int pageSize;
private final String strSQLOrder = " order by sysdate desc";
public boolean getHots(String path){
boolean returnCode = true;
String sqlString = " from Bakmusic";
sqlString += " order by orderCount desc,sysdate desc";
try {
BakmusicOperation opHandle = new BakmusicOperation();
opHandle.setPageSize(10);
List collection = (List)opHandle.getAll(sqlString,1,"");
//将文件存放在当前目录下
int i=0;
File oldFile = new File(path+"\\manager\\top10.htm");
if(oldFile.exists()) oldFile.delete();
oldFile.createNewFile();
PrintWriter myFile = new PrintWriter(new FileWriter(oldFile));
String tableHead = "<table width=\"178\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
String tableTail = "</table>";
String infoHead ="<tr><td width=\"6\"> </td><td><table width=\"172\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
infoHead += "<tr><td width=\"12\"><img src=\"images/allow.gif\" width=\"9\" height=\"9\"></td>";
String infoTail = "</tr></table></td></tr><tr><td> </td><td><table cellspacing=0 cellpadding=0 width=\"100%\" border=0>";
infoTail += "<tbody><tr><td bgcolor=#5D605C height=1></td></tr></tbody></table></td></tr>";
myFile.println(tableHead);
if(collection!=null){
Bakmusic object;
for(;i<collection.size();i++){
myFile.println(infoHead);
object = (Bakmusic) collection.get(i);
myFile.println("<td>"+TextHandle.limitStrLen(object.getTitle(),10)+"</td>");
myFile.println("<td width=\"20\" align=\"center\" style='cursor:hand'><img src=\"images/try.gif\" width=\"14\" height=\"12\" onclick=\"MM_openBrWindow('music_preview.jsp?id="+object.getId()+"','背景音乐试听','width=320,height=280')\"></td>");
myFile.println(infoTail);
}
}
while(i<10){
myFile.println(infoHead);
myFile.println("<td>排行榜信息位为空</td>");
myFile.println("<td width=\"20\"> </td>");
myFile.println(infoTail);
i++;
}
myFile.println(tableTail);
myFile.flush();
myFile.close();
//将文件复制到根目录下
java.io.File toFile = new java.io.File(path+"\\top10.htm");
FileInputStream fis = new FileInputStream(oldFile);
FileOutputStream fos = new FileOutputStream(toFile);
int bytesRead;
byte[] buf = new byte[4 * 1024]; // 4K buffer ---------
while ((bytesRead = fis.read(buf)) != -1) fos.write(buf, 0, bytesRead);
fos.close();
fis.close();
} catch (HibernateException e) {
returnCode = false;
e.printStackTrace();
} catch (IOException e) {
returnCode = false;
e.printStackTrace();
}
return returnCode;
}
public Collection getSelect(String url){
Collection collection = null;
String sqlString = " from Bakmusic";
if((condition!=null)&&(!condition.equals(""))&&(!condition.equalsIgnoreCase("null"))){
sqlString += " where title LIKE '%" + condition + "%'";
}
sqlString += strSQLOrder;
int Page = 1;
if((page!=null)&&(!page.equals(""))&&(!page.equalsIgnoreCase("null"))){
Page = Integer.parseInt(page);
}else page = "1";
Page = (Page<1)?1:Page;
try {
BakmusicOperation opHandle = new BakmusicOperation();
if("option_select.jsp".equals(url)) opHandle.setPageSize(10);
collection = opHandle.getAll(sqlString,Page,""+url+"?condition="+condition+"&page=");
pagestr = opHandle.getPageStr();
pageSize = opHandle.getPageSize();
} catch (HibernateException e) {
e.printStackTrace();
}
return collection;
}
public Collection getFirst(){
Collection collection = null;
String sqlString = " from Bakmusic";
sqlString += strSQLOrder;
try {
BakmusicOperation opHandle = new BakmusicOperation();
opHandle.setPageSize(8);
collection = opHandle.getAll(sqlString,1,"");
} catch (HibernateException e) {
e.printStackTrace();
}
return collection;
}
public Bakmusic getInfo(){
Bakmusic object = null;
try {
BakmusicOperation opHandle = new BakmusicOperation();
object = (Bakmusic)opHandle.getInfo(Bakmusic.class,id);
} catch (HibernateException e) {
e.printStackTrace();
}
return object;
}
public boolean insert(){
boolean returnCode = true;
if(isValid()){
Bakmusic object = new Bakmusic();
object.setAccessory(this.accessory);
object.setOrderCount(new Integer(0));
object.setSize(this.size);
object.setSysdate(new Date());
object.setTitle(this.title);
object.setDetail(this.detail);
try {
BakmusicOperation opHandle = new BakmusicOperation();
opHandle.insert(object);
} catch (HibernateException e) {
returnCode = false;
e.printStackTrace();
}
}else returnCode = false;
return returnCode;
}
public boolean delete(String path){
if( (id == null)||(id.equals(""))||(id.equals(" "))||(id.equals("null")) ) return false;
boolean returnCode = true;
try {
BakmusicOperation opHandle = new BakmusicOperation();
opHandle.delete(path,id);
} catch (HibernateException e) {
returnCode = false;
e.printStackTrace();
}
return returnCode;
}
private boolean isValid(){
boolean returnCode = true;
if( (title == null)||(title.equals(""))||(title.equals(" "))||(title.equals("null")) ) returnCode = false;
if( (accessory == null)||(accessory.equals(""))||(accessory.equals(" "))||(accessory.equals("null")) ) returnCode = false;
if( (detail == null)||(detail.equals(""))||(detail.equals(" "))||(detail.equals("null")) ) detail = "无说明";
return returnCode;
}
/**
* Returns the title.
* @return String
*/
public String getTitle() {
return title;
}
/**
* Set the title.
* @param title The title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Returns the detail.
* @return String
*/
public String getDetail() {
return detail;
}
/**
* Set the detail.
* @param detail The detail to set
*/
public void setDetail(String detail) {
this.detail = detail;
}
/**
* Returns the page.
* @return String
*/
public String getPage() {
return page;
}
/**
* Set the page.
* @param page The page to set
*/
public void setPage(String page) {
this.page = page;
}
/**
* Returns the accessory.
* @return String
*/
public String getAccessory() {
return accessory;
}
/**
* Set the accessory.
* @param accessory The accessory to set
*/
public void setAccessory(String accessory) {
this.accessory = accessory;
}
/**
* Returns the size.
* @return Integer
*/
public Integer getSize() {
return size;
}
/**
* Set the size.
* @param size The size to set
*/
public void setSize(Integer size) {
this.size = size;
}
/**
* Returns the sysdate.
* @return String
*/
public String getSysdate() {
return sysdate;
}
/**
* Set the sysdate.
* @param sysdate The sysdate to set
*/
public void setSysdate(String sysdate) {
this.sysdate = sysdate;
}
/**
* Returns the method.
* @return String
*/
public String getMethod() {
return method;
}
/**
* Set the method.
* @param method The method to set
*/
public void setMethod(String method) {
this.method = method;
}
/**
* Returns the id.
* @return String
*/
public String getId() {
return id;
}
/**
* Set the id.
* @param id The id to set
*/
public void setId(String id) {
this.id = id;
}
public String getPagestr() {
return pagestr;
}
public void setPagestr(String pagestr) {
this.pagestr = pagestr;
}
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -