如何将值存储在应用程序中。

发布于 2025-02-11 00:47:11 字数 101 浏览 2 评论 0原文

我想在应用程序属性文件中存储一个血组列表,以便在要求用户选择血组的同时将其获取并显示在下拉列表中。我正在使用百里香叶模板引擎。我想用它来避免尽可能多的硬编码(用于学习经验)。有什么想法吗?

I wanted to store a list of blood groups in the application properties file so that it can be fetched and displayed in a dropdown list while the user is asked to pick a blood group. I'm using thyme leaf template engine. I wanted to use this to avoid hard coding as much as possible(for learning experience). Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疏忽 2025-02-18 00:47:11
  1. 在application.properties文件中,定义一个财产血组

血组= a+,b+,ab+

  1. 在Java类中(可能是控制器)绑定此属性
  @value(“ $ {BloodGroups}”)
私人弦[]血组;
 
  1. 在您的控制器类中,将其设置为模型属性

model.addattribute(“血组”,血组);

  1. 访问ThmeLeaf
 < select必需=“ true” name =“ BloodGroup” ID =“ BloodGroup”>
                              <选项th:selected/>
                              <选项th:每个=“ BloodGroup:$ {BloodGroups}” Th:value =“ $ {BloodGroup}” Th:text =“ $ {BloodGroup}”><</option>
                          </select>
 
  1. In application.properties file, define one property bloodGroups

bloodGroups=A+,B+,AB+

  1. In java class(may be controller) bind this property
@Value("${bloodGroups}")
private String[] bloodGroups;
  1. In your controller class set this as model attribute

model.addAttribute("bloodGroups", bloodGroups);

  1. Access in thmeleaf
<select required="true" name="bloodGroup" id="bloodGroup">
                              <option th:selected/>
                              <option th:each="bloodGroup: ${bloodGroups}" th:value="${bloodGroup}" th:text="${bloodGroup}"></option>
                          </select>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文