<!-- 配置多媒体解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<!-- 设定文件上传的最大值 5MB,5*1024*1024 -->
<property name="maxUploadSize" value="5242880"></property>
</bean>
在 contentController.js 引入 uploadService
//控制层
app.controller('contentController' ,function($scope,$controller ,contentService,u ploadService){
<script type="text/javascript" src="../js/service/uploadService.js"> </script>
//上传广告图
$scope.uploadFile=function(){ uploadService.uploadFile().success(
function(response){ if(response.success){
$scope.entity.pic=response.message;
}else{
alert("上传失败!");
}
}
).error(
function(){
alert("上传出错!");
}
);
}
<tr>
<td>图片</td>
<td>
<input type="file" id="file">
<button ng-click="uploadFile()">上传</button>
<img alt="" src="{{entity.pic}}" height="100px" width="200px">
</td>
</tr>
<img alt="" src="{{entity.pic}}" height="50px" width="100px">
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |