package com.groups.ims.customers.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.struts.action.ActionForward;
import org.springframework.beans.factory.annotation.Autowired;
import com.groups.GroupsCustomSQLException;
import com.groups.GroupsCustomeException;
import com.groups.GroupsFormUtil;
import com.groups.ims.customers.dao.CustomerAddress;
import com.groups.ims.customers.dao.CustomerService;
import com.groups.ims.customers.form.CustomersForm;
public class ViewCustomersAddressDetailsAction extends CustomersAction
{
@Autowired
CustomerService customerService;
public ActionForward executeHibernateAction()
throws GroupsCustomeException, GroupsCustomSQLException, Exception
{
CustomersForm customersForm = (CustomersForm) form;
HashMap bean = null;
String customerSeq = customersForm.getSelectedId();
System.out.println("\n customerSeq : " +customerSeq);
customerSeq = nullToEmptyString(customerSeq);
if (customerSeq.length() == 0)
throw new GroupsCustomeException("error.details.no.record");
CustomerAddress bl = customerService.getCustomerAddress(customerSeq);
List<GroupsFormUtil> props = new ArrayList<GroupsFormUtil>();
props.add(new GroupsFormUtil("addressName", "addressName"));
props.add(new GroupsFormUtil("address1", "address1"));
props.add(new GroupsFormUtil("address2", "address2"));
props.add(new GroupsFormUtil("address3", "address3"));
props.add(new GroupsFormUtil("citySeq", "citySeq"));
props.add(new GroupsFormUtil("stateSeq", "stateSeq"));
props.add(new GroupsFormUtil("pincode", "pincode"));
beanToForm(customersForm, bl, props);
setDetailsSelectBoxLists(session, connection);
if (customersForm.getTabIDHtml().length() == 0)
{
customersForm.setTabIDHtml("customer_address");
}
session.setAttribute("CustomersForm", customersForm);
return mapping.findForward("viewDetails");
}
}
这是提交详情的行动
package com.groups.ims.customers.action;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts.action.ActionForward;
import org.springframework.beans.factory.annotation.Autowired;
import com.groups.GroupsCustomSQLException;
import com.groups.GroupsCustomeException;
import com.groups.GroupsFormUtil;
import com.groups.form.BeanValueFormatter;
import com.groups.form.DateValueFormatterImpl;
import com.groups.form.DateValueFormatterImpl.DATE_TYPE;
import com.groups.form.NumberValueFormatterImpl;
import com.groups.form.NumberValueFormatterImpl.NUMBER_TYPE;
import com.groups.ims.customers.dao.Customer;
import com.groups.ims.customers.dao.CustomerAddress;
import com.groups.ims.customers.dao.CustomerService;
import com.groups.ims.customers.dao.CustomerServiceImpl;
import com.groups.ims.customers.form.CustomersForm;
public class CustomersAddressDetailsSubmitAction extends CustomersAction
{
@Autowired
CustomerService customerService;
public ActionForward executeHibernateAction()
throws GroupsCustomeException, GroupsCustomSQLException, Exception
{
CustomersForm customersForm = (CustomersForm) form;
customerSeq = customersForm.getSelectedId();
CustomerAddress bl = customerService.getCustomerAddress(customerSeq);
List<GroupsFormUtil> props = new ArrayList<GroupsFormUtil>();
props.add(new GroupsFormUtil("addressName", "addressName"));
props.add(new GroupsFormUtil("address1", "address1"));
props.add(new GroupsFormUtil("address2", "address2"));
props.add(new GroupsFormUtil("address3", "address3"));
props.add(new GroupsFormUtil("citySeq", "citySeq"));
props.add(new GroupsFormUtil("stateSeq", "stateSeq"));
props.add(new GroupsFormUtil("pincode", "pincode"));
formToBean(customersForm, bl, props);
bl.updateCustomerAddress(userName,customerSeq);
return mapping.findForward("viewDetails");
}
}
我只是想更新记录而不在数据库中添加任何记录
我的意思是代替添加我想要更新空记录的记录
public void updateCustomerAddress(String user, String customerSeq) throws SQLException {
HashMap bean = new HashMap();
bean.put("cust_address_name", getAddressName());
bean.put("cust_address1", getAddress1());
bean.put("cust_address2", getAddress2());
bean.put("cust_address3", getAddress3());
bean.put("cust_city", getCitySeq());
bean.put("cust_state", getStateSeq());
bean.put("cust_pincode", getPincode());
bean.put(GroupsBaseAccess.TABLE_NAME, "customer_address");
bean.put("update_user", user);
bean.put("update_date", "now()");
bean.put("where", "customer_seq=" + customerSeq);
GroupsBaseAccess.update(bean, getConnection());
}
查询是:
String customerAddressQuery = "(select cust_addr_seq, cust_address_name, cust_address1, cust_address2, cust_address3, cust_city, cust_state, cust_pincode" +
" from customer_address where <customer_seq> )";