<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Vikings

    T3 里的圖片顯示

    例子參考:
    T3自帶的workbeanch里有
    1.ChartService class
    2.ChartAsset class
    3.IChartProvider的例子代碼

    思路:
    因為在DAO,service里返回的Info對象里已經(jīng)有圖片的屬性,
    類型是byte[]
    所以直接out.write(byte[])獲得圖片.

    題外:
    其中,AbstractService相比T4少了Webresponse屬性,
    不可以直接在IChartProvider里定義 
    public void sendDynaAsset(WebResponse response);
    然后在實現(xiàn)類里用這句 
    OutputStream out = response.getOutputStream(new ContentType("image/jpeg"));
    來操作out.write .
    T3里都在AbstractService里操作out, service()方法里就有參數(shù)ResponseOutputStream output

    代碼:
    1. ChartService
    public class ChartService extends AbstractService{

      
    public void service(
            IEngineServiceView engine,
            IRequestCycle cycle,
            ResponseOutputStream output)
            
    throws ServletException, IOException
        
    {

    .

      
    try
            
    {
                IChartProvider provider 
    = (IChartProvider) component;

                
    byte[] bytes = provider.getImageBytes();

                
    //默認規(guī)則,page頁面里若數(shù)據(jù)庫里沒有bytes,則返回null
                if (bytes==null)
                    
    //顯示默認圖片
                    bytes = drawDefaultImage();         
                
                output.setContentType(
    "image/jpeg");

                
    // I've seen a few bits of wierdness (including a JVM crash) inside this code.
                
    // Hopefully, its a multi-threading problem that can be resolved
                
    // by synchronizing.

                
    synchronized (this)
                
    {
                    output.write(bytes);
                }

            }


       }


    protected byte[] drawDefaultImage() {
            
    int width = 102, height = 126;
            BufferedImage image 
    = new BufferedImage(width, height,
                    BufferedImage.TYPE_INT_RGB);
            Graphics g 
    = image.getGraphics();

            g.setColor(Color.WHITE);
            g.fillRect(
    00, width, height);

            g.setColor(Color.RED);
            g.setFont(
    new Font("Default", Font.PLAIN, 22));
            g.drawString(
    "暫無照片"10, height / 2 - 10);

            
    byte buffer[] = null;
            
    try {
                ByteArrayOutputStream out 
    = new ByteArrayOutputStream();
                ImageIO.write(image, 
    "JPEG", out);
                buffer 
    = out.toByteArray();
            }
     catch (Exception e) {
                log.info(
    "繪制默認圖片失敗");
            }

            
    return buffer;
        }

    }


    2. ChartAsset
    與workbeanch里的CharAsset一樣,沒有任何增刪
    public class ChartAsset extends AbstractAsset{
      
    private IEngineService _chartService;
      
    private IComponent _chartProvider;
     
    public ChartAsset(IRequestCycle cycle, IComponent chartProvider)
        
    {
            
    super(nullnull);
            
            IEngine engine 
    = cycle.getEngine();

            _chartService 
    = engine.getService(ChartService.SERVICE_NAME);
            _chartProvider 
    = chartProvider;
        }


    }

    3. IChartProvider
    Service類回調接口
    public interface IChartProvider
    {
        
    public byte[] getImageBytes();
    }


    4.Page類
    需要實現(xiàn)IChartProvider回調接口的getImageBytes()方法
    public abstract SaryPage extends BasePage implements IChartProvider{
     
    private IAsset chartImageAsset;

        
    public IAsset getChartImageAsset() {
            
    if (chartImageAsset == null)
                chartImageAsset 
    = new ChartAsset(getRequestCycle(), this);

            
    return chartImageAsset;
        }

     
    /**
         * This method is invoked by the service (in a seperate request cycle from
         * all the form handling stuff). The {
    @link #getChartImageAsset()} method
         * provides an {
    @link IAsset} that is handled by the {@link ChartService},
         * and the asset encodes the identity of this page.
         * 
         
    */

        
    public byte[] getImageBytes() {
            
    if (getSary().getXp()!=null)
                
    return getSary().getXp();
            
    else
                
    //默認規(guī)則,page頁面里若數(shù)據(jù)庫里沒有bytes,則返回null
                return null;
        }


    }


    5.  Html頁面
    <img jwcid="@Image" width="102" height="126"  image="ognl:chartImageAsset"/>

    6. .application文件 注冊ChartService
    <application name="SaryProject" engine-class="cn.vikings.tapestry.common.SaryEngine">
        
     
    <service name="chart" class="cn.vikings.tapestry.common.chart.ChartService"/>

    </application>

    圖片顯示搞店. 就這么簡單.
    不用再很BT得傳一句HQL語句和圖片ID來,再用JDBC查一次數(shù)據(jù)庫.

    posted on 2007-10-29 16:56 Vikings 閱讀(694) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 免费久久人人爽人人爽av| 日韩av无码成人无码免费| 亚洲免费视频在线观看| 最近免费中文字幕高清大全| 亚洲一区二区三区高清不卡| 免费一级毛片清高播放| 一级毛片不卡片免费观看| MM1313亚洲国产精品| 亚洲欧洲日产国产综合网| 毛片a级毛片免费观看品善网| 一区二区免费在线观看| 78成人精品电影在线播放日韩精品电影一区亚洲 | 好吊妞998视频免费观看在线| 乱淫片免费影院观看| 亚洲成人免费网址| 国产成人亚洲精品91专区手机| 久久综合AV免费观看| 国产永久免费高清在线| 色天使色婷婷在线影院亚洲| 亚洲色图古典武侠| 亚洲最大激情中文字幕| 色吊丝最新永久免费观看网站 | 99视频在线精品免费观看6| 一个人看的www免费高清| 亚洲jjzzjjzz在线观看| 在线观看亚洲成人| 午夜视频在线观看免费完整版| a毛片免费在线观看| 国产精品亚洲二区在线| 亚洲伊人色一综合网| 国产亚洲无线码一区二区| 日韩免费福利视频| 成年免费大片黄在线观看岛国| 成人免费一区二区三区| 亚洲国产精品美女久久久久| 亚洲精品国产免费| 亚洲国产精品线在线观看| 亚洲精品无码mv在线观看网站| 免费在线观看视频a| 日日夜夜精品免费视频| 国产乱子精品免费视观看片|