<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)站導航:
     
    主站蜘蛛池模板: 亚洲免费福利在线视频| 香港a毛片免费观看| 最近中文字幕无吗免费高清| 亚洲狠狠久久综合一区77777| 最近中文字幕免费大全| 亚洲国产精品无码久久一区二区| 国产精品美女久久久免费 | 日韩精品亚洲aⅴ在线影院| 激情小说亚洲色图| 亚洲AV成人精品日韩一区18p| 特黄特色大片免费| 亚洲国产人成精品| 国产亚洲欧美日韩亚洲中文色| 成人永久免费高清| 无码免费又爽又高潮喷水的视频 | 成人在线免费观看| 亚洲精品人成网线在线播放va| 日本a级片免费看| 国产精品免费观看视频| 亚洲专区先锋影音| 成人黄18免费视频| 免费人成视频在线播放| 亚洲最大激情中文字幕| 99视频免费播放| 亚洲乱码中文字幕小综合| 亚洲成人免费网址| 亚洲AV无码XXX麻豆艾秋| 亚洲无码日韩精品第一页| 在线观看免费无码视频| 2022年亚洲午夜一区二区福利| 无码一区二区三区AV免费| 午夜亚洲乱码伦小说区69堂| 亚洲精品二区国产综合野狼| 成年黄网站色大免费全看| 日韩色日韩视频亚洲网站 | 亚洲AV无码专区在线亚| 又粗又硬免费毛片| 免费无码成人AV在线播放不卡| 中文日韩亚洲欧美制服| 国产亚洲老熟女视频| 成人免费福利视频|