customerserviceimp.java

来自「SSH经典练习」· Java 代码 · 共 55 行

JAVA
55
字号
package com.ghy.service;

import java.util.Collection;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ghy.data.Address;
import com.ghy.data.Customer;
import com.ghy.form.CustomerForm;

public class CustomerServiceImp extends HibernateDaoSupport  implements CustomerService{

	public void deleteCustomer(String customer_id) throws DataAccessException {
		// TODO 自动生成方法存根
		this.getHibernateTemplate().delete(this.getSession().get(Customer.class, customer_id));
	}
	public Collection findAllCustomers() throws DataAccessException {
		// TODO 自动生成方法存根
		String query="from Customer as c order by c.name asc";
	      List customers=this.getHibernateTemplate().find(query);
	      return customers;
	}

	public Customer findCustomer(String customer_id) throws DataAccessException {
		// TODO 自动生成方法存根
		Customer customer =(Customer)this.getHibernateTemplate().get(Customer.class, customer_id);
		return customer;
	}

	public void saveCustomer(CustomerForm customerForm) throws DataAccessException {
		// TODO 自动生成方法存根
		String customerName = (String)customerForm.getCustomerName();
	    String homeProvince = (String)customerForm.getHomeProvince();
	    String homeCity = (String)customerForm.getHomeCity();
	    String homeStreet = (String)customerForm.getHomeStreet();
	    String homeZipcode = (String)customerForm.getHomeZipcode();
	    String comProvince = (String)customerForm.getComProvince();
	    String comCity = (String)customerForm.getComCity();
	    String comStreet = (String)customerForm.getComStreet();
	    String comZipcode = (String)customerForm.getComZipcode();
	    Customer customer=new Customer();
	      Address homeAddress=new Address(homeProvince,homeCity,homeStreet,homeZipcode,customer);
	      Address comAddress=new Address(comProvince,comCity,comStreet,comZipcode,customer);
	      customer.setName(customerName);
	      customer.setHomeAddress(homeAddress);
	      customer.setComAddress(comAddress);
	      this.getHibernateTemplate().save(customer);
		
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?