栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

一个springboot+mybatisplus+vue实现的增删改查加多条件查询加分页

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一个springboot+mybatisplus+vue实现的增删改查加多条件查询加分页

0.一个小Demo 就没有用到其它的技术了 格式如下

表文件
create table FinancingProduct
(
    id           varchar(50) not null
        primary key,
    risk         int         not null,
    income       varchar(50) not null,
    saleStarting datetime    not null,
    saleEnd      datetime    not null,
    end          datetime    not null
);

pom配置
  
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-devtools
            runtime
            true
        
        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.3.1.tmp
        

        

        
            mysql
            mysql-connector-java
            runtime
        
        
        
            com.baomidou
            mybatis-plus-generator
            3.4.1
        

        
            org.apache.velocity
            velocity
            1.7
        
        

        
            com.alibaba
            druid-spring-boot-starter
            1.2.8
        
        
            org.springframework.boot
            spring-boot-configuration-processor
            true
        
        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.4.1
        
    
application.yml配置
#设置端口号
server:
  port: 8080
#配置数据源
spring:
  datasource:
    username: root
    password: newPassword
    #url中database为对应的数据库名称
    url: jdbc:mysql://IP地址/fina?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
    driver-class-name: com.mysql.cj.jdbc.Driver
    #连接池
    type: com.alibaba.druid.pool.DruidDataSource
    #释放静态资源
  mvc:
    static-path-pattern: /static
@Data
  @EqualsAndHashCode(callSuper = false)
    @TableName("FinancingProduct")
public class Financingproduct implements Serializable {

    private static final long serialVersionUID = 1L;

    private String id;
	//跟枚举类对应
    private TypeEnum risk;

    private String income;

    @TableField("saleStarting")
    private LocalDateTime salestarting;

    @TableField("saleEnd")
    private LocalDateTime saleend;

    private LocalDateTime end;


}

创建vo
FinancingproductVo类
package com.hexu.demo666.entity.vo;

import lombok.Data;


@Data
public class FinancingproductVo {
    //条件Id
    private String id;
    //条件类型
    private String risk;
    //页码
    private Integer pageNum = 1;
    //数量
    private Integer pageSize = 3;
}

创建枚举
typeEnum类
package com.hexu.demo666.entity.typeEnum;


import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;


public enum TypeEnum {


    YI(1, "R1"),
    ER(2, "R2"),
    SAN(3, "R3");

    @EnumValue
    private Integer key;

    @JsonValue
    private String display;

    TypeEnum(Integer key, String display) {
        this.key = key;
        this.display = display;
    }

    public Integer getKey() {
        return key;
    }

    public String getDisplay() {
        return display;
    }
}
2.持久层 创建mapper
FinancingproductMapper类
package com.hexu.demo666.mapper;

import com.baomidou.mybatisplus.core.mapper.baseMapper;
import com.hexu.demo666.entity.Financingproduct;


public interface FinancingproductMapper extends baseMapper {

}

3.业务层 创建service
FinancingproductService类
package com.hexu.demo666.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.hexu.demo666.entity.Financingproduct;


public interface FinancingproductService extends IService {

}

实现类
package com.hexu.demo666.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hexu.demo666.entity.Financingproduct;
import com.hexu.demo666.mapper.FinancingproductMapper;
import com.hexu.demo666.service.FinancingproductService;
import org.springframework.stereotype.Service;


@Service
public class FinancingproductServiceImpl extends ServiceImpl implements FinancingproductService {

}

4.工具类 ResponseMessage统一返回格式类
ResponseMessage类
package com.hexu.demo666.util;

import java.util.HashMap;
import java.util.Map;


public class ResponseMessage {
    private String errorCode;
    private String errorMsg;
    private Map objectMap = new HashMap<>();

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Map getObjectMap() {
        return objectMap;
    }

    public void setObjectMap(Map objectMap) {
        this.objectMap = objectMap;
    }

    public ResponseMessage addObject(String key, Object value) {
        this.objectMap.put(key, value);
        return this;
    }

    public static ResponseMessage success() {
        ResponseMessage rm = new ResponseMessage();
        rm.setErrorCode("100");
        rm.setErrorMsg("处理成功");
        return rm;
    }

    public static ResponseMessage error() {
        ResponseMessage rm = new ResponseMessage();
        rm.setErrorCode("200");
        rm.setErrorMsg("处理失败");
        return rm;
    }
}

5.控制层 FinancingproductController类
package com.hexu.demo666.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hexu.demo666.entity.Financingproduct;
import com.hexu.demo666.entity.vo.FinancingproductVo;
import com.hexu.demo666.service.FinancingproductService;
import com.hexu.demo666.util.ResponseMessage;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@Controller
public class FinancingproductController {

    @Resource
    private FinancingproductService financingproductService;

    
    @PostMapping("/getAllger")
    @ResponseBody
    public ResponseMessage getAllger(@RequestBody FinancingproductVo vo) {
        //分页设置
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        //进行条件查询
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (vo.getId() != null && !"".equals(vo.getId())) {
            queryWrapper.like("id", vo.getId());
        }
        if (vo.getRisk() != null && !"".equals(vo.getRisk())) {
            queryWrapper.eq("risk", vo.getRisk());
        }
        List list = financingproductService.list(queryWrapper);

        PageInfo pageInfo = new PageInfo<>(list);
        //统一返回格式
        return ResponseMessage.success().addObject("list", pageInfo);
    }

    
    @GetMapping("/deleteById/{id}")
    @ResponseBody
    public ResponseMessage deleteById(@PathVariable Integer id) {
        Assert.notNull(id, "不能为null");
        boolean b = financingproductService.removeById(id);
        return b ? ResponseMessage.success() : ResponseMessage.error();
    }

    
    @PostMapping("/addAll")
    @ResponseBody
    public ResponseMessage addAll(@RequestBody Financingproduct financingproduct) {
        boolean save = financingproductService.save(financingproduct);
        return save ? ResponseMessage.success() : ResponseMessage.error();
    }

    
    @PostMapping("/getById/{id}")
    @ResponseBody
    public ResponseMessage getById(@PathVariable Integer id) {
        Assert.notNull(id, "不能为null");

        Financingproduct byId = financingproductService.getById(id);
        return ResponseMessage.success().addObject("list", byId);
    }

    
    @PostMapping("/updateById")
    @ResponseBody
    public ResponseMessage updateById(@RequestBody Financingproduct financingproduct) {
        boolean b = financingproductService.updateById(financingproduct);
        return b ? ResponseMessage.success() : ResponseMessage.error();
    }
    //以下是跳转
    @RequestMapping("/in")
    public String index() {
        return "index";
    }

    @RequestMapping("/update")
    public String update() {
        return "update";
    }

    @RequestMapping("/add")
    public String add() {
        return "add";
    }

}


前端 前端index页面
index.html



    
    Title


产品代码 风险评级
产品代码 风险评级 预期收益 起始日 截止日 到期日 操作
{{fina.id}} {{fina.risk}} {{fina.income}} {{finasalestarting}} {{fina.saleend}} {{fina.end}} 删除 修改
增加 {{list1.pageNum}} / {{list1.pages}} 下一页 上一页 第一页 最后一页
add页面
add.html



    
    Title


产品代码 风险评级 预期收益 起始日 截止日 到期日

{{financingproduct}}

update页面
update.html



    
    Title


产品代码 风险评级 预期收益 起始日 截止日 到期日
前后端分离跨域为解决
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
                .maxAge(3600);
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/685427.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号