+ fix: 修改createTime注解,默认交给数据库赋值
This commit is contained in:
parent
714e3e891d
commit
7747f40ee4
|
@ -1,10 +1,7 @@
|
|||
package com.diboot.core.entity;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.diboot.core.util.JSON;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -37,7 +34,7 @@ public abstract class BaseEntity implements Serializable {
|
|||
/***
|
||||
* 默认记录创建时间字段,新建时由数据库赋值
|
||||
*/
|
||||
@TableField(update="now()")
|
||||
@TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
|
||||
private Date createTime;
|
||||
|
||||
public Long getId() {
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.diboot.core.vo.DictionaryVO;
|
|||
import com.diboot.core.vo.KeyValue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -21,6 +22,7 @@ import java.util.List;
|
|||
* @version 2.0
|
||||
* @date 2019/01/01
|
||||
*/
|
||||
@Primary
|
||||
@Service("dictionaryService")
|
||||
public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {
|
||||
private static final Logger log = LoggerFactory.getLogger(DictionaryServiceImpl.class);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.diboot.core.vo;
|
||||
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -38,10 +39,8 @@ public class JsonResult implements Serializable {
|
|||
public JsonResult(Object data, String... additionalMsg){
|
||||
this.code = Status.OK.code();
|
||||
this.msg = Status.OK.label();
|
||||
initMsg(additionalMsg);
|
||||
this.data = data;
|
||||
if(V.notEmpty(additionalMsg)){
|
||||
this.msg += ": " + additionalMsg[0];
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -52,9 +51,7 @@ public class JsonResult implements Serializable {
|
|||
public JsonResult(Status status, String... additionalMsg){
|
||||
this.code = status.code();
|
||||
this.msg = status.label();
|
||||
if(V.notEmpty(additionalMsg)){
|
||||
this.msg += ": " + additionalMsg[0];
|
||||
}
|
||||
initMsg(additionalMsg);
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
|
@ -64,9 +61,7 @@ public class JsonResult implements Serializable {
|
|||
public JsonResult(Status status, Object data, String... additionalMsg){
|
||||
this.code = status.code();
|
||||
this.msg = status.label();
|
||||
if(V.notEmpty(additionalMsg)){
|
||||
this.msg += ": " + additionalMsg[0];
|
||||
}
|
||||
initMsg(additionalMsg);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
@ -99,4 +94,20 @@ public class JsonResult implements Serializable {
|
|||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 赋值msg(去掉重复前缀以支持与BusinessException嵌套使用)
|
||||
* @param additionalMsg
|
||||
*/
|
||||
private void initMsg(String... additionalMsg){
|
||||
if(V.notEmpty(additionalMsg)){
|
||||
if(S.startsWith(additionalMsg[0], this.msg)){
|
||||
this.msg = additionalMsg[0];
|
||||
}
|
||||
else{
|
||||
this.msg += ": " + additionalMsg[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -125,6 +126,10 @@ public class BaseServiceTest {
|
|||
success = dictionaryService.createEntities(dictionaryList);
|
||||
Assert.assertTrue(success);
|
||||
|
||||
dictionaryList.get(2).setCreateTime(new Date());
|
||||
dictionaryList.get(2).setItemValue("HZ2");
|
||||
dictionaryService.updateEntity(dictionaryList.get(2));
|
||||
|
||||
success = clearTestData(TYPE);
|
||||
Assert.assertTrue(success);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue