如何根据java中的日期从数据库中检索数据?

时间:2017-07-29 08:45:04

标签: java spring-mvc spring-data-jpa

这是我试过的

控制器:

public void lovForFincurrency() {

    LOG.info("\n\n\nINSIDE \n CLASS == LovController \n METHOD == lovForFincurrency(); ");
    try {

        apexManagerService = ServiceManagerFactory.getServiceManager(getServletContext());
        MmsBean mmsBean = (MmsBean) getControllerObject(ApexManagedBean.MMSBEAN.getName(), MmsBean.class);
        PmBean pmBean = (PmBean) getControllerObject(ApexManagedBean.PMBEAN.getName(), PmBean.class);
        final FinCurrencyService finsurrencyservice = apexManagerService.getFinCurrencyService();

        DateFormat dateFormat = new SimpleDateFormat("MM/DD/YYYY HH:mm:ss");
        Date date = new Date();

        List<Fincurrency> fincurrencies = finsurrencyservice.readcurrencies("Y", date);

        List<Admlov> admlovs = new ArrayList<Admlov>();

        for (Fincurrency fincurrency : fincurrencies) {
            Admlov admlov = new Admlov();

            admlov.setId(fincurrency.getCurrency());
            admlov.setCode(fincurrency.getSymbol());
            admlov.setDescr(fincurrency.getDescr());
            admlovs.add(admlov);

        }

        if (admlovs != null) {
            mmsBean.setAdmlovs(admlovs);
        }

    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
        addMessageToFacesContext(ERROR_DELETE);
    }
    LOG.info("EXITING THIS METHOD \n\n\n");

}

这是我的存储库:

public interface FinCurrencyRepo extends JpaRepository<Fincurrency, String> {

    List<Fincurrency> findByEffectivefromAfterAndEffectivetoBeforeAndEnabled(Date sysdate, Date sysdate1,
            String enabled);
}

这是我的服务实现:

@Override
public List<Fincurrency> readcurrencies(String enabled, Date sysdate) {
    return fincurrencyRepo.findByEffectivefromAfterAndEffectivetoBeforeAndEnabled(sysdate, sysdate, enabled);
}

这是我的Fincurrency实体:我想在今年和今年之后的数据表中显示符号和货币,但不是在今年之前。请帮助我解决这个问题。

public class Fincurrency implements Serializable {

    @Id
    private String currency;

    //@Temporal(TemporalType.DATE)
    private Date effectivefrom;

    //@Temporal(TemporalType.DATE)
    private Date effectiveto;

    private String enabled;

    private String symbol;

    @Column(name="\"TYPE\"")
    private String type;

    public Fincurrency() {
    }

    public String getCurrency() {
        return this.currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public BigDecimal getAfterdecimal() {
        return this.afterdecimal;
    }

    public void setAfterdecimal(BigDecimal afterdecimal) {
        this.afterdecimal = afterdecimal;
    }

    public Date getEffectivefrom() {
        return this.effectivefrom;
    }

    public void setEffectivefrom(Date effectivefrom) {
        this.effectivefrom = effectivefrom;
    }

    public Date getEffectiveto() {
        return this.effectiveto;
    }

    public void setEffectiveto(Date effectiveto) {
        this.effectiveto = effectiveto;
    }

    public String getEnabled() {
        return this.enabled;
    }

    public void setEnabled(String enabled) {
        this.enabled = enabled;
    }

    public String getSymbol() {
        return this.symbol;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

}

0 个答案:

没有答案