基于javaweb+mysql的springboot在线电子书小说阅读系统(java+layui+springboot+maven+mysql+html)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线电子书小说阅读系统(java+layui+springboot+maven+mysql+html)
一、项目介绍 环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
Layui+Springboot+ SpringMVC + HTML + FTP+ JavaScript + JQuery + Ajax + maven等等。
String res = toolsUtils.uploadImg(file,typeImg);
if (!"".equals(res) && res != null) {
return Result.success(Result.SUCCESS,res);
}else {
return Result.success(Result.NULL, null);
}
} catch (Exception e) {
log.print(e);
return Result.error(Result.COLLAPSE, String.valueOf(e));
}
}
}
package zl.readCloud.controller.front;
/**
*/
@RequestMapping("/front/login")
@RestController
public class FrLoginController {
@Resource
FrLoginService frLoginService;
/**
* 注册用户
*/
@PostMapping("/addOne")
public Result addOne(UserPO user){
return Result.success(frLoginService.addOne(user));
}
/**
* 用户登录
*/
@GetMapping("/showOne")
public Result showOne(String uAccount,String uPassword){
return Result.success(frLoginService.showOne(uAccount,uPassword));
}
/**
* 查重用户名
/**
* 注册用户
*/
@PostMapping("/addOne")
public Result addOne(UserPO user){
return Result.success(frLoginService.addOne(user));
}
/**
* 用户登录
*/
@GetMapping("/showOne")
public Result showOne(String uAccount,String uPassword){
return Result.success(frLoginService.showOne(uAccount,uPassword));
}
/**
* 查重用户名
*/
@GetMapping("/showByUAccount")
public Result showByUAccount(String uAccount){
return Result.success(frLoginService.showByUAccount(uAccount));
}
}
package zl.readCloud.controller.after;
/**
*/
@RequestMapping("/after/chapter")
@RestController
public class AfChapterController {
@Resource
AfChapterService afChapterService;
@GetMapping("/showByBTitle")
public Result showByBTitle(String bTitle, String index){
book.setBTitle(null);
}
if ("".equals(book.getCate())) {
book.setCate(null);
}
// integer类型,前台传值时为空,转化为null
if (book.getAuthor() == null && book.getBTitle() == null
&& book.getCate() == null && book.getGoodNum() == null
&& book.getReadNum() == null) {
Integer pages = (page - 1) * limit;
List<BookPO> list = afBookService.showAll(pages, limit);
for (int i = 0; i < list.size(); i++) {
list.get(i).setBPicture(ToolsUtils.getImgPath(list.get(i).getBPicture()));
}
Integer count = afBookService.showAllItem().size();
return Result.success(Result.SUCCESS, count, list);
}
List<BookPO> list = afBookService.showScreen(book);
for (int i = 0; i < list.size(); i++) {
list.get(i).setBPicture(ToolsUtils.getImgPath(list.get(i).getBPicture()));
}
LoggerFactory.getLogger(AfBookController.class).info(list.toString());
return Result.success(list);
}
/**
* detail: 添加书籍
*/
@PostMapping("/addOne")
public Result addOne(@RequestBody BookPO book) {
// 获取一个当前时间,精确到毫秒,确保添加时间不会重,为后面客户端页面排序做准备
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String dateStr = simpleDateFormat.format(date);
book.setUpdateTime(dateStr);
if (book.getBPicture() == null || book.getBPicture() == "") {
book.setBPicture(ToolsUtils.DEFAULT_IMG);
}
return Result.success(afBookService.addOne(book));
}
/**
* detail: 删除书籍,改变状态
*
* @param bId
public class HttpAspect {
private static long startTime;
private static long endTime;
private static final Logger log = LoggerFactory.getLogger(zl.readCloud.aop.HttpAspect.class);
/**
* 切点表达式
*/
@Pointcut("execution(public * zl.readCloud.controller..*.*(..))")
/**
* 切点签名
*/
public void print() {
}
/**
* @Before注解表示在具体的方法之前执行
* @param joinPoint
*/
@Before("print()")
public void before(JoinPoint joinPoint) {
startTime = System.currentTimeMillis();
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
String requestURI = request.getRequestURI();
String remoteAddr = "127.0.0.1";
String requestMethod = request.getMethod();
String declaringTypeNamepeName = joinPoint.getSignature().getDeclaringTypeName();
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
log.info("请求url:=" + requestURI + ",客户端ip:=" + remoteAddr + ",请求方式:=" + requestMethod + ",请求的类名:=" + declaringTypeNamepeName + ",方法名:=" + methodName);
}
/**
* @After注解表示在方法执行之后执行
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
}
}
} catch (Exception e) {
ipAddress="";
}
// ipAddress = this.getRequest().getRemoteAddr();
return ipAddress;
}
}
package zl.readCloud.controller.after;
/**
*/
@RequestMapping("/after/type")
@RestController
public class AfTypeController {
@Resource
AfTypeService afTypeService;
@PostMapping("/addType")
public Result addType(String cate) {
if (afTypeService.showByType(cate) == null){
return Result.success(200,"添加成功",0,afTypeService.addType(cate));
}
return Result.success(200,"该分类已存在,请添加新分类",0,0);
}
@PostMapping("/showAll")
public Result showAll() {
return Result.success(Result.SUCCESS, afTypeService.showAll().size(),afTypeService.showAll());
}
@GetMapping("/updateById")
public Result updateById(@RequestBody TypePO type) {
return Result.success(afTypeService.updateById(type));
}
List<BookChapterDTO> lastChapter = frIndexService.showLastUpdate(lastNnm,null);
List<BookChapterDTO> lastBook = frIndexService.showLastUpdateBook(lastBookNum);
Map<String,List> map = new HashMap<>();
map.put("types",types);
map.put("banners",banners);
map.put("hotRec",hotRec);
map.put("lastChapter",lastChapter);
map.put("lastBook",lastBook);
return Result.success(map);
}
/**
* type页面的所有数据
* @return map
* @param cate 类型
* @param lastNnm 最近更新章节的条数
*/
@GetMapping("/frType")
public Result frType(Integer lastNnm, String cate){
List<TypePO> types = frIndexService.showTypeAll();
List<BookPO> hotRec = frIndexService.showByHotRec(cate);
for (BookPO bookPO : hotRec) {
bookPO.setBPicture(ToolsUtils.getImgPath(bookPO.getBPicture()));
}
List<BookChapterDTO> lastChapter = frIndexService.showLastUpdate(lastNnm,cate);
Map<String,List> map = new HashMap<>();
map.put("types",types);
map.put("hotRec",hotRec);
map.put("lastChapter",lastChapter);
return Result.success(map);
}
/**
* details页面的所有数据
* @return map
* @param bId
*/
@GetMapping("/frDetail")
public Result frDetail(Integer bId){
List<TypePO> types = frIndexService.showTypeAll();
public class AfTypeController {
@Resource
AfTypeService afTypeService;
@PostMapping("/addType")
public Result addType(String cate) {
if (afTypeService.showByType(cate) == null){
return Result.success(200,"添加成功",0,afTypeService.addType(cate));
}
return Result.success(200,"该分类已存在,请添加新分类",0,0);
}
@PostMapping("/showAll")
public Result showAll() {
return Result.success(Result.SUCCESS, afTypeService.showAll().size(),afTypeService.showAll());
}
@GetMapping("/updateById")
public Result updateById(@RequestBody TypePO type) {
return Result.success(afTypeService.updateById(type));
}
@PostMapping("/deleteById")
public Result deleteById(Integer tId) {
return Result.success(afTypeService.deleteById(tId));
}
}
package zl.readCloud.controller.common;
/**
* @Description:
*/
@RestController
@RequestMapping("/common")
* @Before注解表示在具体的方法之前执行
* @param joinPoint
*/
@Before("print()")
public void before(JoinPoint joinPoint) {
startTime = System.currentTimeMillis();
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
String requestURI = request.getRequestURI();
String remoteAddr = "127.0.0.1";
String requestMethod = request.getMethod();
String declaringTypeNamepeName = joinPoint.getSignature().getDeclaringTypeName();
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
log.info("请求url:=" + requestURI + ",客户端ip:=" + remoteAddr + ",请求方式:=" + requestMethod + ",请求的类名:=" + declaringTypeNamepeName + ",方法名:=" + methodName);
}
/**
* @After注解表示在方法执行之后执行
*/
@After("print()")
public void after() {
endTime = System.currentTimeMillis() - startTime;
}
/**
* @AfterReturning注解用于获取方法的返回值
* @param object
*/
@AfterReturning(pointcut = "print()", returning = "object")
public void getAfterReturn(Object object) {
log.info("本次接口耗时={}ms", endTime);
}
}
package zl.readCloud.controller.after;
* reading页面的所有数据
* @return map
* @param bId
*/
@GetMapping("/frReading")
public Result frReading(Integer bId,String cTitle){
List<TypePO> types = frIndexService.showTypeAll();
List<BookChapterDTO> chapter = frReadingService.showReadingChapter(bId,cTitle);
Map<String,List> map = new HashMap<>();
map.put("types",types);
map.put("chapter",chapter);
return Result.success(map);
}
/**
* reading页面的翻页
* @return map
* @param bId
*/
@GetMapping("/frNextOrPrevious")
public Result frNextOrPrevious(Integer bId, String eTime, String compare){
if ("".equals(compare)){
return Result.success(frReadingService.showNextOrPrevious(bId,eTime,null));
}
return Result.success(frReadingService.showNextOrPrevious(bId,eTime,compare));
}
}
package zl.readCloud.controller.after;
/**
*/
afBookService.deleteById(bId,1);
return Result.success(afBookService.addChap(chapter));
}
/**
* detail: 根据小说bId查询小说的所有条数,进而得出下一章的数字
*
* @param bId
* @return int
*/
@GetMapping("/showByBId")
public Result showByBId(Integer bId){
return Result.success(afBookService.showByBId(bId).size());
}
@GetMapping("/showByBTitle")
public Result showByBTitle(String bTitle) {
BookPO book = afBookService.showByBTitle(bTitle);
if (book != null) {
return Result.success(Result.SUCCESS,1,book);
}
return Result.success(Result.SUCCESS,0,null);
}
}
package zl.readCloud.controller.after;
/**
*/
@RequestMapping("/after/user")
@RestController
public class AfUserController {
@Resource
AfUserService afUserService;
/**
* 通过aop拦截请求 记录运行信息
*
*/
@Aspect
@Component
public class HttpAspect {
private static long startTime;
private static long endTime;
private static final Logger log = LoggerFactory.getLogger(zl.readCloud.aop.HttpAspect.class);
/**
* 切点表达式
*/
@Pointcut("execution(public * zl.readCloud.controller..*.*(..))")
/**
* 切点签名
*/
public void print() {
}
/**
* @Before注解表示在具体的方法之前执行
* @param joinPoint
*/
@Before("print()")
public void before(JoinPoint joinPoint) {
startTime = System.currentTimeMillis();
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
String requestURI = request.getRequestURI();
String remoteAddr = "127.0.0.1";
String requestMethod = request.getMethod();
String declaringTypeNamepeName = joinPoint.getSignature().getDeclaringTypeName();
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
log.info("请求url:=" + requestURI + ",客户端ip:=" + remoteAddr + ",请求方式:=" + requestMethod + ",请求的类名:=" + declaringTypeNamepeName + ",方法名:=" + methodName);
}
/**
* @After注解表示在方法执行之后执行
@GetMapping("/frReading")
public Result frReading(Integer bId,String cTitle){
List<TypePO> types = frIndexService.showTypeAll();
List<BookChapterDTO> chapter = frReadingService.showReadingChapter(bId,cTitle);
Map<String,List> map = new HashMap<>();
map.put("types",types);
map.put("chapter",chapter);
return Result.success(map);
}
/**
* reading页面的翻页
* @return map
* @param bId
*/
@GetMapping("/frNextOrPrevious")
public Result frNextOrPrevious(Integer bId, String eTime, String compare){
if ("".equals(compare)){
return Result.success(frReadingService.showNextOrPrevious(bId,eTime,null));
}
return Result.success(frReadingService.showNextOrPrevious(bId,eTime,compare));
}
}
package zl.readCloud.controller.after;
/**
*/
@RequestMapping("/front")
@RestController
public class FrController {
// 首页banner图的数量
private static final Integer BANNER_COUNT = 5;
@Resource
FrIndexService frIndexService;
@Resource
FrDetailsService frDetailsService;
@Resource
FrReadingService frReadingService;
/**
* 头部的搜索功能
* @return list<book>
* @param bTitle 输入的书籍名称,模糊查询
*/
@GetMapping("/frSearch")
public Result frSearch(String bTitle){
List<TypePO> types = frIndexService.showTypeAll();
List<BookPO> books = frIndexService.showBTitleByLike(bTitle);
if (books.size() == 0) {
}
Map<String,List> map = new HashMap<>();
map.put("types",types);
map.put("books",books);
/**
*/
@RequestMapping("/front/login")
@RestController
public class FrLoginController {
@Resource
FrLoginService frLoginService;
/**
* 注册用户
*/
@PostMapping("/addOne")
public Result addOne(UserPO user){
return Result.success(frLoginService.addOne(user));
}
/**
* 用户登录
*/
@GetMapping("/showOne")
public Result showOne(String uAccount,String uPassword){
return Result.success(frLoginService.showOne(uAccount,uPassword));
}
/**
* 查重用户名
*/
@GetMapping("/showByUAccount")
public Result showByUAccount(String uAccount){
return Result.success(frLoginService.showByUAccount(uAccount));
}
}
package zl.readCloud.controller.after;
/**
*/
@RequestMapping("/after/admin")
@RestController
public class AfAdminController {
@Resource
private AfAdminService afAdminService;
/**
* 登录验证
*/
@PostMapping(value = "/login")
public Result login(@RequestBody AdminPO admin, HttpServletRequest request){
AdminPO res = afAdminService.showOne(admin);
HttpSession session = request.getSession();
if (res != null){
session.setAttribute("admin",res);
}
return Result.success(res);
}
@GetMapping("/showAA")
public Result showAA(String password,String account){
AdminPO admin = new AdminPO();
admin.setPassword(password);
admin.setAccount(account);
return Result.success(afAdminService.showOne(admin));
}
/**
* 旧密码通过验证后,修改密码
*/
@GetMapping("/updateByUAccount")
Result updateByUAccount(String password,String account){
return Result.success(afAdminService.updateByUAccount(password,account));
}
/**
* detail: 编辑书籍
*
* @param book
* @return int
*/
@PostMapping("/updateOne")
public Result updateOne(@RequestBody BookPO book) {
return Result.success(afBookService.updateOne(book));
}
/**
* detail: 添加章节内容
*
* @param chapter
* @return int
*/
@PostMapping("/addChap")
public Result addChap(ChapterPO chapter){
//获取一个当前时间,精确到毫秒,确保添加时间不会重,为后面客户端页面排序做准备
//创建一个date对象保存当前时间
// Date date = new Date();
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
//format()方法将Date转换成指定格式的String
// String dateStr = simpleDateFormat.format(date);
chapter.setETime(DateUtils.getCurrentTime());
Integer bId = chapter.getBId();
afBookService.updateByBId(bId,DateUtils.getCurrentTime());
afBookService.deleteById(bId,1);
return Result.success(afBookService.addChap(chapter));
}
/**
* detail: 根据小说bId查询小说的所有条数,进而得出下一章的数字
*
* @param bId
* @return int
*/
@GetMapping("/showByBId")
public Result showByBId(Integer bId){
map.put("chapters", chapters);
return Result.success(map);
}
/**
* reading页面的所有数据
* @return map
* @param bId
*/
@GetMapping("/frReading")
public Result frReading(Integer bId,String cTitle){
List<TypePO> types = frIndexService.showTypeAll();
List<BookChapterDTO> chapter = frReadingService.showReadingChapter(bId,cTitle);
Map<String,List> map = new HashMap<>();
map.put("types",types);
map.put("chapter",chapter);
return Result.success(map);
}
/**
* reading页面的翻页
* @return map
* @param bId
*/
@GetMapping("/frNextOrPrevious")
public Result frNextOrPrevious(Integer bId, String eTime, String compare){
if ("".equals(compare)){
return Result.success(frReadingService.showNextOrPrevious(bId,eTime,null));
}
return Result.success(frReadingService.showNextOrPrevious(bId,eTime,compare));
}
}
package zl.readCloud.controller.after;
*/
@PostMapping("/addChap")
public Result addChap(ChapterPO chapter){
//获取一个当前时间,精确到毫秒,确保添加时间不会重,为后面客户端页面排序做准备
//创建一个date对象保存当前时间
// Date date = new Date();
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
//format()方法将Date转换成指定格式的String
// String dateStr = simpleDateFormat.format(date);
chapter.setETime(DateUtils.getCurrentTime());
Integer bId = chapter.getBId();
afBookService.updateByBId(bId,DateUtils.getCurrentTime());
afBookService.deleteById(bId,1);
return Result.success(afBookService.addChap(chapter));
}
/**
* detail: 根据小说bId查询小说的所有条数,进而得出下一章的数字
*
* @param bId
* @return int
*/
@GetMapping("/showByBId")
public Result showByBId(Integer bId){
return Result.success(afBookService.showByBId(bId).size());
}
@GetMapping("/showByBTitle")
public Result showByBTitle(String bTitle) {
BookPO book = afBookService.showByBTitle(bTitle);
if (book != null) {
return Result.success(Result.SUCCESS,1,book);
}
return Result.success(Result.SUCCESS,0,null);
}
}
package zl.readCloud.controller.after;
/**
* detail: 验证用户,账号和密码
* @param uAccount
* @param uPassword
* @return int
*/
@GetMapping("/showOne")
Result showOne(String uAccount,String uPassword){
return Result.success(afUserService.showOne(uAccount,uPassword));
}
/**
* detail: 修改密码操作:
* 第一步,showOne,验证通过后,才可以修改密码
* 第二步,根据已登录的用户名修改密码
* @param uPassword
* @param uAccount
* @return int
*/
@GetMapping("/updateByUAccount")
Result updateByUAccount(String uPassword,String uAccount){
return Result.success(afUserService.updateByUAccount(uPassword,uAccount));
}
/**
* detail: 通过账号查询
* @param uAccount
* @return int
*/
@GetMapping("/showByUAccount")
Result showByUAccount(String uAccount){
return Result.success(afUserService.showByUAccount(uAccount));
}
/**
* detail: 添加用户
* @param user
* @return int
*/
@PostMapping("/addOne")
Result addOne(@RequestBody UserPO user){
return Result.success(afUserService.addOne(user));
}
/**
* detail: 编辑用户基本信息
* @param user
* @return int
afBookService.updateByBId(bId,DateUtils.getCurrentTime());
afBookService.deleteById(bId,1);
return Result.success(afBookService.addChap(chapter));
}
/**
* detail: 根据小说bId查询小说的所有条数,进而得出下一章的数字
*
* @param bId
* @return int
*/
@GetMapping("/showByBId")
public Result showByBId(Integer bId){
return Result.success(afBookService.showByBId(bId).size());
}
@GetMapping("/showByBTitle")
public Result showByBTitle(String bTitle) {
BookPO book = afBookService.showByBTitle(bTitle);
if (book != null) {
return Result.success(Result.SUCCESS,1,book);
}
return Result.success(Result.SUCCESS,0,null);
}
}
package zl.readCloud.controller.after;
/**
*/
@RequestMapping("/after/user")
@RestController
public class AfUserController {
@Resource
AfUserService afUserService;
/**
* detail: 分页展示所有用户、及查询用户
* 1.layui会自动传page和limit两个参数过来,进行分页操作
* 2.layui方法的重载,会在额外在传过来uAcc参数
* @param
* @return List<User>
@Resource
private AfAdminService afAdminService;
/**
* 登录验证
*/
@PostMapping(value = "/login")
public Result login(@RequestBody AdminPO admin, HttpServletRequest request){
AdminPO res = afAdminService.showOne(admin);
HttpSession session = request.getSession();
if (res != null){
session.setAttribute("admin",res);
}
return Result.success(res);
}
@GetMapping("/showAA")
public Result showAA(String password,String account){
AdminPO admin = new AdminPO();
admin.setPassword(password);
admin.setAccount(account);
return Result.success(afAdminService.showOne(admin));
}
/**
* 旧密码通过验证后,修改密码
*/
@GetMapping("/updateByUAccount")
Result updateByUAccount(String password,String account){
return Result.success(afAdminService.updateByUAccount(password,account));
}
/**
* 查询所有的管理员
*/
@PostMapping(value = "/showAll")
public Result showAll(){
return Result.success(Result.SUCCESS,afAdminService.showAll().size(),afAdminService.showAll());
}
/**
* 删除管理员
*/
@PostMapping(value = "/deleteByAccount")
public Result deleteByAccount(String account){
return Result.success(afAdminService.deleteByAccount(account));
}
/**
* 添加管理员
*/
}
LoggerFactory.getLogger(AfBookController.class).info(list.toString());
return Result.success(list);
}
/**
* detail: 添加书籍
*/
@PostMapping("/addOne")
public Result addOne(@RequestBody BookPO book) {
// 获取一个当前时间,精确到毫秒,确保添加时间不会重,为后面客户端页面排序做准备
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String dateStr = simpleDateFormat.format(date);
book.setUpdateTime(dateStr);
if (book.getBPicture() == null || book.getBPicture() == "") {
book.setBPicture(ToolsUtils.DEFAULT_IMG);
}
return Result.success(afBookService.addOne(book));
}
/**
* detail: 删除书籍,改变状态
*
* @param bId
* @return int
*/
@PostMapping("/deleteById")
public Result deleteById(Integer bId, Integer status) {
if (status == 1) {
return Result.success(200, "下架成功", 200, afBookService.deleteById(bId, 0));
}
return Result.success(200, "上架成功", 200, afBookService.deleteById(bId, 1));
}
/**
* detail: 编辑书籍
*
* @param book
* @return int
*/
@PostMapping("/updateOne")
public Result updateOne(@RequestBody BookPO book) {
return Result.success(afBookService.updateOne(book));
}
/**
* detail: 添加章节内容
*
* @param chapter
* @return int
*/
@PostMapping("/addChap")
}
/**
* detail: 编辑用户基本信息
* @param user
* @return int
*/
@PostMapping("/updateById")
Result updateById(@RequestBody UserPO user){
return Result.success(afUserService.updateById(user));
}
}
package zl.readCloud.aop;
/**
* 通过aop拦截请求 记录运行信息
*
*/
@Aspect
@Component
public class HttpAspect {
private static long startTime;
private static long endTime;
private static final Logger log = LoggerFactory.getLogger(zl.readCloud.aop.HttpAspect.class);
/**
* 切点表达式
*/
@Pointcut("execution(public * zl.readCloud.controller..*.*(..))")
/**
* 2.layui方法的重载,会在额外在传过来uAcc参数
* @param
* @return List<User>
*/
@PostMapping("/showAll")
Result showAll(Integer page, Integer limit, String uAcc){
if (uAcc == null || uAcc == ""){
Integer pages = (page-1) * limit;
return Result.success(Result.SUCCESS, afUserService.showAllItem().size(), afUserService.showAll(pages, limit));
}
return Result.success(Result.SUCCESS, afUserService.showByUAccount(uAcc));
}
/**
* detail: 注销用户,启用用户
* @param uId
* @return int
*/
@PostMapping("/deleteById")
Result deleteById(Integer uId,Integer status){
if (status == 1){
return Result.success(200,"注销成功",200,afUserService.deleteById(uId,0));
}
return Result.success(200,"启用成功",200,afUserService.deleteById(uId,1));
}
/**
* detail: 批量注销用户
* @param uIds
* @return int
*/
@PostMapping("/deleteByIds")
Result deleteByIds(Integer[] uIds){
return Result.success(afUserService.deleteByIds(uIds));
}
/**
* detail: 验证用户,账号和密码
* @param uAccount
* @param uPassword
* @return int
*/
@GetMapping("/showOne")
Result showOne(String uAccount,String uPassword){
return Result.success(afUserService.showOne(uAccount,uPassword));
}
/**
* detail: 修改密码操作:
* 第一步,showOne,验证通过后,才可以修改密码
* 第二步,根据已登录的用户名修改密码
@Resource
AfUserService afUserService;
/**
* detail: 分页展示所有用户、及查询用户
* 1.layui会自动传page和limit两个参数过来,进行分页操作
* 2.layui方法的重载,会在额外在传过来uAcc参数
* @param
* @return List<User>
*/
@PostMapping("/showAll")
Result showAll(Integer page, Integer limit, String uAcc){
if (uAcc == null || uAcc == ""){
Integer pages = (page-1) * limit;
return Result.success(Result.SUCCESS, afUserService.showAllItem().size(), afUserService.showAll(pages, limit));
}
return Result.success(Result.SUCCESS, afUserService.showByUAccount(uAcc));
}
/**
* detail: 注销用户,启用用户
* @param uId
* @return int
*/
@PostMapping("/deleteById")
Result deleteById(Integer uId,Integer status){
if (status == 1){
return Result.success(200,"注销成功",200,afUserService.deleteById(uId,0));
}
return Result.success(200,"启用成功",200,afUserService.deleteById(uId,1));
}
/**
* detail: 批量注销用户
* @param uIds
* @return int
*/
@PostMapping("/deleteByIds")
* detail: 编辑书籍
*
* @param book
* @return int
*/
@PostMapping("/updateOne")
public Result updateOne(@RequestBody BookPO book) {
return Result.success(afBookService.updateOne(book));
}
/**
* detail: 添加章节内容
*
* @param chapter
* @return int
*/
@PostMapping("/addChap")
public Result addChap(ChapterPO chapter){
//获取一个当前时间,精确到毫秒,确保添加时间不会重,为后面客户端页面排序做准备
//创建一个date对象保存当前时间
// Date date = new Date();
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
//format()方法将Date转换成指定格式的String
// String dateStr = simpleDateFormat.format(date);
chapter.setETime(DateUtils.getCurrentTime());
Integer bId = chapter.getBId();
afBookService.updateByBId(bId,DateUtils.getCurrentTime());
afBookService.deleteById(bId,1);
return Result.success(afBookService.addChap(chapter));
}
/**
* detail: 根据小说bId查询小说的所有条数,进而得出下一章的数字
*
* @param bId
* @return int
*/
@GetMapping("/showByBId")
public Result showByBId(Integer bId){
return Result.success(afBookService.showByBId(bId).size());
}
@GetMapping("/showByBTitle")
public Result showByBTitle(String bTitle) {
BookPO book = afBookService.showByBTitle(bTitle);
if (book != null) {
return Result.success(Result.SUCCESS,1,book);
}
return Result.success(Result.SUCCESS,0,null);