📄 searchaction.java
字号:
package product.action;
import product.db.*;
import product.form.*;
import java.sql.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.actions.DispatchAction;
import java.text.DecimalFormat;
public class searchAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
{
PageForm pageBean = (PageForm)form;
String value=request.getParameter("value");
String search=request.getParameter("search");
Connection con = null;
try{
con=DatabaseConnection.getConnection();
Statement st = con.createStatement();
String q1 = "SELECT COUNT(*) AS total FROM Product where "+search+" like '%"+value+"%'";
ResultSet rs1 = st.executeQuery(q1);
int total = 0;
if(rs1.next()){
total = rs1.getInt("total");
}
pageBean.setMaxRowCount(total);
pageBean.setMaxPage();
int num = pageBean.getRowsPerPage();
int start = (pageBean.getCurPage()-1)*num;
String q2="SELECT * FROM Product where "+search+" like '%"+value+"%' ORDER BY createDay DESC LIMIT "+start+","+num;
ResultSet rs2 = st.executeQuery(q2);
Vector v = new Vector();
Node node;
java.text.DecimalFormat df=new DecimalFormat("##.0");
while(rs2.next()){
node = new Node();
node.setId(rs2.getInt("id"));
node.setName(rs2.getString("name").replace(" "," "));
node.setParent(rs2.getInt("parent"));
node.setSize(rs2.getString("size"));
node.setUnit(rs2.getString("unit"));
node.setContent(rs2.getString("content"));
node.setProduct_factory(rs2.getString("product_factory"));
node.setProduct_supply(rs2.getString("product_supply"));
node.setColor(rs2.getString("color"));
node.setPrice_in(rs2.getFloat("price_in"));
node.setPrice_agent(rs2.getFloat("price_agent"));
node.setPrice_sale(rs2.getFloat("price_sale"));
node.setPrice_detail(rs2.getFloat("price_detail"));
node.setSpecification(rs2.getString("specification"));
node.setNote(rs2.getString("note"));
node.setCreateDay(rs2.getDate("createDay"));
node.setLayer(rs2.getInt("layer"));
node.setNextId(rs2.getInt("nextId"));
if(Float.compare(rs2.getFloat("price_detail"),0.0f)!=0&&Float.compare(rs2.getFloat("price_in"),0.0f)!=0)
{
float t=(100*(rs2.getFloat("price_detail")-rs2.getFloat("price_in"))/rs2.getFloat("price_in"));
String temp=df.format(t)+"%";
//System.out.println("temp===="+temp);
node.setTemp(temp);
}else{
node.setTemp("");
}
if(Float.compare(rs2.getFloat("price_agent"),0.0f)!=0&&Float.compare(rs2.getFloat("price_in"),0.0f)!=0)
{
float t1=(100*(rs2.getFloat("price_agent")-rs2.getFloat("price_in"))/rs2.getFloat("price_in"));
String temp1=df.format(t1)+"%";
//System.out.println("temp===="+temp);
node.setTemp1(temp1);
}else{
node.setTemp1("");
}
if(Float.compare(rs2.getFloat("price_sale"),0.0f)!=0&&Float.compare(rs2.getFloat("price_in"),0.0f)!=0)
{
float t2=(100*(rs2.getFloat("price_sale")-rs2.getFloat("price_in"))/rs2.getFloat("price_in"));
String temp2=df.format(t2)+"%";
//System.out.println("temp===="+temp);
node.setTemp2(temp2);
}else{
node.setTemp2("");
}
v.add(node);
}
pageBean.setData(v);
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e2){}
}
return mapping.findForward("search");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -