主要就是mybatis-plus使用,以及前端表单验证。
优点:
Mybatis-Plus(简称MP)是一个 Mybatis 的增强工具,在 Mybatis 的基础上只做增强不做改变,为简化开发、提高效率而生。参考mybatis-plus官网。其实就是它已经封装好了一些crud方法,我们不需要再写xml了,直接调用这些方法就行,就类似于JPA。
效果图:
主要依赖:
com.baomidou
mybatis-plus-boot-starter
2.3.1
直接在配置文件添加配置参数即可:
spring:
......
mybatis-plus:
global-config:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
id-type: 0
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy: 2
#驼峰下划线转换
db-column-underline: true
#刷新mapper 调试神器
refresh-mapper: true
#数据库大写下划线转换
#capital-mode: true
#序列接口实现类配置
#key-generator: com.baomidou.springboot.xxx
#逻辑删除配置
#logic-delete-value: 0
#logic-not-delete-value: 1
#自定义填充策略接口实现
#meta-object-handler: com.umeox.waas.domain.handler.MyMetaObjectHandler
#自定义SQL注入器
#sql-injector: com.baomidou.springboot.xxx
configuration:
map-underscore-to-camel-case: true #entity类字段名映射表字段名
cache-enabled: false
MyBatis-Plus使用:
public interface IService {
/**
*
* 插入一条记录(选择字段,策略插入)
*
*
* @param entity 实体对象
* @return boolean
*/
boolean insert(T entity);
/**
*
* 插入一条记录(全部字段)
*
*
* @param entity 实体对象
* @return boolean
*/
boolean insertAllColumn(T entity);
/**
*
* 插入(批量),该方法不适合 Oracle
*
*
* @param entityList 实体对象列表
* @return boolean
*/
boolean insertBatch(List entityList);
/**
*
* 插入(批量)
*
*
* @param entityList 实体对象列表
* @param batchSize 插入批次数量
* @return boolean
*/
boolean insertBatch(List entityList, int batchSize);
/**
*
* 批量修改插入
*
*
* @param entityList 实体对象列表
* @return boolean
*/
boolean insertOrUpdateBatch(List entityList);
/**
*
* 批量修改插入
*
*
* @param entityList 实体对象列表
* @param batchSize
* @return boolean
*/
boolean insertOrUpdateBatch(List entityList, int batchSize);
/**
*
* 批量修改或插入全部字段
*
*
* @param entityList 实体对象列表
* @return boolean
*/
boolean insertOrUpdateAllColumnBatch(List entityList);
/**
* 批量修改或插入全部字段
*
* @param entityList 实体对象列表
* @param batchSize
* @return boolean
*/
boolean insertOrUpdateAllColumnBatch(List entityList, int batchSize);
/**
*
* 根据 ID 删除
*
*
* @param id 主键ID
* @return boolean
*/
boolean deleteById(Serializable id);
/**
*
* 根据 columnMap 条件,删除记录
*
*
* @param columnMap 表字段 map 对象
* @return boolean
*/
boolean deleteByMap(Map columnMap);
/**
*
* 根据 entity 条件,删除记录
*
*
* @param wrapper 实体包装类 {@link Wrapper}
* @return boolean
*/
boolean delete(Wrapper wrapper);
/**
*
* 删除(根据ID 批量删除)
*
*
* @param idList 主键ID列表
* @return boolean
*/
boolean deleteBatchIds(Collection extends Serializable> idList);
/**
*
* 根据 ID 选择修改
*
*
* @param entity 实体对象
* @return boolean
*/
boolean updateById(T entity);
/**
*
* 根据 ID 修改全部字段
*
*
* @param entity 实体对象
* @return boolean
*/
boolean updateAllColumnById(T entity);
/**
*
* 根据 whereEntity 条件,更新记录
*
*
* @param entity 实体对象
* @param wrapper 实体包装类 {@link Wrapper}
* @return boolean
*/
boolean update(T entity, Wrapper wrapper);
/**
*
* 根据 whereEntity 条件,自定义set值更新记录
*
*
* @param setStr set值字符串
* @param wrapper 实体包装类 {@link Wrapper}
* @return boolean
*/
boolean updateForSet(String setStr, Wrapper wrapper);
/**
*
* 根据ID 批量更新
*
*
* @param entityList 实体对象列表
* @return boolean
*/
boolean updateBatchById(List entityList);
/**
*
* 根据ID 批量更新
*
*
* @param entityList 实体对象列表
* @param batchSize 更新批次数量
* @return boolean
*/
boolean updateBatchById(List entityList, int batchSize);
/**
*
* 根据ID 批量更新全部字段
*
*
* @param entityList 实体对象列表
* @return boolean
*/
boolean updateAllColumnBatchById(List entityList);
/**
*
* 根据ID 批量更新全部字段
*
*
* @param entityList 实体对象列表
* @param batchSize 更新批次数量
* @return boolean
*/
boolean updateAllColumnBatchById(List entityList, int batchSize);
/**
*
* TableId 注解存在更新记录,否插入一条记录
*
*
* @param entity 实体对象
* @return boolean
*/
boolean insertOrUpdate(T entity);
/**
* 插入或修改一条记录的全部字段
*
* @param entity 实体对象
* @return boolean
*/
boolean insertOrUpdateAllColumn(T entity);
/**
*
* 根据 ID 查询
*
*
* @param id 主键ID
* @return T
*/
T selectById(Serializable id);
/**
*
* 查询(根据ID 批量查询)
*
*
* @param idList 主键ID列表
* @return List
*/
List selectBatchIds(Collection extends Serializable> idList);
/**
*
* 查询(根据 columnMap 条件)
*
*
* @param columnMap 表字段 map 对象
* @return List
*/
List selectByMap(Map columnMap);
/**
*
* 根据 Wrapper,查询一条记录
*
*
* @param wrapper 实体对象
* @return T
*/
T selectOne(Wrapper wrapper);
/**
*
* 根据 Wrapper,查询一条记录
*
*
* @param wrapper {@link Wrapper}
* @return Map
*/
Map selectMap(Wrapper wrapper);
/**
*
* 根据 Wrapper,查询一条记录
*
*
* @param wrapper {@link Wrapper}
* @return Object
*/
Object selectObj(Wrapper wrapper);
/**
*
* 根据 Wrapper 条件,查询总记录数
*
*
* @param wrapper 实体对象
* @return int
*/
int selectCount(Wrapper wrapper);
/**
*
* 查询列表
*
*
* @param wrapper 实体包装类 {@link Wrapper}
* @return
*/
List selectList(Wrapper wrapper);
/**
*
* 翻页查询
*
*
* @param page 翻页对象
* @return
*/
Page selectPage(Page page);
/**
*
* 查询列表
*
*
* @param wrapper {@link Wrapper}
* @return
*/
List
需要继承的基础接口,有默认的实现。(以菜单为例)
新增操作单个或者数组批量新增。直接调用相应的方法即可
修改, 根据ID修改。
只修改一个字段,或者某几个字段。
# 不为null的属性都会被修改。 反之如果不想修改的属性直接设置为null即可。
Menu menu = new Menu();
menu.setId(1);
menu.setName("新的名称")
menuRepository.updateById(menu);
# 相当于SQL语句。update menu set name = "新的名称" where id = 1;
不是根据ID修改的怎么处理呢?把所有的按钮设置为无效的。
Menu menu = new Menu();
menu.setStatus(false)
udpate(menu, new EntityWrapper
查询操作
根据ID查询一个:
Menu menu = this.selectById(1);
根据条件查询一个
Menu menu = selectOne(new EntityWrapper
当然也可以自己写SQL语句。多表关联查询时,需要自己定义SQL。
和mybatis使用方式一致。
前端表单校验
确定要删除这些菜单吗?
取消
确定
菜单
按钮
提交
取消