使用 POST 方法中的 ftl 显示列表

对不起我的英语不好!我是 Spring 和 FTL 的新手。我想显示firstName和lastName使用<#list模板,但我无法识别我的 POST 方法中的任何序列,有人可以向我解释一下吗?再说一次,我是一个新手,如果我不明白我应该做什么,请不要评判我。我正在使用 CUBA STUDIO 6.8 和 IDEA。我也在门户模块中处理此任务


这是我使用 ftl 表单和门户控制器将firstName和添加到数据库的方法:lastName


@GetMapping("/add")

public String add(Model model){

    PersonPojo personPojo = new PersonPojo();

    model.addAttribute("personPojo", personPojo);

    return "add";

}


@PostMapping("/add")

public String save(Model model, @ModelAttribute("personPojo") PersonPojo personPojo){


    String firstName = personPojo.getFirstName();

    String lastName = personPojo.getLastName();

    PersonPojo newPerson = new PersonPojo(firstName, lastName);


    Person standardEntity = metadata.create(Person.class);

    standardEntity.setFirtName(newPerson.getFirstName());

    standardEntity.setLastName(newPerson.getLastName());

    dataManager.commit(standardEntity);


    return "redirect:/allPersons";

}

我的ftl表格:


<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>Title</title>

</head>

<body>

<form action="" method="post" name="person">

    First Name: <input type="text" name="firstName"> <br>

    Last Name: <input type="text" name="lastName"> <br>

    <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}">

    <input type="submit" value="Create">

</form></body>

</html>


阿晨1998
浏览 102回答 1
1回答

森栏

因此,如果有人感兴趣,我将在这里发布我的解决方案:&nbsp;@RequestMapping(value = "/allPersons", method = RequestMethod.GET)&nbsp; &nbsp; public String getPersons(Model model) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LoadContext loadJohn = new LoadContext(John.class);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadJohn.setQueryString("select u from test6$John u");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model.addAttribute("users", dataService.loadList(loadJohn));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "list";&nbsp; &nbsp; }ftl 应该如下所示: 接下来我面临的问题是我不知道我必须检查列表是否为空。!””是这样的<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <title>Title</title></head><body><h3>Person List</h3><a href="/app-portal/add">Add Person</a><br><br><div>&nbsp; &nbsp; <table border="1">&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>First Name</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Last Name</th>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; <#list users as show>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>${show.firstName!""}</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>${show.lastName!""}</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; </#list>&nbsp; &nbsp; </table></div></body></html>我希望这对像我这样的人有帮助。另外,如果有人知道如何删除和更新数据,请分享。谢谢!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java