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

📄 modeldaoimp.java

📁 关于java的web编程
💻 JAVA
字号:
package dao;

import hibernate.Model;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class ModelDaoImp extends HibernateDaoSupport implements ModelDao{
	 private static final Log log=LogFactory.getLog(ModelDaoImp.class);
	public boolean deleteModel(Long id) {
	    Model model=(Model) this.getHibernateTemplate().load(Model.class, id);
		try{
			this.getHibernateTemplate().delete(model);
			return true;
		}catch(Exception e)
		{
			log.debug(e);
		}
		return false;
	}

	public boolean deleteModel(Model model) {
		try{
			this.getHibernateTemplate().delete(model);
			return true;
		}catch(Exception e)
		{
			log.debug(e);
		}
		return false;
	}

	public List<Model> findAllModel() {
		// TODO Auto-generated method stub
		String hql="from Model mode";
		try{
			List<Model> list=this.getHibernateTemplate().find(hql);
			return list;
		}catch(Exception e)
		{
			log.debug(e);
		}
		return null;
	}

	public List<Model> findByBrand(String brand_name) {
		// TODO Auto-generated method stub
		String hql="from Model model where model.brand.name=?";
		try{
			List<Model> list=this.getHibernateTemplate().find(hql,brand_name);
			return list;
		}catch(Exception e)
		{
			log.debug(e);
		}
		return null;
	}

	public Model findByModel(String model_name) {
		String hql="from Model model where model.name=?";
		try{
		List list=this.getHibernateTemplate().find(hql,model_name);
		if(list!=null && list.size()==1)
		{
			Model model=(Model)list.get(0);
			return model;
		}
		}catch(Exception e)
		{
			log.debug(e);
		}
		return null;
	}

	public Model getModel(Long id) {
		try{
			Model model=(Model) this.getHibernateTemplate().load(Model.class, id);
			return model;
		}catch(Exception e)
		{
			log.debug(e);
		}
		return null;
	}

	public boolean saveModel(Model model) {
		try{
			this.getHibernateTemplate().save(model);
			return true;
		}catch(Exception e)
		{
		log.debug(e);
		}
		return false;
	}

	public boolean updateModel(Model model) {
		try{
		this.getHibernateTemplate().update(model);
		return true;
		}catch(Exception e)
		{
			log.debug(e);
		}
		return false;
	}

}

⌨️ 快捷键说明

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