简单的增删改查(后端)

23 阅读2分钟

image.png

controller.CheckInformationController

package com.lc.modules.fin.checkInformation.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lc.modules.fin.checkInformation.entity.CheckInformation;
import com.lc.modules.fin.checkInformation.mapper.CheckInformationMapper;
import com.lc.modules.fin.checkInformation.service.ICheckInformationService;
import com.lc.modules.fin.system.entity.DocumentItemConfig;
import org.apache.catalina.User;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/checkInformation")

public class CheckInformationController {
    @Autowired
    CheckInformationMapper mapper;
//     @Resource 需要注入才能使用 ICheckInformationService
    @Resource
    ICheckInformationService iCheckInformationService;
    @GetMapping(value = "/getCheckInformationList")
    public Result checkInformationDataQuery(@RequestParam(name = "orgId", required = true) String orgId,
                                                 @RequestParam(name = "pageNo", required = true) Integer pageNo,
                                                 @RequestParam(name = "pageSize", required = true) Integer pageSize,
                                                     @RequestParam(name = "keyword", required = false) String keyword
                                                                                                    ) {
//        定义一个分页的功能
        Result<IPage<CheckInformation>> result = new Result<>();
//        定义获取数据库的表
        LambdaQueryWrapper<CheckInformation> queryWrapper=new LambdaQueryWrapper<>();
//        将参数orgId去查询数据库中的数据
        queryWrapper.eq(CheckInformation::getOrgId,orgId).orderByDesc(CheckInformation::getOperateTime);
        if(StringUtils.isNotBlank(keyword)){
            queryWrapper.like(CheckInformation::getPayee,keyword).
                    or().like(CheckInformation::getAmount,keyword).
                    or().like(CheckInformation::getPurpose,keyword).
                    or().like(CheckInformation::getCreateBy,keyword).
                    or().like(CheckInformation::getCreateBy,keyword).
                    or().like(CheckInformation::getOperateTime,keyword).
                    or().like(CheckInformation::getChequeNum,keyword).
                    or().like(CheckInformation::getIssuingBankNum,keyword).
                    or().like(CheckInformation::getDraftData,keyword);
        }
//        定义一个查询到表的列表的pageList
        IPage<CheckInformation> pageList = null;
//        定义并将传入的page数据赋值
        Page<CheckInformation> page = new Page<CheckInformation>(pageNo, pageSize);
//        将根据参数搜索到的数据赋值给pageList
        pageList = mapper.selectPage(page, queryWrapper);
//        返回pagelist数据给前端
        result.setResult(pageList);
        return result;
    }
//    @GetMapping(value = "/getList")
//    public List<CheckInformation> getUsers(){
//        return  mapper.selectList( null);
//    }
    @PostMapping(value = "/addCheckInformationList")
    public Boolean saveUser(@RequestBody CheckInformation checkInformation){
        System.out.println(checkInformation);
        int i = mapper.insert(checkInformation);

        return i == 1;
    }
    @PutMapping(value = "/updateCheckInformationList/{uid}")
    public Boolean updateUser(@PathVariable("uid") String uid ,@RequestBody CheckInformation checkInformation){
        System.out.println(checkInformation);
//        updateById 只根据id来进行修改  上面的参数与他无关
        int update =mapper.updateById(checkInformation);
        return update == 1;
    }

    @DeleteMapping(value = "/delList/{id}")
    public Boolean deleteUser(@PathVariable("id") String id) {
        int delete = mapper.deleteById(id);
        return delete == 1;
    }
//public List<checkInformation> deleteUser(@PathVariable("id") String id){
//    return mapper.deleteById(id);
//}
}

entity.CheckInformation

package com.lc.modules.fin.checkInformation.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;

import java.io.Serializable;
import java.util.Date;
/**
 * 实体类
 * @description 支票信息配置
 * @author 支票信息配置
 * @Date 2023.04.24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("check_information")
public class CheckInformation implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(value = "ID", type = IdType.ASSIGN_ID)
    private String id;
    private String createBy;
    private Date createTime;
    private String orgId;
    private String workstation;

    private String uid;
    private String payee;
    private String amount;
    private String purpose;
    private String draftData;
    private String operator;
    private String chequeNum;
    private String operateTime;
    private String issuingBankNum;
    private boolean disabled;
}

mapper.CheckInformationMapper

package com.lc.modules.fin.checkInformation.mapper;

        import com.lc.modules.fin.checkInformation.entity.CheckInformation;
        import com.baomidou.mybatisplus.core.mapper.BaseMapper;
        import org.apache.ibatis.annotations.Mapper;

        import java.util.List;
//查询所有的方法
@Mapper

public interface CheckInformationMapper extends BaseMapper<CheckInformation>{

}

mapper.xml.CheckInformation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lc.modules.fin.checkInformation.mapper">



</mapper>

service.ICheckInformationService

package com.lc.modules.fin.checkInformation.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.lc.modules.fin.checkInformation.entity.CheckInformation;


/**
 * 业务(服务)接口
 * @description 支票信息配置
 * @author 支票信息配置
 * @Date 2023-04-24
 */



public interface ICheckInformationService extends IService<CheckInformation> {

}

service.impl.ICheckInformationServiceImpl

package com.lc.modules.fin.checkInformation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.modules.fin.checkInformation.entity.CheckInformation;
import com.lc.modules.fin.checkInformation.mapper.CheckInformationMapper;
import com.lc.modules.fin.checkInformation.service.ICheckInformationService;
import org.springframework.stereotype.Service;

@Service
public class ICheckInformationServiceImpl extends ServiceImpl<CheckInformationMapper, CheckInformation> implements ICheckInformationService {


}

数据库表头

CREATE TABLE "check_information"
(
"id" VARCHAR(100) NOT NULL,
"payee" VARCHAR(150),
"amount" VARCHAR(150),
"purpose" VARCHAR(150),
"draft_data" VARCHAR(150),
"operator" VARCHAR(150),
"cheque_num" VARCHAR(60),
"operate_time" VARCHAR(60),
"UID" VARCHAR(150) NOT NULL,
"CREATE_BY" VARCHAR(150),
"CREATE_TIME" TIMESTAMP(0),
"ORG_ID" VARCHAR(150),
"WORKSTATION" VARCHAR(200) DEFAULT '',
"disabled" BIT DEFAULT 0,
"issuing_bank_num" VARCHAR(100)) STORAGE(ON "MAIN", CLUSTERBTR) ;