mybatis-plus 封裝本身格式的curd

mybatis-plus-extension-3.1.0.jarmybatis

com.baomidou.mybatisplus.extension.service.implapp

ServiceImpl 複製到項目中spa

添加本身的接口service實現類調用響應以下,便可生成規範的響應結構體code

/**
 * 自定義CRUD 單查詢
 * @param id
 * @return
 */
public BaseResponse selectById(Serializable id) {
	BaseResponse response = BaseResponse.Instance();
    T t = baseMapper.selectById(id);
    if(Objects.isNull(t)) {
    	response.CHANGE_STATUZ(Statuz.DATA_ERROR_404);
    } else {
    	response.addResult(extractClazzName(t.getClass().getName()), t);
    }
    return response;
}
/**
 * 自定義CRUD 建立單條記錄
 * @param id
 * @return
 */
public BaseResponse insert(T entity) {
	BaseResponse response = BaseResponse.Instance();
	Integer result = baseMapper.insert(entity);
	if(null != result || result < 1) {
		response.CHANGE_STATUZ(Statuz.SYS_ERROR);
	}
    return response;
}
複製代碼
相關文章
相關標籤/搜索