`
Cash
  • 浏览: 181922 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

Eclipse3M7+Hibernate2+Spring1.2 环境测试

阅读更多
package springWebwork2;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import junit.framework.TestCase;


import showHelper.Menu_Block;

public class TestSpringHibernate extends TestCase {

/**
* @param args
*/
public String getList(String ObjName) {
    String ShowContent="";
try{
        ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");
        ShowContent=((Menu_Block)context.getBean(ObjName)).show(0);
    }catch(Exception e){
        System.out.println("执行时出现错误"+e.getMessage());
    }
    return ShowContent;
}

}
-----------------------------------------------------------------------------------
上面需要的 Menu_Block.java类用以显示一个下拉列表

package showHelper;

import org.springframework.orm.hibernate.support.*;
import java.util.*;
import showHelper.block.Block;

public class Menu_Block extends HibernateDaoSupport implements Menu_i {

public String show(Integer BlockID ){
String R="";
List L = new ArrayList();
String Sql="from Block as block1 order by block1.Showorder";
try{
L=getHibernateTemplate().find(Sql);
}catch(Exception e){
System.out.println("显示帮助类错误:"+e.getMessage());
}
R="<select>";
R+="<option value='' >区域</option>";
for(int i=0;i<L.size();i++){
Block M = (Block)L.get(i);
R+="<option value='"+M.getId()+"'";
if(BlockID==M.getId()){
R+=" selected ";
}
R+=">"+M.getBlockname()+"</option>";
}
R+="</select>";
return R;
}



}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics