###前提・実現したいこと
thymeleafのth:withの宛先をURLにしてAPIが返す数値を取得したい。
(もし仕様上難しいようであれば、代替方法を教えていただきたく思っています。)
###該当のソースコード
具体的なthymeleaf実装は以下のようにしています。
thymeleaf
1th:with="count=@{/api1/count/error}" 2th:text="${count}"
数値を返すAPIも関係があるかもしれませんので記載します。
レスポンスの指定方法に誤りがあるのかもしれない?と懸念しているのですが…。
現在はダミーで99を返すようになっています。
spring
1@RestController 2@RequestMapping("api1/count") 3public class CountController { 4(中略) 5 @GetMapping(value="error") 6 ResponseEntity<Integer> count(Model model) { 7 try { 8 HttpHeaders headers = new HttpHeaders(); 9 headers.add("contet-type", MimeTypeUtils.TEXT_PLAIN_VALUE + ";utf-8"); 10 headers.add("Accept-Charset", "utf-8"); 11 Integer count = 99; 12 ResponseEntity<Integer> response = new ResponseEntity<Integer>(count, headers, HttpStatus.OK); 13 return response; 14 } catch (Exception e) { 15 (中略) 16 } 17 return new ResponseEntity<Integer>(HttpStatus.NOT_FOUND); 18 } 19}
画面には、withで指定したURL箇所がそのまま表示されてしまいます。
表示:/api1/count/error
理想:99
###試したこと
th:text="@{/api1/count/error}"も試しましたが結果は同様でした。
###補足情報(言語/FW/ツール等のバージョンなど)
spring-boot1.4.6
thymeleaf2.1.5
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。