java Spring Boot中用啥代替“System.out.println”

Posted

技术标签:

【中文标题】java Spring Boot中用啥代替“System.out.println”【英文标题】:What to use instead of "System.out.println" in java Spring Bootjava Spring Boot中用什么代替“System.out.println” 【发布时间】:2020-05-15 19:07:55 【问题描述】:
@RequestMapping(method=RequestMethod.POST, value= "/LMSServer/getNoOfDaysOfApplicationBycellNo" )
@PreAuthorize("hasAuthority('CUSTOMER_MANAGEMENT_R') OR hasAuthority('CUSTOMER_MANAGEMENT_RW')")
public BasicResponce getNoOfDaysOfApplicationBycellNo(@RequestParam(value = "cellNo") long cellNo)

    if(LOG.isInfoEnabled())
        LOG.info("WebClientRestContoller.getNoOfDaysOfApplicationBycellNo--Start");
        LOG.info("Cell NO: "+cellNo);
    

    BasicResponce authResp = null;
    try 

        Customer fromDB= (Customer) objLMSDAO.getDetailsByCellno(cellNo);
        DaysOfApplicationResponseDTO toSend= new DaysOfApplicationResponseDTO();

        toSend.setCreatedAt(fromDB.getCreatedAt()+"");
        toSend.setUpdatedAt(fromDB.getUpdatedAt()+"");

        toSend.setRequested_Action(true);

        authResp=toSend;    


         catch (Exception e) 
            e.printStackTrace();
        

        if(LOG.isInfoEnabled())
            LOG.info("Returned Response is:");
            LOG.info("Response Requested_Action:  ",new Object[]authResp.getRequested_Action());
            LOG.info("WebClientRestContoller.getNoOfDaysOfApplicationBycellNo--End");
        

        return authResp;


以上是我的主要代码。我想打印天数的差异(createdAtupdatedAt 之间的天数)。我在哪里写这个逻辑?我记得在java中我们使用System.out.println来显示输出,但是这里我不知道在Postman上显示代码。

下面是我的 DTO:

public class DaysOfApplicationResponseDTO extends BasicResponce

private String createdAt;
private String updatedAt;
private String days;


public String getDays() 
    return days;


public void setDays(String days) 
    this.days = days;

private List<CustomerLoanSummaryResponseDTO> LoanApplicationDummyResponseList;

public String getCreatedAt() 
    return createdAt;


public void setCreatedAt(String createdAt) 
    this.createdAt = createdAt;


public String getUpdatedAt() 
    return updatedAt;


public void setUpdatedAt(String updatedAt) 
    this.updatedAt = updatedAt;


public List<CustomerLoanSummaryResponseDTO> getLoanApplicationDummyResponseList() 
    return LoanApplicationDummyResponseList;


public void setLoanApplicationDummyResponseList(
        List<CustomerLoanSummaryResponseDTO> loanApplicationDummyResponseList) 
    LoanApplicationDummyResponseList = loanApplicationDummyResponseList;


public DaysOfApplicationResponseDTO() 
    super();

public DaysOfApplicationResponseDTO(String createdAt, String UpdatedAt, String days,
        List<CustomerLoanSummaryResponseDTO> loanApplicationDummyResponseList) 
    super();
    this.createdAt = createdAt;
    this.updatedAt = updatedAt;
    this.days = days;
    this.LoanApplicationDummyResponseList = loanApplicationDummyResponseList;



【问题讨论】:

您希望输出到哪里?放入日志文件以控制发生的情况,还是在客户端页面上? 请修改标题,因为标题与实际问题无关! 【参考方案1】:

您可以将服务类(@service 注释)引入您的项目以实现域逻辑。您必须将项目分解并组织成合适的项目结构(为了清晰起见,您的控制器、实体、服务位于不同的包中)。最好阅读这些以获取更多信息。

这是一个有用的堆栈溢出问题, What is the recommended project structure for spring boot rest projects?

【讨论】:

以上是关于java Spring Boot中用啥代替“System.out.println”的主要内容,如果未能解决你的问题,请参考以下文章

eggjs是不是可以代替spring boot?

Spring中用配置类代替配置xml文件

Java中用CyclicBarrier以及CountDownLatch和join相比有啥不同

spring boot 结合啥前端框架

spring boot 视图层(JAVA之学习-2)

Spring Boot入门