通用优化

This commit is contained in:
zhujunjieit 2018-12-07 21:32:30 +08:00
parent 09b798c912
commit 6582f12c54
4 changed files with 65 additions and 53 deletions

View File

@ -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>

View File

@ -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));
}
}

View File

@ -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);
}

View File

@ -1,65 +1,71 @@
package com.ruoyi.framework.web.util;
import cn.hutool.core.util.RandomUtil;
import java.lang.reflect.Method;
/**
* 实体类相关工具类
* 实体类相关工具类
* 解决问题 1快速对实体的常驻字段createUserupdateUser等值快速注入
*
*
* @author Ace
* @version 1.0
* @date 2016年4月18日
* @since 1.7
*/
public class EntityUtils {
/**
* 快速将bean的crtUsercrtHostcrtTimeupdUserupdHostupdTime附上相关值
*
* @param entity 实体bean
* @author 王浩彬
*/
public static <T> void setCreatAndUpdatInfo(T entity) {
setCreateInfo(entity);
setUpdatedInfo(entity);
}
/**
* 快速将bean的crtUsercrtHostcrtTime附上相关值
*
* @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的crtUsercrtHostcrtTimeupdUserupdHostupdTime附上相关值
*
* @param entity 实体bean
* @author 王浩彬
*/
public static <T> void setCreateAndUpdatInfo(T entity) {
setCreateInfo( entity );
setUpdatedInfo( entity );
}
/**
* 快速将bean的updUserupdHostupdTime附上相关值
*
* @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的crtUsercrtHostcrtTime附上相关值
*
* @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的updUserupdHostupdTime附上相关值
*
* @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();
}
}
}