通用优化
This commit is contained in:
parent
09b798c912
commit
6582f12c54
|
|
@ -69,6 +69,12 @@
|
|||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
</dependency>
|
||||
<!-- 通用工具 -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>4.2.1</version>
|
||||
</dependency>
|
||||
<!-- 单表通用mapper -->
|
||||
<dependency>
|
||||
<groupId>tk.mybatis</groupId>
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class ExamQuestionCategoryController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult addSave(ExamQuestionCategory examQuestionCategory)
|
||||
{
|
||||
return toAjax(examQuestionCategoryService.insertExamQuestionCategory(examQuestionCategory));
|
||||
return toAjax(examQuestionCategoryService.insert(examQuestionCategory));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -121,7 +121,7 @@ public class ExamQuestionCategoryController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult remove(String ids)
|
||||
{
|
||||
return toAjax(examQuestionCategoryService.deleteExamQuestionCategoryByIds(ids));
|
||||
return toAjax(examQuestionCategoryService.deleteByIds(ids));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ public abstract class AbstractBaseServiceImpl<M extends MyMapper<T>, T> implemen
|
|||
|
||||
@Override
|
||||
public int insert(T entity) {
|
||||
EntityUtils.setCreatAndUpdatInfo(entity);
|
||||
EntityUtils.setCreateAndUpdatInfo(entity);
|
||||
return mapper.insert(entity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int insertSelective(T entity) {
|
||||
EntityUtils.setCreatAndUpdatInfo(entity);
|
||||
EntityUtils.setCreateAndUpdatInfo(entity);
|
||||
return mapper.insertSelective(entity);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,65 +1,71 @@
|
|||
package com.ruoyi.framework.web.util;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
/**
|
||||
* 实体类相关工具类
|
||||
* 实体类相关工具类
|
||||
* 解决问题: 1、快速对实体的常驻字段,如:createUser、updateUser等值快速注入
|
||||
*
|
||||
*
|
||||
* @author Ace
|
||||
* @version 1.0
|
||||
* @date 2016年4月18日
|
||||
* @since 1.7
|
||||
*/
|
||||
public class EntityUtils {
|
||||
/**
|
||||
* 快速将bean的crtUser、crtHost、crtTime、updUser、updHost、updTime附上相关值
|
||||
*
|
||||
* @param entity 实体bean
|
||||
* @author 王浩彬
|
||||
*/
|
||||
public static <T> void setCreatAndUpdatInfo(T entity) {
|
||||
setCreateInfo(entity);
|
||||
setUpdatedInfo(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速将bean的crtUser、crtHost、crtTime附上相关值
|
||||
*
|
||||
* @param entity 实体bean
|
||||
* @author 王浩彬
|
||||
*/
|
||||
public static <T> void setCreateInfo(T entity){
|
||||
try {
|
||||
Method[] methods = entity.getClass().getMethods();
|
||||
for(Method m : methods){
|
||||
if(m.getName().equals("setCreateBy")){
|
||||
m.invoke(entity, com.ruoyi.framework.web.util.ShiroUtils.getUserId());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 快速将bean的crtUser、crtHost、crtTime、updUser、updHost、updTime附上相关值
|
||||
*
|
||||
* @param entity 实体bean
|
||||
* @author 王浩彬
|
||||
*/
|
||||
public static <T> void setCreateAndUpdatInfo(T entity) {
|
||||
setCreateInfo( entity );
|
||||
setUpdatedInfo( entity );
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速将bean的updUser、updHost、updTime附上相关值
|
||||
*
|
||||
* @param entity 实体bean
|
||||
* @author 王浩彬
|
||||
*/
|
||||
public static <T> void setUpdatedInfo(T entity){
|
||||
try {
|
||||
Method[] methods = entity.getClass().getMethods();
|
||||
for(Method m : methods){
|
||||
if(m.getName().equals("setUpdateBy")){
|
||||
m.invoke(entity, com.ruoyi.framework.web.util.ShiroUtils.getUserId());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 快速将bean的crtUser、crtHost、crtTime附上相关值
|
||||
*
|
||||
* @param entity 实体bean
|
||||
* @author 王浩彬
|
||||
*/
|
||||
public static <T> void setCreateInfo(T entity) {
|
||||
try {
|
||||
Method[] methods = entity.getClass().getMethods();
|
||||
for (Method m : methods) {
|
||||
if (m.getName().equals( "setCreateBy" )) {
|
||||
m.invoke( entity, com.ruoyi.framework.web.util.ShiroUtils.getUserId() );
|
||||
} else if (m.getName().equals( "setId" )) {
|
||||
m.invoke( entity, RandomUtil.randomUUID() );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速将bean的updUser、updHost、updTime附上相关值
|
||||
*
|
||||
* @param entity 实体bean
|
||||
* @author 王浩彬
|
||||
*/
|
||||
public static <T> void setUpdatedInfo(T entity) {
|
||||
try {
|
||||
Method[] methods = entity.getClass().getMethods();
|
||||
for (Method m : methods) {
|
||||
if (m.getName().equals( "setUpdateBy" )) {
|
||||
m.invoke( entity, com.ruoyi.framework.web.util.ShiroUtils.getUserId() );
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue