⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customerserviceimp.java

📁 SSH经典练习
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -