通用优化
This commit is contained in:
parent
09b798c912
commit
6582f12c54
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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、快速对实体的常驻字段,如:createUser、updateUser等值快速注入
|
* 解决问题: 1、快速对实体的常驻字段,如:createUser、updateUser等值快速注入
|
||||||
*
|
*
|
||||||
* @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的crtUser、crtHost、crtTime、updUser、updHost、updTime附上相关值
|
* 快速将bean的crtUser、crtHost、crtTime、updUser、updHost、updTime附上相关值
|
||||||
*
|
*
|
||||||
* @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的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的updUser、updHost、updTime附上相关值
|
* 快速将bean的crtUser、crtHost、crtTime附上相关值
|
||||||
*
|
*
|
||||||
* @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的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