基于Springboot的在线网络小说阅读网站
本系统主要有网站首页注册界面、登录界面、个人中心界面、个人管理界面、小说管理界面、章节管理界面、添加章节界面、我的书架界面、阅读记录界面、小说主界面、用户管理界面、书评管理界面、订单管理界面、分类管理页面、支付界面。主要实现了用户创建、更新小说,用户在线阅读小说,用户更改个人信息、用户更改小说信息、用户添加摹本小说到我的书架、用户对小说进行评价,用户购买平台VIP等功能。
使用Springboot框架后,因为此框架内嵌了Tomcat服务器,所以开发人员在运行系统后不需要把Tomcat部署到服务器上,直接将项目打成jar 包,运行main函数后,直接在浏览器上输入对应端口对应网址,即可进入到开发的网站中。
Springboot在开发时采用Maven来管理项目,这样的组合框架可以隔离各个层次之间的依赖性。此种架构开发出来实现的系统对后期的维护与二次开发带来了很大的便利[11]。除此之外它还避免了编写过多的注释,样板代码和XML配置。Springboot框架与其它的Spring库如Spring ORM,Spring Data,等集成操作起来十分简易方便。用Spring boot框架开发和测试Web应用程序能减少开发人员不必要的工作量,同时在配置环境变量中有适应的JDK即可运行。从最根本上来讲, Springboot是一些库的集合, 框架中的框架, 只要导入相应依赖, 它就能够被任意项目的构建系统所使用[12]。
MVC架构通俗的说是一种将数据、页面与业务逻辑分割开来的组织架构,分为模型(model)、视图(view)、控制器(controller)。在本系统中对应Entity实体类层,JSP前端界面,Controller控制层,Service业务层,数据访问Dao层,及对数据库实际操作的Mapper层。MVC架构模式将逻辑、界面和数据进行分离,使得代码组织结构更加清晰明了[13]。
本系统Controller层使用Springboot框架默认的整合Spring MVC框架,Spring MVC和Springboot整合操作不同于其他框架,相比来说不需要配置任何文件,全注解开发,同时使用Swagger技术来管理API,节省了传统意义上繁琐的书写接口文档的时间,提高了开发速度与效率。
本系统的数据库访问层使用MyBatis框架,注解版本可以免去配置文件,实现零配置集成,导入Maven依赖,之后在application.yml配置文件中添加了连接数据库信息,然后编写对应的Controller,Service等。
JSP是Java的服务器页面,是一种适用于各种Java程序中的动态网页技术。JSP集成其他插件,如在本系统中就集成了一个富文本编辑器(UEditor:是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器, 具有轻量、可定制、用户体验优秀等特点[14])来达到在线写作的功能。JSP是在传统网页中插入程序段和JSP标记,然后形成后缀名为(*.jsp)的JSP文件,就构成了网站的前端界面。本系统在前端的限制上还采用JQuery中的一些决策规则,如正则表达式等,正则表达式之间的多项式时间包含决策规则,并证明了该规则能准确地捕捉实际的包含关系[15]。
package com.novel.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.novel.entity.Evaluation;
import com.novel.entity.User;
import com.novel.service.EvaluationService;
import com.novel.util.DateUtil;
import com.novel.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
/**
* @Description: 评论管理
*/
@Controller
@RequestMapping("evaluation")
public class EvaluationController {
@Autowired
private EvaluationService evaluationService;
/**
* 跳转到评论管理
* @return
*/
@RequestMapping("show")
public String show(){
return "evaluationManage";
}
@RequestMapping("addevaluation")
public String addevaluation(Evaluation record, HttpSession session){
User user = (User) session.getAttribute("user");
if(user==null){
return "login";
}
record.setCreatetime(DateUtil.getStringDate());
record.setUsername(user.getUsername());
evaluationService.insert(record);
return "redirect:/novelDetail?novelId="+record.getUserid();
}
/**
* 评论列表
* @param pn
* @return
*/
@RequestMapping("/showjson")
@ResponseBody
public Msg getAllGoods(@RequestParam(value = "page",defaultValue = "1") Integer pn, HttpServletResponse response, Model model) {
//一页显示几个数据
PageHelper.startPage(pn, 10);
List<Evaluation> evaluationList = evaluationService.selectByEvaluation();
//显示几个页号
PageInfo page = new PageInfo(evaluationList,5);
return Msg.success("查询成功!").add("pageInfo", page);
}
/**
* 评论删除
* @param id
* @return
*/
@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
@ResponseBody
public Msg deleteUser(@PathVariable("id")Integer id) {
evaluationService.deleteByPrimaryKey(id);
return Msg.success("删除成功!");
}
}
package com.bs.yzm.controller;
import com.bs.yzm.entity.common.LayPage;
import com.bs.yzm.entity.dto.NOrderDto;
import com.bs.yzm.entity.dto.OrderFormDto;
import com.bs.yzm.entity.dto.OrderSearchDto;
import com.bs.yzm.entity.pojo.YzmOrder;
import com.bs.yzm.entity.vo.OrderPageVO;
import com.bs.yzm.service.intf.YzmOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author pzh
*/
@Slf4j
@RestController
@Api(tags = "供应商模块操作接口")
@RequestMapping("api/v1/order")
public class OrderController {
@Resource
private YzmOrderService yzmOrderService;
@GetMapping("/list")
@ApiOperation("返回订单详情分页接口")
public LayPage<OrderPageVO> selectSupplierList(
@RequestParam Integer page, @RequestParam Integer limit) {
log.info("page is {},limit is {}", page, limit);
return yzmOrderService.selectPageList(page, limit);
}
@PostMapping("/search")
@ApiOperation("根据不同条件查询订单")
public LayPage<OrderPageVO> searchOrder(@RequestBody OrderSearchDto orderSearchDto) {
return yzmOrderService.searchByOrderCondition(orderSearchDto);
}
@PostMapping("/update")
@ApiOperation("更新订单")
public ResponseEntity<Boolean> updateOrder(
@RequestBody OrderFormDto orderFormDto) {
YzmOrder yzmOrder = new YzmOrder();
BeanUtils.copyProperties(orderFormDto, yzmOrder);
return new ResponseEntity<>(yzmOrderService.updateById(yzmOrder), HttpStatus.OK);
}
@PostMapping("/del")
@ApiOperation("删除订单")
public ResponseEntity<Boolean> deleteOrder(@RequestBody List<Long> idList) {
log.info("delete order id list is {}", idList);
return new ResponseEntity<>(yzmOrderService.removeByIds(idList), HttpStatus.OK);
}
@PostMapping("")
@ApiOperation("创建订单")
public ResponseEntity<Boolean> createOrder(@RequestBody NOrderDto nOrderDto) {
return new ResponseEntity<>(yzmOrderService.createOrder(nOrderDto), HttpStatus.OK);
}
}
package com.bs.yzm.controller;
import com.bs.yzm.entity.common.LayPage;
import com.bs.yzm.entity.dto.ProductFormDto;
import com.bs.yzm.entity.dto.ProductSearchDto;
import com.bs.yzm.entity.vo.YzmProductVo;
import com.bs.yzm.service.intf.YzmProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author pzh
* createTime:2022/01/26/9:37
*/
@Slf4j
@RestController
@Api(tags = "产品模块操作接口")
@RequestMapping("api/v1/product")
public class ProductController {
@Resource
private YzmProductService yzmProductService;
@GetMapping("/list")
@ApiOperation("返回供应商详情分页接口")
public LayPage<YzmProductVo> selectSupplierList(
@RequestParam Integer page, @RequestParam Integer limit) {
log.info("page is {},limit is {}", page, limit);
return yzmProductService.selectPageList(page, limit);
}
@PostMapping()
@ApiOperation("添加生鲜接口")
public ResponseEntity<Boolean> insertFresh(
@RequestBody ProductFormDto productFormDto) {
return new ResponseEntity<>(yzmProductService.saveProduceByCategory(productFormDto.convertProduct()),
HttpStatus.OK);
}
@PostMapping("/update")
@ApiOperation("更新供应商信息")
public ResponseEntity<Boolean> updateProduct(
@RequestBody ProductFormDto productFormDto) {
return new ResponseEntity<>(yzmProductService.updateById(productFormDto.convertProduct()),
HttpStatus.OK);
}
@PostMapping("/search")
@ApiOperation("根据不同条件查询供应商信息")
public LayPage<YzmProductVo> searchSupplier(@RequestBody ProductSearchDto productSearchDto) {
return yzmProductService.searchByProductCondition(productSearchDto);
}
@PostMapping("/del")
@ApiOperation("删除产品信息")
public ResponseEntity<Boolean> deleteProduct(@RequestBody List<Long> productIdList) {
return new ResponseEntity<>(yzmProductService.removeByIds(productIdList), HttpStatus.OK);
}
}