我想获得以下 URL 以使用 2 个参数访问我的数据:
http://localhost:8080/contactnote?entryDate=2022-02-01?contactType=T
具有单个参数的两个映射都有效:
@GetMapping(params ={"contactType"})
public ResponseEntity<Collection<ContactNote>> findContactNotesWithEntryDateGreaterThan(@RequestParam(value = "contactType") String contactType) {
return new ResponseEntity<>(repository.findByContactType(contactType), HttpStatus.OK);
}
@GetMapping(params ={"entryDate"})
public ResponseEntity<Collection<ContactNote>> findContactNotesWithDateTilGreaterThan(@RequestParam(value = "entryDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date entryDate) {
return new ResponseEntity<>(repository.findByEntryDateGreaterThan(entryDate), HttpStatus.OK);
但是当我尝试将它们与两个参数结合使用时,它不会起作用,其中没有一个是可用的。
@GetMapping(params ={"entryDate", "contactType"})
public ResponseEntity<Collection<ContactNote>> findByEntryDateGreaterThanAndContactTypeWith(
@RequestParam(value = "entryDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date entryDate,
@RequestParam(value = "contactType") String contactType
)
我的存储库如下所示:
import de.bhm.zvoove.api.domain.ContactNote;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
@Repository
public interface ContactNoteRepository extends JpaRepository<ContactNote, Long> {
List<ContactNote> findByContactType(String ContactType);
List<ContactNote> findByEntryDateGreaterThanAndContactType(Date entryDate , String ContactType);
}
您输入的网址无效,双精度?
,您必须使用&
第二个参数
正确一个:http://localhost:8080/contactnote?entryDate=2022-02-01&contactType=T
此代码有效,请name
改用value
@GetMapping(path= "/contactnote")
@ResponseBody
public String findByEntryDateGreaterThanAndContactTypeWith(
@RequestParam(name = "entryDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date entryDate,
@RequestParam(name = "contactType", required = false) String contactType) {
return "Hello World";
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句