簡體   English   中英

是否可以以更簡單的方式輸出帶有DB值的下拉列表?

[英]Is it possible to output a drop-down list with values from DB in an easier way?

這種方式不是最大的。 我正在尋找更好的方法。 是否可以沒有列表?

我的PageController:

public class CreateUserPageController {

@Autowired
private UserServiceImpl userServiceImpl;


@RequestMapping(value = "/create-user", method = RequestMethod.GET)
public ModelAndView showForm() {
    ModelAndView model = new ModelAndView("admin/create-user");
    model.addObject("user", new User());
    UserRoleDTO[] roles = UserRoleDTO.values();
    List<String> roleNames = new ArrayList<>();
    for (UserRoleDTO role : roles) {
        roleNames.add(role.getName());
    }
    model.addObject("roleNames", roleNames);
    return model;
}

@RequestMapping(value = "/create-user", method = RequestMethod.POST)
public ModelAndView submitForm(@ModelAttribute("user") User user) {
    userServiceImpl.create(user);
    return showForm();
    }
}

我的JSP:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<html>
<head>
    <title>Create test</title>
</head>
<body>

<h1>Create Test</h1>
<form:form method="POST" action="/create-test" modelAttribute="topicTestDTO">
    <form:input path="topic.name" type="text" list="topic_list" placeholder="choose or create topic"/>
    <datalist id="topic_list">
        <c:forEach items="${topicList}" var="topic">
            <option>${topic}</option>
        </c:forEach>
    </datalist>
    <br>
    <form:input path="test.name" type="text" placeholder="create test name"/>
    <input type="submit">
</form:form>
</body>
</html>

感謝幫助。 如果您需要更多信息,請告訴我,我將完成代碼。

在這里,問題在於它向數據庫檢索數據的每個請求,即使數據沒有更改也降低了應用程序的性能。

通過使用本地緩存,我們可以實現性能,因此,在應用程序加載其自身數據時,將從數據庫查詢自身數據並將其存儲在緩存中,然后我們可以重用緩存中的數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM