ZK 数据传输四:BackingBean获取spring层类再获取数据(jsp页面或zul页面)

dataBinding.zul:

<?page title="Data Binding" contentType="text/html;charset=UTF-8"?>

<panel title="后台bean使用SpringUtil并在前台使用bean获取数据">
	  <panelchildren>
		
		<zscript>
			import cn.wempire.zkcrud.web.backingbean.*;
			InjectTool injectTool=new InjectTool();
			
			List list2 = injectTool.lookforUsers();
			String s2=injectTool.lookforSomething();
		</zscript>
		<vbox>
	    <label value="${list2}"/>
	      <label value="${s2}"/>
	    </vbox>
	  </panelchildren>
	</panel>

 

InjectTool.java是个BackingBean,熟悉jsf的都应该知道这种类是干嘛的,其实可以认为是封装了具体业务的类:

package cn.wempire.zkcrud.web.backingbean;

import java.util.List;

import org.zkoss.zkplus.spring.SpringUtil;

import cn.wempire.zkcrud.pojo.User;
import cn.wempire.zkcrud.service.UserService;

public class InjectTool
{

	private UserService userService;
	
	
	public InjectTool()
	{
		
		userService = (UserService)SpringUtil.getBean("userService");
		
	}
    
	public List lookforUsers()
	{
		List users;
		users = userService.findAllUsers();
		System.out.println("后台已获取:"+users.toString());
		return users;
	}

	public String lookforSomething()
	{
		User user;
		user=userService.findUserById(1);
		
		return "User 1 的登录名是:"+user.getLoginName(); 
	}
}

 

你可能感兴趣的:(spring,jsp,bean,JSF,zk)