@ -1,42 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yshop</artifactId>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<version>2.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>MyBatisPlus模块</name>
|
||||
<artifactId>yshop-mproot</artifactId>
|
||||
|
||||
<properties>
|
||||
<jjwt.version>0.10.6</jjwt.version>
|
||||
<mybatis-plus-boot-starter.version>3.2.0</mybatis-plus-boot-starter.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus-boot-starter.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.2.5</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<groupId>org.mybatis</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<groupId>org.mybatis</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,81 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-6-4 13:52:30
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Query {
|
||||
|
||||
// Dong ZhaoYang 2017/8/7 基本对象的属性名
|
||||
String propName() default "";
|
||||
// Dong ZhaoYang 2017/8/7 查询方式
|
||||
Type type() default Type.EQUAL;
|
||||
|
||||
/**
|
||||
* 连接查询的属性名,如User类中的dept
|
||||
*/
|
||||
String joinName() default "";
|
||||
|
||||
/**
|
||||
* 默认左连接
|
||||
*/
|
||||
Join join() default Join.LEFT;
|
||||
|
||||
/**
|
||||
* 多字段模糊搜索,仅支持String类型字段,多个用逗号隔开, 如@Query(blurry = "email,username")
|
||||
*/
|
||||
String blurry() default "";
|
||||
|
||||
enum Type {
|
||||
// jie 2019/6/4 相等
|
||||
EQUAL
|
||||
// Dong ZhaoYang 2017/8/7 大于等于
|
||||
, GREATER_THAN
|
||||
// Dong ZhaoYang 2017/8/7 小于等于
|
||||
, LESS_THAN
|
||||
// Dong ZhaoYang 2017/8/7 中模糊查询
|
||||
, INNER_LIKE
|
||||
// Dong ZhaoYang 2017/8/7 左模糊查询
|
||||
, LEFT_LIKE
|
||||
// Dong ZhaoYang 2017/8/7 右模糊查询
|
||||
, RIGHT_LIKE
|
||||
// Dong ZhaoYang 2017/8/7 小于
|
||||
, LESS_THAN_NQ
|
||||
// jie 2019/6/4 包含
|
||||
, IN
|
||||
// 不等于
|
||||
,NOT_EQUAL
|
||||
// between
|
||||
,BETWEEN
|
||||
// 不为空
|
||||
,NOT_NULL
|
||||
// 查询时间
|
||||
,UNIX_TIMESTAMP
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* 适用于简单连接查询,复杂的请自定义该注解,或者使用sql查询
|
||||
*/
|
||||
enum Join {
|
||||
/** jie 2019-6-4 13:18:30 左右连接 */
|
||||
LEFT, RIGHT
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@ApiModel("BaseEntity")
|
||||
public abstract class BaseEntity implements Serializable{
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
* @author LionCity
|
||||
*/
|
||||
public interface CoreMapper<T> extends BaseMapper<T> {
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
|
||||
public interface BaseService<T> extends IService<T> {
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import co.yixiang.common.service.BaseService;
|
||||
import co.yixiang.common.web.param.OrderQueryParam;
|
||||
import co.yixiang.common.web.param.QueryParam;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @since 2019-10-16
|
||||
*/
|
||||
@Slf4j
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements BaseService<T> {
|
||||
|
||||
protected Page setPageParam(QueryParam queryParam) {
|
||||
return setPageParam(queryParam,null);
|
||||
}
|
||||
|
||||
protected Page setPageParam(QueryParam queryParam, OrderItem defaultOrder) {
|
||||
Page page = new Page();
|
||||
// 设置当前页码
|
||||
page.setCurrent(queryParam.getPage());
|
||||
// 设置页大小
|
||||
page.setSize(queryParam.getLimit());
|
||||
/**
|
||||
* 如果是queryParam是OrderQueryParam,并且不为空,则使用前端排序
|
||||
* 否则使用默认排序
|
||||
*/
|
||||
if (queryParam instanceof OrderQueryParam){
|
||||
OrderQueryParam orderQueryParam = (OrderQueryParam) queryParam;
|
||||
List<OrderItem> orderItems = orderQueryParam.getOrders();
|
||||
if (CollectionUtil.isEmpty(orderItems)){
|
||||
page.setOrders(Arrays.asList(defaultOrder));
|
||||
}else{
|
||||
page.setOrders(orderItems);
|
||||
}
|
||||
}else{
|
||||
page.setOrders(Arrays.asList(defaultOrder));
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
protected void getPage(Pageable pageable) {
|
||||
String order=null;
|
||||
if(pageable.getSort()!=null){
|
||||
order= pageable.getSort().toString();
|
||||
order=order.replace(":","");
|
||||
if("UNSORTED".equals(order)){
|
||||
order="id desc";
|
||||
}
|
||||
}
|
||||
PageHelper.startPage(pageable.getPageNumber()+1, pageable.getPageSize(),order);
|
||||
}
|
||||
|
||||
}
|
@ -1,218 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import co.yixiang.common.web.vo.Paging;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import co.yixiang.annotation.Query;
|
||||
|
||||
import javax.persistence.criteria.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Wrapper;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-6-4 14:59:48
|
||||
*/
|
||||
@Slf4j
|
||||
@SuppressWarnings({"unchecked", "all"})
|
||||
public class QueryHelpPlus {
|
||||
|
||||
public static <R, Q> QueryWrapper getPredicate(R obj, Q query) {
|
||||
QueryWrapper<R> queryWrapper = new QueryWrapper<R>();
|
||||
if (query == null) {
|
||||
return queryWrapper;
|
||||
}
|
||||
try {
|
||||
List<Field> fields = getAllFields(query.getClass(), new ArrayList<>());
|
||||
for (Field field : fields) {
|
||||
boolean accessible = field.isAccessible();
|
||||
field.setAccessible(true);
|
||||
Query q = field.getAnnotation(Query.class);
|
||||
if (q != null) {
|
||||
String propName = q.propName();
|
||||
String joinName = q.joinName();
|
||||
String blurry = q.blurry();
|
||||
String attributeName = isBlank(propName) ? field.getName() : propName;
|
||||
attributeName = humpToUnderline(attributeName);
|
||||
Class<?> fieldType = field.getType();
|
||||
Object val = field.get(query);
|
||||
if (ObjectUtil.isNull(val) || "".equals(val)) {
|
||||
continue;
|
||||
}
|
||||
Join join = null;
|
||||
// 模糊多字段
|
||||
if (ObjectUtil.isNotEmpty(blurry)) {
|
||||
String[] blurrys = blurry.split(",");
|
||||
//queryWrapper.or();
|
||||
queryWrapper.and(wrapper -> {
|
||||
for (int i=0;i< blurrys.length;i++) {
|
||||
String column = humpToUnderline(blurrys[i]);
|
||||
//if(i!=0){
|
||||
wrapper.or();
|
||||
//}
|
||||
wrapper.like(column, val.toString());
|
||||
}
|
||||
});
|
||||
continue;
|
||||
}
|
||||
/*if (ObjectUtil.isNotEmpty(joinName)) {
|
||||
String[] joinNames = joinName.split(">");
|
||||
for (String name : joinNames) {
|
||||
switch (q.join()) {
|
||||
case LEFT:
|
||||
if (ObjectUtil.isNotNull(join)) {
|
||||
join = join.join(name, JoinType.LEFT);
|
||||
} else {
|
||||
join = root.join(name, JoinType.LEFT);
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
if (ObjectUtil.isNotNull(join)) {
|
||||
join = join.join(name, JoinType.RIGHT);
|
||||
} else {
|
||||
join = root.join(name, JoinType.RIGHT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
String finalAttributeName = attributeName;
|
||||
switch (q.type()) {
|
||||
case EQUAL:
|
||||
//queryWrapper.and(wrapper -> wrapper.eq(finalAttributeName, val));
|
||||
queryWrapper.eq(attributeName, val);
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
queryWrapper.ge(finalAttributeName, val);
|
||||
break;
|
||||
case LESS_THAN:
|
||||
queryWrapper.le(finalAttributeName, val);
|
||||
break;
|
||||
case LESS_THAN_NQ:
|
||||
queryWrapper.lt(finalAttributeName, val);
|
||||
break;
|
||||
case INNER_LIKE:
|
||||
queryWrapper.like(finalAttributeName, val);
|
||||
break;
|
||||
case LEFT_LIKE:
|
||||
queryWrapper.likeLeft(finalAttributeName, val);
|
||||
break;
|
||||
case RIGHT_LIKE:
|
||||
queryWrapper.likeRight(finalAttributeName, val);
|
||||
break;
|
||||
case IN:
|
||||
if (CollUtil.isNotEmpty((Collection<Long>) val)) {
|
||||
queryWrapper.in(finalAttributeName, (Collection<Long>) val);
|
||||
}
|
||||
break;
|
||||
case NOT_EQUAL:
|
||||
queryWrapper.ne(finalAttributeName, val);
|
||||
break;
|
||||
case NOT_NULL:
|
||||
queryWrapper.isNotNull(finalAttributeName);
|
||||
break;
|
||||
case BETWEEN:
|
||||
List<Object> between = new ArrayList<>((List<Object>) val);
|
||||
queryWrapper.between(finalAttributeName, between.get(0), between.get(1));
|
||||
break;
|
||||
case UNIX_TIMESTAMP:
|
||||
List<Object> UNIX_TIMESTAMP = new ArrayList<>((List<Object>)val);
|
||||
if(!UNIX_TIMESTAMP.isEmpty()){
|
||||
SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
long time1 = fm.parse(UNIX_TIMESTAMP.get(0).toString()).getTime()/1000;
|
||||
long time2 = fm.parse(UNIX_TIMESTAMP.get(1).toString()).getTime()/1000;
|
||||
queryWrapper.between(finalAttributeName, time1, time2);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
field.setAccessible(accessible);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) {
|
||||
if (ObjectUtil.isNotEmpty(join)) {
|
||||
return join.get(attributeName);
|
||||
} else {
|
||||
return root.get(attributeName);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isBlank(final CharSequence cs) {
|
||||
int strLen;
|
||||
if (cs == null || (strLen = cs.length()) == 0) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if (!Character.isWhitespace(cs.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static List<Field> getAllFields(Class clazz, List<Field> fields) {
|
||||
if (clazz != null) {
|
||||
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
||||
getAllFields(clazz.getSuperclass(), fields);
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
/***
|
||||
* 驼峰命名转为下划线命名
|
||||
*
|
||||
* @param para
|
||||
* 驼峰命名的字符串
|
||||
*/
|
||||
|
||||
public static String humpToUnderline(String para) {
|
||||
StringBuilder sb = new StringBuilder(para);
|
||||
int temp = 0;//定位
|
||||
if (!para.contains("_")) {
|
||||
for (int i = 0; i < para.length(); i++) {
|
||||
if (Character.isUpperCase(para.charAt(i))) {
|
||||
sb.insert(i + temp, "_");
|
||||
temp += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
QueryWrapper<Paging> query = new QueryWrapper<Paging>();
|
||||
//query.or();
|
||||
query.or(wrapper -> wrapper.eq("store_id", 1).or().eq("store_id", 2));
|
||||
//query.like("a",1);
|
||||
//query.or();
|
||||
//query.like("b",2);
|
||||
//query.and(wrapper->wrapper.eq("c",1));
|
||||
query.eq("1", 1);
|
||||
|
||||
System.out.println(query.getSqlSegment());
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.web.param;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel("可排序查询参数对象")
|
||||
public abstract class OrderQueryParam extends QueryParam{
|
||||
private static final long serialVersionUID = 57714391204790143L;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private List<OrderItem> orders;
|
||||
|
||||
public void defaultOrder(OrderItem orderItem){
|
||||
this.defaultOrders(Arrays.asList(orderItem));
|
||||
}
|
||||
|
||||
public void defaultOrders(List<OrderItem> orderItems){
|
||||
if (CollectionUtil.isEmpty(orderItems)){
|
||||
return;
|
||||
}
|
||||
this.orders = orderItems;
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.web.param;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@Data
|
||||
@ApiModel("查询参数对象")
|
||||
public abstract class QueryParam implements Serializable{
|
||||
private static final long serialVersionUID = -3263921252635611410L;
|
||||
|
||||
@ApiModelProperty(value = "页码,默认为1")
|
||||
private Integer page =1;
|
||||
@ApiModelProperty(value = "页大小,默认为10")
|
||||
private Integer limit = 10;
|
||||
@ApiModelProperty(value = "搜索字符串")
|
||||
private String keyword;
|
||||
|
||||
public void setCurrent(Integer current) {
|
||||
if (current == null || current <= 0){
|
||||
this.page = 1;
|
||||
}else{
|
||||
this.page = current;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSize(Integer size) {
|
||||
if (size == null || size <= 0){
|
||||
this.limit = 10;
|
||||
}else{
|
||||
this.limit = size;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.common.web.vo;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ApiModel("分页")
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Paging<T> implements Serializable {
|
||||
private static final long serialVersionUID = -1683800405530086022L;
|
||||
|
||||
@ApiModelProperty("总行数")
|
||||
@JSONField(name = "total")
|
||||
@JsonProperty("total")
|
||||
private long total = 0;
|
||||
|
||||
@ApiModelProperty("数据列表")
|
||||
@JSONField(name = "records")
|
||||
@JsonProperty("records")
|
||||
private List<T> records = Collections.emptyList();
|
||||
|
||||
public Paging() {
|
||||
}
|
||||
|
||||
public Paging(IPage page) {
|
||||
this.total = page.getTotal();
|
||||
this.records = page.getRecords();
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<T> getRecords() {
|
||||
return records;
|
||||
}
|
||||
|
||||
public void setRecords(List<T> records) {
|
||||
this.records = records;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Paging{" +
|
||||
"total=" + total +
|
||||
", records=" + records +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.config;
|
||||
|
||||
/**
|
||||
* @author :LionCity
|
||||
* @date :Created in 2020-04-10 15:47
|
||||
* @description:自动注入时间处理
|
||||
* @modified By:
|
||||
* @version:
|
||||
*/
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 处理新增和更新的基础数据填充,配合BaseEntity和MyBatisPlusConfig使用
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MetaHandler implements MetaObjectHandler {
|
||||
|
||||
|
||||
/**
|
||||
* 新增数据执行
|
||||
*
|
||||
* @param metaObject
|
||||
*/
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
try {
|
||||
Timestamp time=new Timestamp(System.currentTimeMillis());
|
||||
if (metaObject.hasSetter("createTime")) {
|
||||
log.debug("自动插入 createTime");
|
||||
this.setFieldValByName("createTime", time, metaObject);
|
||||
}
|
||||
if (metaObject.hasSetter("updateTime")) {
|
||||
log.debug("自动插入 updateTime");
|
||||
this.setFieldValByName("updateTime", time, metaObject);
|
||||
}
|
||||
if (metaObject.hasSetter("createDate")) {
|
||||
log.debug("自动插入 createDate");
|
||||
this.setFieldValByName("createDate", time, metaObject);
|
||||
}
|
||||
if (metaObject.hasSetter("updateDate")) {
|
||||
log.debug("自动插入 updateDate");
|
||||
this.setFieldValByName("updateDate", time, metaObject);
|
||||
}
|
||||
if (metaObject.hasSetter("delFlag")) {
|
||||
log.debug("自动插入 delFlag");
|
||||
this.setFieldValByName("delFlag", false, metaObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("自动注入失败:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据执行
|
||||
*
|
||||
* @param metaObject
|
||||
*/
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
try {
|
||||
Timestamp time=new Timestamp(System.currentTimeMillis());
|
||||
if (metaObject.hasSetter("updateTime")) {
|
||||
log.debug("自动插入 updateTime");
|
||||
this.setFieldValByName("updateTime", time, metaObject);
|
||||
}
|
||||
if (metaObject.hasSetter("updateDate")) {
|
||||
log.debug("自动插入 updateDate");
|
||||
this.setFieldValByName("updateDate", time, metaObject);
|
||||
}
|
||||
if (metaObject.hasSetter("delFlag")) {
|
||||
log.debug("自动插入 delFlag");
|
||||
this.setFieldValByName("delFlag", null, metaObject);
|
||||
}
|
||||
if (metaObject.hasSetter("createTime")) {
|
||||
log.debug("自动插入 createTime");
|
||||
this.setFieldValByName("createTime", null, metaObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("自动注入失败:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.config;
|
||||
|
||||
/**
|
||||
* @author :LionCity
|
||||
* @date :Created in 2020-04-10 15:11
|
||||
* @description:MybatisConfig
|
||||
* @modified By:
|
||||
* @version:
|
||||
*/
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Configuration
|
||||
public class MybatisConfig {
|
||||
/**
|
||||
* 配置mybatis的分页插件pageHelper
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public PageHelper pageHelper(){
|
||||
PageHelper pageHelper = new PageHelper();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("offsetAsPageNum","true");
|
||||
properties.setProperty("rowBoundsWithCount","true");
|
||||
properties.setProperty("reasonable","true");
|
||||
//配置mysql数据库的方言
|
||||
properties.setProperty("dialect","mysql");
|
||||
pageHelper.setProperties(properties);
|
||||
return pageHelper;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
co.yixiang.config.MetaHandler,\
|
||||
co.yixiang.config.MybatisConfig
|
Reference in New Issue
Block a user