[Kotlin Spring boot] Connect template with a backing bean
2023-09-14 09:00:46 时间
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 = "" }
相关文章
- Spring学习笔记(三)——Spring注解开发&spring与Junit整合测试
- Spring学习笔记(五)——JdbcTemplate和spring中声明式事务
- 简单介绍一下spring bean的生命周期_Spring bean的生命周期
- 你有没有掉进去过这些Spring的“陷阱“(上)
- Spring batch教程 之 spring batch简介
- Spring @Autowired 注解静态变量
- spring注解有哪些_Spring 注解
- 基于Spring Boot及Kotlin的ddd领域驱动实现
- Spring常用事务传播特性
- 将Bean交给Spring容器管理的几种方式
- java 长轮询_java – Spring中的长轮询[通俗易懂]
- Spring MVC 的请求映射与参数
- Java框架Spring入门-第一个spring项目
- Spring Boot的测试工具和技巧(一)
- Spring Cloud Gateway环境搭建和配置(一)
- Spring Cloud Gateway 网关与微服务架构的整合(二)
- Spring Cloud Stream核心组件Channel(二)
- spring-boot项目的新建(出生)详解编程语言
- jpa+spring配置多数据源详解编程语言
- Spring Boot Starters启动器详解编程语言