[Kotlin Spring boot] Connect template with a backing bean
Backing bean:
A typical JavaServer Faces application includes one or more backing beans, each of which is a type of JavaServer Faces managed bean that can be associated with the components used in a particular page. This section introduces the basic concepts of creating, configuring, and using backing beans in an application.
templates/seatBooking.html:
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Theater Booking</title> </head> <body> <h1>Theater Booking</h1> <h2>Seat availability</h2> <form action="/checkAvailability" th:object="${bean}" method="POST"> <p>Check if seat number <select th:field="*{selectedSeatNum}"> <option th:each="n : ${bean.seatNums}" th:value="${n}" th:text="${n}" /> </select> in row <select th:field="*{selectedSeatRow}"> <option th:each="r : ${bean.seatRows}" th:value="${r}" th:text="${r}" /> </select> is available <input type="submit"/></p> </form> <p th:text="${bean.result}"></p> </body> </html>
Create bean and connect to controller:
package com.virtualpairprogrammers.theater.control import org.springframework.stereotype.Controller import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.servlet.ModelAndView @Controller class MainController { @RequestMapping("") fun homePage() : ModelAndView { return ModelAndView("seatBooking", "bean", CheckAvailabilityBackingBean()) } } class CheckAvailabilityBackingBean() { val seatNums = 1..36 val seatRows = 'A'..'O' var selectedSeatNum: Int = 1 var selectedSeatRow: Char = 'A' var result: String = "" }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2019-11-04 [NPM + React] Prepare a Custom React Hook to be Published as an npm Package
2019-11-04 [Debug] How to Debug a NestJs Backend using the Chrome Dev Tools
2018-11-04 [Testing] Static Analysis Testing JavaScript Applications
2014-11-04 [Angular-Scaled web] 4. Using ui-router's named views
2014-11-04 [Angular-Scaled web] 3. Basic State with ui-router