目录
一、后端
1.1实体类
1.2paperMapper类
1.3 PaperMapper类
1.4Service层
1.5 Controller层
二、前端
源代码
我们已经实现列表数据了,接下来我们将实现增删查改功能,新增和修改还能够回显
实体类还是我们上一版的列表功能的实现的paper实体类

代码附在上一版中

delete from t_paper where id=#{id} insert into t_paper (title, type_id,created_by) values ( #{title}, #{typeId}, #{createdBy}) update t_paper set title=#{title}, type_id=#{typeId}, created_by=#{createdBy} where id=#{id}

package com.woniu.paper.mapper;import com.woniu.paper.entity.HttpResult;
import com.woniu.paper.entity.Paper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;import java.net.HttpCookie;
import java.util.List;/*** * Mapper 接口*
** @author zhang* @since 2022-11-18*/
public interface PaperMapper extends BaseMapper {List selectPaperListByCondition(String title, String typeName, int start, int size);int count(String title, String typeName);//查询总数,用于列表分页//根据id获取论文信息的接口Paper getPaperByid(Long id);//根据id删除论文的接口int deletePaperById(Long id);//添加论文int insertPaper(Paper paper);//根据id修改论文int updatePaperById(Paper paper);}
接口
package com.woniu.paper.service;import com.woniu.paper.entity.HttpResult;
import com.woniu.paper.entity.Paper;
import com.baomidou.mybatisplus.extension.service.IService;/*** * 服务类*
** @author zhang* @since 2022-11-18*/
public interface IPaperService {public HttpResult selectPaperListByCondition(String title, String typeName, int pageIndex, int pageSize);// public HttpResult insertPaper(String title,Long typeId,String paperSummary,String paperPath,String createdBy,String modifyBy,String fileName);HttpResult getPaperByid(Long id);HttpResult deletePaperById(Long id);HttpResult insertPaper(Paper paper);HttpResult updatePaperById(Paper paper);
}
实现类
package com.woniu.paper.service.impl;import com.woniu.paper.entity.HttpResult;
import com.woniu.paper.entity.Paper;
import com.woniu.paper.mapper.PaperMapper;
import com.woniu.paper.mapper.UserMapper;
import com.woniu.paper.service.IPaperService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;/*** * 服务实现类*
** @author zhang* @since 2022-11-18*/
@Service
public class PaperServiceImpl implements IPaperService {@Autowired(required = false)private PaperMapper paperMapper;//实例化DAO对象@Overridepublic HttpResult selectPaperListByCondition(String title, String typeName, int pageIndex, int pageSize) {List papers = paperMapper.selectPaperListByCondition(title, typeName, (pageIndex - 1) * pageSize, pageSize);int count = paperMapper.count(title, typeName);HttpResult result=null;if (papers!=null&&papers.size()>0){result= new HttpResult(papers,count,200,null);}else{result= new HttpResult(null,0,500,"没有更多数据");}return result;}@Overridepublic HttpResult getPaperByid(Long id) {Paper paper = paperMapper.getPaperByid(id);HttpResult result=null;if (paper!=null){result= new HttpResult(paper,0,200,null);}else{result= new HttpResult(null,0,500,"没有更多数据");}return result;}@Overridepublic HttpResult deletePaperById(Long id) {int count = paperMapper.deletePaperById(id);HttpResult result=null;if (count>0){result=new HttpResult(null,0,200,"删除论文成功");}else{result=new HttpResult(null,0,500,"删除论文失败");}return result;}@Overridepublic HttpResult insertPaper(Paper paper) {int count = paperMapper.insertPaper(paper);HttpResult result=null;if (count>0){result=new HttpResult(null,0,200,"添加论文成功");}else{result=new HttpResult(null,0,500,"添加论文失败");}return result;}@Overridepublic HttpResult updatePaperById(Paper paper) {int count = paperMapper.updatePaperById(paper);HttpResult result = null;if(count > 0){result = new HttpResult(null, 0, 200, "修改论文成功");} else {result = new HttpResult(null, 0, 500, "修改论文失败");}return result;}}

package com.woniu.paper.controller;import com.woniu.paper.entity.HttpResult;
import com.woniu.paper.entity.Paper;
import com.woniu.paper.service.IPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.origin.Origin;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;/*** * 前端控制器*
** @author zhang* @since 2022-11-18*/
@RestController
@RequestMapping("/paper/paper")
public class PaperController {@Autowiredprivate IPaperService paperService;//实例化Service对象/*** 根据分页查询论文列表* @return*/@RequestMapping("/list")@CrossOrigin(origins = "*")public HttpResult selectPaperListByCondition(String title,String typeName,int pageIndex,int pageSize) {return paperService.selectPaperListByCondition(title,typeName,pageIndex,pageSize);}/*** 根据id查询论文信息*/@RequestMapping("/info")@CrossOrigin(origins = "*")public HttpResult getPaperByid(Long id){return paperService.getPaperByid(id);}/*** 根据id删除论文* @param id* @return*/@RequestMapping("/delete")@CrossOrigin(origins = "*")public HttpResult deletePaperById(Long id){return paperService.deletePaperById(id);}/*** 增加论文数量*/@RequestMapping("/add")@CrossOrigin(origins = "*")public HttpResult insertPaper(String title,String createdBy,Long typeId){Paper paper = new Paper();paper.setTitle(title);paper.setCreatedBy(createdBy);paper.setTypeId(typeId);return paperService.insertPaper(paper);}@RequestMapping("/update")@CrossOrigin(origins = "*")public HttpResult updatePaperById(Long id,String title,String createdBy,Long typeId){Paper paper = new Paper();paper.setId(id);paper.setTitle(title);paper.setCreatedBy(createdBy);paper.setTypeId(typeId);return paperService.updatePaperById(paper);}}
这就是我们增删改查的后端部分,接下来,我们将来写前端部分
Title
上一篇:描写音乐的句子有什么