doctypeservice.java

来自「基于hibernate + struts框架 采用mssql数据库,因容量原因」· Java 代码 · 共 58 行

JAVA
58
字号
package com.hdlb.service;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;

import com.hdlb.dao.IDocType;
import com.hdlb.factory.DAOFactory;
import com.hdlb.hibernate.TDoctype;

public class DocTypeService implements IDocTypeService {

	public List getDocType() {
		IDocType doctype = DAOFactory.getDocTypeDAO();
		List list = doctype.createQuery("from TDoctype doctype")
				.list();
		return list;
	}

	public String getDocTypeById(int id) {//bang ni gai jin xia dai ma.xing ma?
		
		System.out.println("in DocTypeService getDocTypeById method");
		IDocType doctypeDAO = DAOFactory.getDocTypeDAO();
		String queryString = "select doctype from TDoctype doctype where doctype.fid=?";
		try {
			Query q = doctypeDAO.createQuery(queryString);
			q.setInteger(0,id);
			TDoctype dt = new TDoctype();
			dt = (TDoctype)q.list().get(0);
			return dt.getFtypename();
		} catch (Exception e) {
			/*
			 * if(){
			 * }else{
			 * }
			 * */
			e.printStackTrace();

		}
		return null;
		
		
//		Query q =	doctypeDAO.createQuery("select doctype from TDoctype doctype where doctype.fid=?");
//		q.setInteger(0,id);
//		List names = q.list();//这里错了
//		Iterator iterator = names.iterator();
//		String type = "";
//		while(iterator.hasNext()) {
//			TDoctype doctype = (TDoctype) iterator.next();
//			type = doctype.getFtypename();
//		    System.out.println(doctype.getFid() + "\t" + doctype.getFtypename());
//		}

	}

}

⌨️ 快捷键说明

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