zoukankan      html  css  js  c++  java
  • [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 = ""
    }
  • 相关阅读:
    原生js 异步请求,responseXML解析
    asp.net中Page.ClientScript.RegisterStartupScript用法小结
    asp.net 在repeater控件中加按钮
    无法打开物理文件 操作系统错误 5:拒绝访问 SQL Sever
    js 注册控件的onclick事件
    js控件设置只读属性和不可用属性
    js CheckBox只读
    js时间日期格式
    js正则判断日期
    UIPickerView的使用(三)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/13923732.html
Copyright © 2011-2022 走看看