admin管理员组

文章数量:1389761

I've been trying to assemble a data table display in html via thymeleaf.

In general, it's a part of a system meant to display, edit and create not preset sql database via browser I am working on at my spare time. I want it to be able to take in any form of database and generate sql queries based on the opions selected via buttons, or direct sql input. However, I faced a small problem with html output and I've been stuck at it for about 2 weeks by now.

Everything goes inside as expected, however, when I request the said table back, it returns nothing (my input/output is nullproof so technically it's null). Any ideas on what's wrong?

Here's the HTML

<!DOCTYPE html>
<html lang="en" xmlns:th=";>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
    <body>
        <form method="post">
            <table>
                <tr>
                    <td>
                        <button type="submit" name="send">UpdateDB</button>
                    </td>
                </tr>
            </table>
        </form>
        <form method="post" th:object="${arrayList}">
            <table>
                <tr>
                    <td th:each="currentType : ${currentTypesList}">
                        <select >
                            <option th:each="t : ${typeList}"
                                    th:selected="${t.dataType==currentType}"
                                    th:text="${t.dataTypeDesc}">
                            </option>
                        </select>
                    </td>
                </tr>
                <tr th:each="l : ${arrayList.tableData}">
                    <td th:each="s : ${l.tableRowData}">
                        <input th:value="*{tableData[__${arrayList.tableData.indexOf(l)}__]
                            .tableRowData[__${l.tableRowData.indexOf(s)}__]}" type="text">
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

And controller (I removed unrelated to the above html parts)

@Controller
public class DataBaseController {
    private final DataBaseService dataBaseService;

    private String currentDBTitle;


    @Autowired
    public DataBaseController (DataBaseService dataBaseService) {
        this.dataBaseService = dataBaseService;
    }

    @GetMapping("/DBView")
    public String showDB(Model model) {
        if (currentDBTitle != null) {
            model.addAttribute("typeList", dataBaseService.getDataTypes());
            model.addAttribute("currentTypesList", dataBaseService.getJDBCDataTypes(currentDBTitle));
            model.addAttribute("arrayList", dataBaseService.getDataBase(currentDBTitle));
        }
        else {
            return "redirect:/DBList";
        }
        return "DBView";
    }

    @PostMapping("/DBView")
    public String selectDB(Model model, @RequestParam(value = "send") String action,
                           @ModelAttribute("arrayList") Table newData) {
        if (currentDBTitle != null) {
            model.addAttribute("typeList", dataBaseService.getDataTypes());
            model.addAttribute("currentTypesList", dataBaseService.getJDBCDataTypes(currentDBTitle));
            model.addAttribute("arrayList", dataBaseService.getDataBase(currentDBTitle));
            dataBaseService.updateDB(currentDBTitle, newData);
            return "/DBView";
        }
        else {
            return "redirect:/DBList";
        }
    }
}

本文标签: spring bootThymeleaf input does not return List valuesStack Overflow