通用优化

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,5 +1,7 @@
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;
@ -19,7 +21,7 @@ public class EntityUtils {
* @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 );
} }
@ -36,7 +38,11 @@ public class EntityUtils {
for (Method m : methods) { for (Method m : methods) {
if (m.getName().equals( "setCreateBy" )) { 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();