| | |
| | | |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.executor.Executor; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.mapping.SqlCommandType; |
| | | import org.apache.ibatis.plugin.*; |
| | | import org.apache.ibatis.plugin.Interceptor; |
| | | import org.apache.ibatis.plugin.Invocation; |
| | | import org.apache.ibatis.plugin.Plugin; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | @Intercepts({ @Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) }) |
| | | /*@Component |
| | | @Intercepts({ @Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) })*/ |
| | | public class MybatisInterceptor implements Interceptor { |
| | | |
| | | @Autowired |
| | |
| | | //注入创建时间 |
| | | if ("createTime".equals(field.getName())) { |
| | | field.setAccessible(true); |
| | | field.set(parameter, LocalDateTime.now()); |
| | | field.set(parameter, new Date()); |
| | | field.setAccessible(false); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | if ("updateTime".equals(field.getName())) { |
| | | field.setAccessible(true); |
| | | field.set(parameter, LocalDateTime.now()); |
| | | field.set(parameter, new Date()); |
| | | field.setAccessible(false); |
| | | } |
| | | } catch (Exception e) { |