简体   繁体   中英

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type Model

This is repository method, which as you will see select columns from UserDetail Entity Table by created_date, but I have getting error When I type in swagger this value 2021-10-14 23:16:31

@Query(value = "SELECT usd.phoneNumber,usd.textMessage FROM UserDetail entity usd WHERE usd.created_date=:createdDate", nativeQuery = true)
    UserDetail findByCreatedDate(LocalDateTime createdDate);

I try to type parametr String format in service layer and convert to LocalDate time like following code:

 @Override
    public UserDetail findByCreatedDateWhenUserTypeOwnInfo(String createdDate) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.parse(createdDate, formatter);
        return this.userDetailRepository.findByCreatedDate(dateTime);
    }

I have getting this error:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [az.expressbank.expressbankproject.data.model.UserDetail]

How to solve this problem>?

You're using "named parameters" so looks like you need to add a @Param to your query. like this:

UserDetail findByCreatedDate(@Param("createdDate") LocalDateTime createdDate);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type Account to type AllAccount Exception: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type Spring MVC “No converter found capable of converting from type java.lang.String to type org.springframework.core.io.Resource” No converter found capable of converting from type [java.time.LocalDate] to type [@org.springframework.data.jpa.repository.Query java.lang.String] MongoDB No converter found capable of converting from type [java.lang.String] to type [java.time.LocalDateTime] No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String] - Spring config server No converter found capable of converting from type [java.lang.String] to type [@Autowired @ManyToOne @JoinColumn com.papertrue.country.Country] Spring boot 2 : ConverterNotFoundException: No converter found capable of converting from type [java.time.ZonedDateTime] to type [java.util.Date] No converter found capable of converting from type [java.lang.String] to type [com.google.cloud.datastore.Key] error if spring-data-rest is used No converter found capable of converting from type org.bson.BsonUndefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM