Mybatis-plus简单配置

北城余情 提交于 2020-02-25 18:58:07

.pom文件

<!-- mybatis-plus -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.2.0</version>
</dependency>

 mybatis-plus配置

package com.example.baseproject.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }
}

 实体类

package com.example.baseproject.pojo;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import java.math.BigDecimal;

/**
 * 水果实体类
 */
@Data
@TableName(value="go_fruits",autoResultMap = true)
public class FruitsEntity extends Model<FruitsEntity> {
    /**
     * id
     */
    @TableId(type = IdType.INPUT)
    private Integer fId;
    /**
     * 水果类型
     */
    private String fType;
    /**
     * 水果名称
     */
    //增加查询条件
    @TableField(condition = SqlCondition.LIKE)
    private String fName;
    /**
     * 水果价格
     */
    private BigDecimal fPrice;
    /**
     * 菜单数量
     */
    private String fNum;
    /**
     * 删除标识
     */
    @TableLogic
    @TableField(exist = false)
    private Integer delFlag;
    private String createTime;
}

service

package com.example.baseproject.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.baseproject.pojo.FruitsEntity;

public interface FruitsService extends IService<FruitsEntity> {

}

serviceImpl

package com.example.baseproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.baseproject.dao.FruitsMapper;
import com.example.baseproject.pojo.FruitsEntity;
import com.example.baseproject.service.FruitsService;
import org.springframework.stereotype.Service;

@Service
public class FruitsServiceImpl extends ServiceImpl<FruitsMapper, FruitsEntity> implements FruitsService {

}

 dao

package com.example.baseproject.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.baseproject.pojo.FruitsEntity;

public interface FruitsMapper extends BaseMapper<FruitsEntity> {

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!