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

若依前端分离版整合mybatis-plus

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

若依前端分离版整合mybatis-plus

基本上参考官帮助文档就可以http://doc.ruoyi.vip/ruoyi-vue/document/cjjc.html#%E9%9B%86%E6%88%90mybatisplus%E5%AE%9E%E7%8E%B0mybatis%E5%A2%9E%E5%BC%BA

1.ruoyi-commonpom.xml模块添加整合依赖添加依赖。打开mybatisplus官网,用最新的MyBatis-Plus

        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.5.1
        

2.ruoyi-admin文件application.yml,修改mybatis配置为mybatis-plus。将mybatis 改成mybatis-plus就行了

# MyBatis Plus配置
mybatis-plus:
  # 搜索指定包别名
  typeAliasesPackage: com.ruoyi.**.domain
  # 配置mapper的扫描,找到所有的mapper.xml映射文件
  mapperLocations: classpath*:mapper*Mapper.xml
  # 加载全局的配置文件
  configLocation: classpath:mybatis/mybatis-config.xml

3.ruoyi-framework/config/添加Mybatis Plus配置MybatisPlusConfig.java。 原来的MyBatisConfig.java需要删除掉。

package com.ruoyi.framework.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;


@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
public class MybatisPlusConfig
{
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor()
    {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 分页插件
        interceptor.addInnerInterceptor(paginationInnerInterceptor());
        // 乐观锁插件
        interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
        // 阻断插件
        interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
        return interceptor;
    }

    
    public PaginationInnerInterceptor paginationInnerInterceptor()
    {
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        // 设置数据库类型为mysql
        paginationInnerInterceptor.setDbType(DbType.MYSQL);
        // 设置最大单页限制数量,默认 500 条,-1 不受限制
        paginationInnerInterceptor.setMaxLimit(-1L);
        return paginationInnerInterceptor;
    }

    
    public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor()
    {
        return new OptimisticLockerInnerInterceptor();
    }

    
    public BlockAttackInnerInterceptor blockAttackInnerInterceptor()
    {
        return new BlockAttackInnerInterceptor();
    }
}

4.以上就集成完了,下面改domain.加上
@TableName(value="sysUser")
在ID字段上加 @TableId(type=IdType.AUTO)

//这里
@TableName(value = "sys_student")
public class SysStudent implements Serializable
{
//这里
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    
//这里
    @TableId(type = IdType.AUTO)

5.修改服务层I...Service.java,加上extends IService<>

public interface ISysStudentService extends IService

6.修改mapper,加上extends BaseMapper<实体类名称>

public interface SysStudentMapper extends BaseMapper

7.修改服务实现层:....ServiceImpl.java , 加上extends ServiceImpl< , >

public class SysStudentServiceImpl extends ServiceImpl implements ISysStudentService
{

8.domina 中还 继承有一个BaseEntity,打开它修改,给每一个不存在的字段都加上@TableField(exist = false)

**
 * Entity基类
 * 
 * @author ruoyi
 */
public class BaseEntity implements Serializable
{
    private static final long serialVersionUID = 1L;

    
    @TableField(exist = false)
    private String searchValue;

    
    @TableField(exist = false)
    private String createBy;

    
    @TableField(exist = false)
    private  Integer idCreatBy;

    
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    
    @TableField(exist = false)
    private String updateBy;

    
    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    
    @TableField(exist = false)
    private String remark;

    
    @TableField(exist = false)
    private Map params;

9.修改代码生成器。domain.java.vm

@TableName("${tableName}") //添加
#if($table.crud || $table.sub)
#set($Entity="BaseEntity")
#elseif($table.tree)
#set($Entity="TreeEntity")
#end
public class ${ClassName} extends ${Entity} implements Serializable //修改
{
............

#else
    @Excel(name = "${comment}")
#end
#end
//这里
#if($column.isPk==1)
    @TableId
#end
    private $column.javaType $column.javaField;

#end

.............

10.修改mapper.java.vm

package ${packageName}.mapper;

import java.util.List;
import ${packageName}.domain.${ClassName};
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
#if($table.sub)
import ${packageName}.domain.${subClassName};
#end


public interface ${ClassName}Mapper extends BaseMapper<${ClassName}>
...........

11.修改serviceImpl.java.vm

package ${packageName}.service.impl;

import java.util.List;
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.ruoyi.common.utils.DateUtils;
#break
#end
#end
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
#if($table.sub)
import java.util.ArrayList;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;//导包
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import ${packageName}.domain.${subClassName};
#end
import ${packageName}.mapper.${ClassName}Mapper;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;


@Service
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service //修改

12.修改service.java.vm

package ${packageName}.service;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import ${packageName}.domain.${ClassName};


public interface I${ClassName}Service extends IService<${ClassName}>
{

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

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

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