Eclipse3M7+Hibernate2+Spring1.2 环境测试
程序员文章站
2022-07-12 18:31:33
...
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;
}
}
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;
}
}