<el
‐
upload
action=
"
/filesystem/upload
"
list
‐
type
=
"
picture
‐
card
"
:before
‐
upload
=
"
setbusinesskey
"
:on
‐
success
=
"
handleSuccess
"
:file
‐
list
=
"
fileList
"
:limit
=
"
picmax
"
:on
‐
exceed
=
"
rejectupload
"
:data
=
"
uploadval
"
>
<i class
=
"
el
‐
icon
‐
plus
"
></i>
</el
‐
upload>
<script>
import
*
as sysConfig from
'
@/../config/sysConfig
'
;
import
*
as courseApi from
'
../../api/course
'
;
import utilApi from
'
../../../../common/utils
'
;
import
*
as systemApi from
'
../../../../base/api/system
'
;
export default {
data() {
return {
picmax:1,
courseid:
''
,
dialogImageUrl:
''
,
dialogVisible: false,
fileList:[],
uploadval:{filetag:
"
course
"
},
imgUrl:sysConfig
.imgUrl
}
},
methods: {
//超出文件上传个数提示信息
rejectupload(){
this.
$message.error(
"
最多上传
"
+this.
picmax+
"
个图片
"
);
},
//在上传前设置上传请求的数据
setuploaddata(){
},
//删除图片
handleRemove(file, fileList) {
console.log(file)
alert(
'
删除
'
)
},
//上传成功的钩子方法
handleSuccess(response, file, fileList){
console.log(response)
alert(
'
上传成功
'
)
},
//上传失败执行的钩子方法
handleError(err, file, fileList){
this.
$message.error(
'
上传失败
'
);
//清空文件队列
this.fileList
=
[]
}
},
mounted(){
//课程id
this.courseid
=
this.
$route.
params.courseid;
}
}
</script>
@ApiOperation(
"
添加课程图片
"
)
public ResponseResult addCoursePic(String courseId,String pic);
@Data
@ToString
@Entity
@Table(name
=
"
course_pic
"
)
@GenericGenerator(name
=
"
jpa
‐
assigned
"
, strategy
=
"
assigned
"
)
public class CoursePic implements Serializable {
private static final long serialVersionUID =
‐
916357110051689486L;
@Id
@GeneratedValue(generator =
"
jpa
‐
assigned
"
)
private String courseid;
private String pic;
}
public interface CoursePicRepository extends JpaRepository<CoursePic, String> {
}
//添加课程图片
@Transactional
public ResponseResult saveCoursePic(String courseId,String pic){
//查询课程图片
Optional<CoursePic> picOptional =
coursePicRepository
.findById(courseId);
CoursePic coursePic
= null;
if(picOptional.isPresent()){
coursePic
=
picOptional.
get();
}
//没有课程图片则新建对象
if(coursePic
== null){
coursePic
= new CoursePic();
}
coursePic.setCourseid(courseId);
coursePic.setPic(pic);
//保存课程图片
coursePicRepository
.save(coursePic);
return new ResponseResult(CommonCode.SUCCESS);
}
@Override
@PostMapping(
"
/coursepic/add
"
)
public ResponseResult addCoursePic(@RequestParam(
"
courseId
"
) String courseId,
@RequestParam(
"
pic
"
) String pic) {
//保存课程图片
return courseService.saveCoursePic(courseId,pic);
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |