📄 addsortaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.hao2007.struts.action;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
import com.hao2007.struts.form.AddSortForm;
import com.hao2007.struts.db.DataStore;
import java.io.PrintWriter;
/**
* MyEclipse Struts Creation date: 03-21-2007
*
* XDoclet definition:
*
* @struts.action path="/addSort" name="addSortForm" input="/form/addSort.jsp"
* scope="request" validate="true"
* @struts.action-forward name="addFail" path="/admin/addSort.jsp"
* redirect="true"
* @struts.action-forward name="addSortSuccess" path="/admin/addSortSuccess.jsp"
* redirect="true"
*/
public class AddSortAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
ActionMessages messages = new ActionMessages();
AddSortForm addSortForm = (AddSortForm) form;// TODO Auto-generated
// method stub
int parent_id;
String new_sort_name = null;
parent_id = Integer.parseInt(addSortForm.getParent_id());
new_sort_name = (String) addSortForm.getNew_sort_name();
DataStore ds = DataStore.getInstance();
ds.beginTransaction();
try {
//
String sqlInsert = "insert into class(name,parent_id) values('"
+ new_sort_name + "','" + parent_id + "')";
ds.execute(sqlInsert);// �Զ�����
} catch (Exception e) {
e.printStackTrace();
}
ResultSet rs1 = null;
try {
//
String sqlSelect1 = "select * from class order by id desc";
rs1 = ds.read(sqlSelect1);
rs1.first(); // ȡ�õ�ǰ�����¼��id: rs1.getInt("id")
} catch (Exception e) {
e.printStackTrace();
}
// id:parent_id,��}�����parent_id==0��parent_id!=0
if (parent_id == 0) {
try {
// parent_id==0�����¼����ɲ���
String new_sort_path = "0," + rs1.getInt("id") + ",";
String sqlUpdate2 = "update class set sort_path='"
+ new_sort_path + "',sort_depth=1 where id='"
+ rs1.getInt("id") + "'";
ds.execute(sqlUpdate2);
} catch (Exception e) {
e.printStackTrace();
}
} else {
ResultSet rs3 = null;
try {
// parent_id!=0:
String sqlSelect3 = "select * from class where id=" + parent_id
+ "";
rs3 = ds.read(sqlSelect3);
rs3.first(); // ȡ�õ�ǰ��¼�ĸ���ķ���·��:rs3.getString("sort_path")�ͷ������:rs3.getInt("sort_depth")
String latest_sort_path = rs3.getString("sort_path")
+ rs1.getInt("id") + ","; // ���õ��ķ���·��
int latest_sort_depth = rs3.getInt("sort_depth") + 1; // ���õ��ķ������
String sqlUpdate2 = "update class set sort_path='"
+ latest_sort_path + "',sort_depth="
+ latest_sort_depth + " where id='" + rs1.getInt("id")
+ "'";
ds.execute(sqlUpdate2);
} catch (Exception e) {
e.printStackTrace();
}
}
ds.commitTransaction();
return (mapping.findForward("addSortSuccess"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -