通用优化

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> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
</dependency> </dependency>
<!-- 通用工具 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.2.1</version>
</dependency>
<!-- 单表通用mapper --> <!-- 单表通用mapper -->
<dependency> <dependency>
<groupId>tk.mybatis</groupId> <groupId>tk.mybatis</groupId>

View File

@ -86,7 +86,7 @@ public class ExamQuestionCategoryController extends BaseController
@ResponseBody @ResponseBody
public AjaxResult addSave(ExamQuestionCategory examQuestionCategory) 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 @ResponseBody
public AjaxResult remove(String ids) 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 @Override
public int insert(T entity) { public int insert(T entity) {
EntityUtils.setCreatAndUpdatInfo(entity); EntityUtils.setCreateAndUpdatInfo(entity);
return mapper.insert(entity); return mapper.insert(entity);
} }
@Override @Override
public int insertSelective(T entity) { public int insertSelective(T entity) {
EntityUtils.setCreatAndUpdatInfo(entity); EntityUtils.setCreateAndUpdatInfo(entity);
return mapper.insertSelective(entity); return mapper.insertSelective(entity);
} }

View File

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