作家后台新增作品封片图片修改功能

This commit is contained in:
xiongxiaoyang 2021-04-24 10:38:55 +08:00
parent 419d7a971b
commit fb0098aef8
5 changed files with 89 additions and 26 deletions

View File

@ -1,25 +0,0 @@
package com.java2nb.testDemo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RestController;
@RestController()
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestDemo {
@Autowired
RedisTemplate redisTemplate;
@Test
public void test() {
redisTemplate.opsForValue().set("a", "b");
System.out.println(redisTemplate.opsForValue().get("a"));
}
;
}

View File

@ -160,6 +160,17 @@ public class AuthorController extends BaseController{
return ResultBean.ok();
}
/**
* 修改小说封面
*/
@PostMapping("updateBookPic")
public ResultBean updateBookPic(@RequestParam("bookId") Long bookId,@RequestParam("bookPic") String bookPic,HttpServletRequest request) {
Author author = checkAuthor(request);
bookService.updateBookPic(bookId,bookPic, author.getId());
return ResultBean.ok();
}
/**
* 作家日收入统计数据分页列表查询
* */

View File

@ -279,4 +279,12 @@ public interface BookService {
* @param authorId
*/
void updateBookContent( Long indexId, String indexName, String content, Long authorId);
/**
* 修改小说封面
* @param bookId
* @param bookPic
* @param authorId
*/
void updateBookPic(Long bookId, String bookPic, Long authorId);
}

View File

@ -830,5 +830,18 @@ public class BookServiceImpl implements BookService {
}
}
@Override
public void updateBookPic(Long bookId, String bookPic, Long authorId) {
bookMapper.update(update(book)
.set(picUrl)
.equalTo(bookPic)
.set(updateTime)
.equalTo(new Date())
.where(id, isEqualTo(bookId))
.and(BookDynamicSqlSupport.authorId, isEqualTo(authorId))
.build()
.render(RenderingStrategies.MYBATIS3));
}
}

View File

@ -133,6 +133,7 @@
</body>
<script src="/javascript/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="/javascript/ajaxfileupload.js" type="text/javascript"></script>
<script src="/layui/layui.all.js" type="text/javascript"></script>
<script src="/javascript/header.js" type="text/javascript"></script>
<script src="/javascript/user.js" type="text/javascript"></script>
@ -162,7 +163,12 @@
" ["+(i+1)+"]\n" +
" </td>\n" +*/
" <td class=\"goread\">\n" +
" <td style=\"position: relative\" class=\"goread\">\n" +
"<input class=\"opacity\" onchange=\"picChange('"+book.id+"')\"\n" +
" type=\"file\" id=\"file0\" name=\"file\"\n" +
" title=\"点击上传图片\"\n" +
" style=\"z-index: 100;cursor: pointer;left: 30px; top: 0px; width: 60px; height: 80px; opacity: 0; position: absolute; \"\n" +
" />" +
"<img width='50' height='70' src='"+book.picUrl+"'/><br/>" +
" "+book.bookName+"</td>\n" +
@ -269,6 +275,56 @@
}
function picChange(bookId) {
var file = $("#file0").val(); //文件名称
if (file != "") {
$.ajaxFileUpload({
url : "/file/upload", //用于文件上传的服务器端请求地址
secureuri : false, //是否需要安全协议一般设置为false
fileElementId : "file0", //文件上传域的ID
dataType : "json", //返回值类型 一般设置为json
type : "post",
success : function(data) { //服务器成功响应处理函数
if (data.code == 200) {
$.ajax({
type: "POST",
url: "/author/updateBookPic",
data: {'bookId':bookId,'bookPic':data.data},
dataType: "json",
success: function (data) {
if (data.code == 200) {
location.reload();
} else {
lock = false;
layer.alert(data.msg);
}
},
error: function () {
lock = false;
layer.alert('网络异常');
}
})
}else {
layer.alert('图片上传失败');
}
}
});
} else {
alert("请选择上传文件!");
}
}
</script>
</html>