我的物體是回傳欄位空示例:EntityTest{id=null, name=null}
但我需要如果所有欄位都為空回傳 EntityTest = null
測驗物體
@Entity
@Table(name="TestEntity")
public class TestEntity {
@Id
@Column(name="id")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name="test_name")
private String testName;
}
測驗物體Dto
public class TestEntityDto {
private long id;
private String test_name;
}
測驗物體映射器
@Mapper
public interface TestEntityMapper {
TestEntity TestEntityDTOToTestEntity(TestEntityDTO testEntityDTO);
實施
testEntityDTO.setId(null);
testEntityDTO.setNameTest(null);
TestEntity testEntity = TestEntityMapper.TestEntityDTOToTestEntity(testEntityDTO);
實際結果:
EntityTest{id=null, name=null}
預期結果:
EntityTest = null
uj5u.com熱心網友回復:
我建議只執行 toString 來檢查所有 null 情況:
toString(){"id:" id ",name:" name;}
因此,如果這回傳 "id:null,name:null" 那么您可以確定它為 null 并在檢查等于后回傳 null
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/409041.html
標籤:
