0

私のcreate.gspページに写真をアップロードするオプションがあります。作成ページでアップロードした写真を表示し、データベースに写真をアップロードできますが、ショー ページでその写真を表示できません。

これはcreate.gspページです

<html>        
    <head>           
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />         
        <meta name="layout" content="billing-without-grid" />         
            <g:set var="entityName"         
        value="${message(code: 'skeletonBill.label', default: 'SkeletonBill')}" />            
        <title><g:message code="default.create.label"        
         args="[entityName]" /></title>           

        <script>      
            function showPhoto(imageFile) {        
             var fileReader = new FileReader();       
             var image = document.getElementById("uploadPhotoFile");       
             fileReader.onload = function(e) {          
            image.src = e.target.result;          
            }      
            fileReader.readAsDataURL(imageFile.files[0]);       
        }        
       </script>         
    </head>           
    <body>         
     <div class="body">          
     <div class="container-fluid">          
     <div class="row">          
     <div class="span6">         
         <img src="" name="uploadPhotoFile" id="uploadPhotoFile"            
                    height="200" width="160" />       
     <table style="width: 25%">        
     <tbody>       
     <tr class="prop">       
     <td valign="top" class="name"><label for="uploadPhoto"><g:message                        code="uploadInformation.uploadPhoto.label" default="Upload Photo" /></label></td>            
        <td valign="top" class="value ${hasErrors(bean: uploadInformationInstance,           field:    'uploadPhoto', 'errors')}">  
         <input type="file" id="uploadPhoto" name="uploadPhoto"         onchange="showPhoto(this)" />            
        </td>
        </tr>         
        </tbody>         
    </table>         
    </div>         
        </div>         
        </div>    
    </div>        
  </body>           
</html> '         

私が作成したドメインクラス

class UploadInformation {       
     static constraints = {     
         uploadPhoto(nullable:true, maxSize: 16384 /* 16K */)       
     }      
     byte[] uploadPhoto        
     static transients = ["uploadPhoto"]         
     static mapping = {      
         uploadPhoto column:"uploadPhoto",sqlType: "blob"         
    }           
}              
4

1 に答える 1

0

アヌジ。

あなたのコードをざっと見た後に私が目にする問題は次のとおりです。

static transients = ["uploadPhoto"]

UploadPhotoは一時的として宣言されているため、データベースに保存されません。
詳細を参照してください一時的なプロパティ

于 2012-07-26T08:33:40.697 に答える