Home>

Thanks for your help.
I want to display the following values ​​stored in Liston the screen using Thymeleaf.

It will be output in hexadecimal notation of the hash code. You can use the get method for the List object, but I want to avoid it because you have to prepare as many tags as there are List elements in the template.

Corresponding source code
 /*
     * Read CSV
     * /
    public static List<String []>getCsv () {
        String path = "/resources/csv/test.csv";
        List<String []>list = new ArrayList<String []>();
        FileInputStream fi = null;
        InputStreamReader is = null;
        BufferedReader br = null;
        try {
            fi = new FileInputStream (path);
            is = new InputStreamReader (fi);
            br = new BufferedReader (is);
            String line;
            while ((line = br.readLine ())! = null) {
                String [] data = line.split (",");
                list.add (data);
            }
        } catch (Exception e) {
            e.printStackTrace ();
        } finally {
            try {
                br.close ();
            } catch (Exception e) {
                e.printStackTrace ();
            }
        }
        return list;
    }
  @RequestMapping (value = "/ test", method = RequestMethod.GET)
    public String main (Model model) {
       /* Test test = new Test ();* /
        List<String []>list = Test.getCsv ();
        model.addAttribute ("list", list);
        return "test/test.html";
    }
<html xmlns: th = "http://www.thymeleaf.org">
<head>
</head>
<body>
  <ul th: each = "value: ${list}">
    <li th: text = "${value}"></li>
  </ul>
</body>
</html>
Supplementary information (FW/tool version, etc.)

Language: Java
FW: Spring Boot, Thymeleaf

  • Answer # 1

    In the templatevalueToString []Data will be entered, right?
    So if you want to see all the elementsth: eachI think you can use.

    
    <p>
      <span th: text = "${col}"></span>
    </p>
    

    liPlease try to devise the tag set in the element by yourself.

Related articles