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 回答