restaurantrepository.java

来自「zk与jsp技术的整合。可以在jsp页面里面使用zk的组件。」· Java 代码 · 共 69 行

JAVA
69
字号
/**
 * 
 */
package org.zkoss.jspdemo.model;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.zkoss.jspdemo.bean.Restaurant;
import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.Sessions;


/**
 * @author ian
 *
 */
public class RestaurantRepository 
{
	private static final String key =  RestaurantRepository.class.getName();
	
	private List<Restaurant> restaurants;
	/**
	 * 
	 *
	 */
	public RestaurantRepository()
	{
		HttpSession session = (HttpSession)Sessions.getCurrent().getNativeSession();
		restaurants = ( List<Restaurant>)
			Sessions.getCurrent().getAttribute(key);
		
		if(restaurants==null)
			Sessions.getCurrent().setAttribute(key, 
					restaurants=Dummy.getDummyRestaurants(session.getServletContext()));
	}
	/**
	 * 
	 * @param session
	 */
	public RestaurantRepository(HttpSession session)
	{
		restaurants = ( List<Restaurant>)
			session.getAttribute(key);
		
		if(restaurants==null)
			session.setAttribute(key, 
					restaurants=Dummy.getDummyRestaurants(session.getServletContext()));
	}
	
	/**
	 * 
	 * @return
	 */
	public List<Restaurant> getAll()
	{
		return restaurants;
	}
	
	public void addRestaurant(Restaurant res)
	{
		restaurants.add(res);
	}
	
	

}

⌨️ 快捷键说明

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