`
maxer025
  • 浏览: 79560 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

thymeleaf

阅读更多
Thymeleaf 分页功能
https://www.iteye.com/blog/gjp014-2387037


Thymeleaf select 使用 和多select 级联选择
https://www.iteye.com/blog/gjp014-2395655




<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.w3.org/1999/xhtml" layout:decorator="thymeleaf/templates/layout.html">
<head>
    <script type="text/javascript" th:src="@{/js/sgo/endpoint.js}"></script>
    <title>Endpoint Form</title>
</head>
<body>
<div layout:fragment="content">
    <form action="#" id="endpoint-form" th:object="${endpointForm}" method="post"
th:action="@{/{deviceAction} (deviceAction=${endpointForm.id == null ? 'add-endpoint.mvc' :'endpoints/'+endpointForm.id+'/updateendpoint.mvc'})}" >
    <input th:type="hidden" th:field="*{id}" th:if="${endpointForm.id != null}" />
        <div th:if="${#fields.hasErrors('*')} or ${resultList != null}" class="alert alert-danger" role="alert">
            <ul>
                <li th:each="e : ${#fields.detailedErrors()}" th:class="${e.global}? globalerr : fielderr">
                    <span th:text="${e.global}? '*' : ${e.fieldName}">The field name</span> -
                    <span th:text="${e.message}">The error message</span>
                </li>
                <li th:each="r : ${resultList}" th:class="globalerr">
                    <span th:text="'*'">The field name</span> -
                    <span th:text="${r.getMessage()}">The error message</span>
                </li>
            </ul>
        </div>
        <div th:if="${success != null}" class="alert alert-success" role="alert" th:text="${success}" />
        <div class="form-group" th:name="endPointName" th:errorclass="has-error">
            <label class="control-label" th:for="endPointName">Endpoint Name <span class="glyphicon glyphicon-asterisk"></span></label>
            <input type="text" th:field="*{endPointName}" class="form-control required" id="endPointName"/>
        </div>
        <div class="row-fluid col-md-12">
            <div class="form-group col-md-2" th:name="EPSTypeID" th:errorclass="has-error">
                <label class="control-label" th:for="EPSTypeID">Endpoint Type Id <span class="glyphicon glyphicon-asterisk"></span></label>
<select size ="5"  th:field="*{EPSTypeID}" class="form-control" id="EPSTypeID">
                <option th:each="epsTypes : ${epsTypes}"
                        th:value="${epsTypes.id}"
                        th:text="${epsTypes.name}">Endpoint Type Id</option>
            </select>
            </div>
            <div class="form-group col-md-2" th:name="msoId" th:errorclass="has-error" >
                <label class="control-label" th:for="msoId">MSO Id <span class="glyphicon glyphicon-asterisk"></span></label>
<select size ="5"  th:field="*{msoId}" class="form-control" id="msoID">
                <option th:each="mso : ${mso}"
                        th:value="${mso.id}"
                        th:text="${mso.name}">MSO Id</option>
            </select>
            </div>

        </div>
<!--div class="row-fluid col-md-12">
            <div class="form-group col-md-2" th:name="city" th:errorclass="has-error">
                <label class="control-label" th:for="city">City <span class="glyphicon glyphicon-asterisk"></span></label>
                <input type="text" th:field="*{city}" class="form-control required" />
            </div>
            <div class="form-group col-md-2" th:name="state" th:errorclass="has-error" >
                <label class="control-label" th:for="state">State </label>
                <input type="text" th:field="*{state}" class="form-control required" />
            </div>
<div class="form-group col-md-2" th:name="province" th:errorclass="has-error" >
                <label class="control-label" th:for="province">Province </label>
                <input type="text" th:field="*{province}" class="form-control required" />
            </div>
            <div class="form-group col-md-2" th:name="country" th:errorclass="has-error" >
                <label class="control-label" th:for="country">Country <span class="glyphicon glyphicon-asterisk"></span></label>
                <input type="text" th:field="*{country}" class="form-control required" />
            </div>
        </div-->

<div class="row-fluid col-md-12">
    <div class="form-group col-md-2" th:name="country" th:errorclass="has-error" >
                <label class="control-label" th:for="country">Country <span class="glyphicon glyphicon-asterisk"></span></label>
                <select size ="5"  th:field="*{country}" class="form-control" name="startArea1" id="start_select1">
<!--option value="">Choose Country</option-->
<option  th:each="country:${country}" th:value="${country.id}" th:text="${country.name}" ></option>
</select>
            </div>
            <div class="form-group col-md-2" th:name="state" th:errorclass="has-error" >
                <label class="control-label" th:for="state">State </label>
                <select size ="5"  class="form-control" th:field="*{state}" name="startArea3" id="start_select3">
    <!--option value="">Choose State</option-->
<option th:each="state : ${state}"
                            th:value="${state.id}"
                            th:text="${state.name}">State</option>
    </select>
            </div>
<div class="form-group col-md-2" th:name="province" th:errorclass="has-error" >
                <label class="control-label" th:for="province">Province </label>
                <!--select class="form-control" name="startArea2" id="start_select2">
    <option value="">Choose Province</option>
    </select-->
<select size ="5"  class="form-control" th:field="*{province}" id="start_select2">
    <option th:each="province : ${province}"
                            th:value="${province.id}"
                            th:text="${province.name}">Province</option>
    </select>
            </div>
    <div class="form-group col-md-2" th:name="city" th:errorclass="has-error">
                <label class="control-label" th:for="city">City <span class="glyphicon glyphicon-asterisk"></span></label>
<select size ="5"  class="form-control" th:field="*{city}" name="startArea4" id="start_select4">
    <!--option value="">Choose City</option-->
<option th:each="city : ${city}"
                            th:value="${city.id}"
                            th:text="${city.name}">City</option>
    </select>   
            </div>

</div>

        <div class="form-group" th:name="timezoneName" th:errorclass="has-error">
            <label class="control-label" th:for="TimezoneID">Timezone <span class="glyphicon glyphicon-asterisk"></span></label>
            <input type="text" th:field="*{timezoneName}" class="form-control required"  id="timezoneName"/>
        </div>
        <button type="submit" class="btn btn-sm btn-primary" id="endpoint-submit" th:text="${endpointForm.id == null ? 'Create' : 'Update'}">Create</button>
        <a th:href="@{{deviceAction} (deviceAction=${endpointForm.id == null ? 'endpoints.mvc' :'/endpoints/'+endpointForm.id+'/devices.mvc'})}" title="Cancel" class="btn btn-sm btn-primary">Cancel</a>
    </form>
</div>
</body>
</html>



$(document).ready(function() {


    $('#endpoint-form')
        .on('change','#start_select1', function() {
//.on('change','#country', function() {
            let countryid = $("#start_select1").val();
            $.getJSON( "/" + contextRoot + "/provinces-json.mvc?id="+countryid, function( data ) {
                let items = [];
                $.each( data, function( key, value ) {
                    console.log(value);
                    items.push( "<option value='" + value.id + "'>" + value.name + "</option>" );
                });
                $('#start_select2').html(items.join(""));
            });
          
            $.getJSON( "/" + contextRoot + "/states-json.mvc?id="+countryid, function( data ) {
                let items = [];
                $.each( data, function( key, value ) {
                    console.log(value);
                    items.push( "<option value='" + value.id + "'>" + value.name + "</option>" );
                });
                $('#start_select3').html(items.join(""));
            });

    $('#start_select4').html("");
document.getElementById("timezoneName").value ="";

        })
        .on('change','#start_select2', function() {
//.on('change','#province', function() {
            let provinceID = $(this).val();
let stateID = 0;
            let countryid = $('#start_select1').val();
            $.getJSON( "/" + contextRoot + "/cities-json.mvc?id="+countryid+"&provinceID="+provinceID+"&stateID="+stateID, function( data ) {
                let items = [];
                $.each( data, function( key, value ) {
console.log(value);
                    items.push( "<option value='" + value.id + "'>" + value.name + "</option>" );
                });
                $('#start_select4').html(items.join(""));
            });
        })
.on('change','#start_select3', function() {
//.on('change','#state', function() {
            let stateID = $(this).val();
let provinceID = 0;
            let countryid = $('#start_select1').val();
            $.getJSON( "/" + contextRoot + "/cities-json.mvc?id="+countryid+"&provinceID="+provinceID+"&stateID="+stateID, function( data ) {
                let items = [];
                $.each( data, function( key, value ) {
console.log(value);
                    items.push( "<option value='" + value.id + "'>" + value.name + "</option>" );
                });
                $('#start_select4').html(items.join(""));
            });
        })
.on('change','#start_select4', function() {
//.on('change','#city', function() {
            let cityID = $(this).val();
            $.getJSON( "/" + contextRoot + "/timezone-json.mvc?cityID="+cityID, function( data ) {

if(data !=null){
    console.log(data.name);
    //$('#timezoneName').html(data.name);
document.getElementById("timezoneName").value = data.name;
}
                //let items = [];
                //$.each( data, function( key, value ) {
//console.log(value);
                    //items.push( "<option value='" + value.id + "'>" + value.name + "</option>" );
               // });
   //$('#timezoneName').html(items.join(""));
            });
        })
.on("click","#endpoint-submit",function(e) {
            e.preventDefault();
            confirmAdd(dataToParams($('#endpoint-form').data(),$(this).data()));
        });

});




    @RequestMapping(value = "/provinces-json", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public List<Province> getProvinceInJSON(@RequestParam(value="id", required = false) Long countryID,
            @PageableDefault(sort = "model.model", direction = Sort.Direction.ASC) Pageable pageable,
            Model model, HttpServletRequest request, HttpSession session) {
    List<Province> province;
   
    logger.info("get province,countryID:"+ countryID);
    if (countryID != null) {
    province = provinceRepository.searchByCountryIdAndFetchProvince(countryID);
    }else{
    province = null;
    }
    return province;
    }
   
    @RequestMapping(value = "/states-json", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public List<State> getStateInJSON(@RequestParam(value="id", required = false) Long countryID,
            @PageableDefault(sort = "model.model", direction = Sort.Direction.ASC) Pageable pageable,
            Model model, HttpServletRequest request, HttpSession session) {
    List<State> state;
   
    logger.info("get state,countryID:"+ countryID);
    if (countryID != null) {
    state = stateRepository.searchByCountryIdAndFetchState(countryID);
    }else{
    state = null;
    }
    return state;
    }  

    @RequestMapping(value = "/cities-json", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public List<City> getCityInJSON(@RequestParam(value="id", required = false) Long countryID,
    @RequestParam(value="provinceID", required = false) Long provinceID,
    @RequestParam(value="stateID", required = false) Long stateID,
            @PageableDefault(sort = "model.model", direction = Sort.Direction.ASC) Pageable pageable,
            Model model, HttpServletRequest request, HttpSession session) {
    List<City> city;
   
    logger.info("get city,countryID:"+ countryID);
    logger.info("get city,provinceID:"+ provinceID);
    logger.info("get city,stateID:"+ stateID);
    if (provinceID > 0 ) {
    city = cityRepository.searchByProvinceIdAndFetchCity(provinceID);
    }else{
    city = cityRepository.searchByStateIdAndFetchCity(stateID);
    }
    return city;
    }
   
   
    @RequestMapping(value = "/timezone-json", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Timezone getTimezoneInJSON(
    @RequestParam(value="cityID", required = false) Long cityID,
            @PageableDefault(sort = "model.model", direction = Sort.Direction.ASC) Pageable pageable,
            Model model, HttpServletRequest request, HttpSession session) {
   
    logger.info("get timezone,cityID:"+ cityID);
    if (cityID > 0 ) {
    Timezone  timezone = timezoneRepository.searchByCityIdAndFetchTimezone(cityID);
    logger.info("timezone:"+ timezone.getName());
    return timezone;
    }else{
    return null;
    }
    }  


分享到:
评论

相关推荐

    Thymeleaf中文参考手册_3.0.5版_thymeleaf_thymeleaf中文网_thymeleaf文档_thmele

    Thymeleaf的设计理念是使得静态模板在脱离服务器环境时也能正常工作,提供了一种易于阅读和维护的静态代码形式。其3.0.5版是该技术的一个稳定版本,具有诸多增强和改进。 Thymeleaf的主要特性包括: 1. **模板语言...

    thymeleaf-jar包

    在给定的"thymeleaf-jar包"中,包含了一系列依赖的jar文件,这些都是Thymeleaf正常工作所必需的库: 1. `thymeleaf-3.0.12.RELEASE.jar`:这是Thymeleaf的核心库,包含了所有处理模板和表达式的类。版本号3.0.12...

    Thymeleaf中文文档合集-最新版

    Thymeleaf是一款强大的Java模板引擎,常用于Web应用程序,特别是Spring MVC框架中,替代了JSP作为视图层技术。这个"Thymeleaf中文文档合集-最新版"包含了一系列的学习资源,如PDF、PPT等,帮助开发者深入理解和掌握...

    thymeleaf-3.0.11.RELEASE_release_spring_thymeleaf_

    在Spring框架中,Thymeleaf通常作为视图解析器使用,为开发人员提供了便捷的方式来构建动态Web页面。Thymeleaf-3.0.11.RELEASE是该引擎的一个特定版本,它包含了优化和修复的特性,以提高性能和稳定性。 1. **...

    thymeleaf-3.0.3.RELEASE-API文档-中文版.zip

    赠送jar包:thymeleaf-3.0.3.RELEASE.jar; 赠送原API文档:thymeleaf-3.0.3.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-3.0.3.RELEASE-sources.jar; 包含翻译后的API文档:thymeleaf-3.0.3.RELEASE-javadoc-...

    thymeleaf-3.0.12.RELEASE-API文档-中文版.zip

    赠送jar包:thymeleaf-3.0.12.RELEASE.jar; 赠送原API文档:thymeleaf-3.0.12.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-3.0.12.RELEASE-sources.jar; 赠送Maven依赖信息文件:thymeleaf-3.0.12.RELEASE.pom;...

    thymeleaf-3.0.9.RELEASE-API文档-中文版.zip

    赠送jar包:thymeleaf-3.0.9.RELEASE.jar; 赠送原API文档:thymeleaf-3.0.9.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-3.0.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:thymeleaf-3.0.9.RELEASE.pom; ...

    spring mvc整合thymeleaf示例

    thymeleaf,我个人认为是个比较好的模板,性能也比一般的,比如freemaker的要高,而且把将美工和程序员能够结合起来,美工能够在浏览器中查看静态效果,程序员可以在应用服务器查看带数据的效果。 thymeleaf是一个...

    springboot2.7.15+thymeleaf 代码

    SpringBoot 2.7.15 与 Thymeleaf 的整合是现代Java Web开发中的常见实践,这个项目提供了一个基础的实现,包括了登录功能以及员工管理的相关操作。Thymeleaf是一款强大的服务器端模板引擎,常用于Spring Boot应用中...

    thymeleaf使用+API

    Thymeleaf是一个面向web和独立环境的现代服务器端Java模板引擎。 Thymeleaf的主要目标是将优雅的自然模板引入到您的开发工作流程中——可以在浏览器中正确显示的HTML,也可以作为静态原型工作,从而在开发团队中实现...

    springboot整合thymeleaf完整例子

    本案例将详细讲解如何将SpringBoot与Thymeleaf进行整合,构建一个完整的Web应用。 首先,我们需要在SpringBoot项目中引入Thymeleaf的依赖。在`pom.xml`文件中,添加如下Maven依赖: ```xml &lt;groupId&gt;org.spring...

    springboot整合thymeleaf模板

    SpringBoot整合Thymeleaf模板是一项常见的Web开发任务,它结合了SpringBoot的便捷性和Thymeleaf的动态模板引擎,使得开发人员可以快速构建功能丰富的Web应用。下面将详细介绍这个过程及其涉及的关键知识点。 首先,...

    springboot与thymeleaf结合的实战、实例项目

    SpringBoot和Thymeleaf是两个非常流行的Java技术,它们在现代Web开发中扮演着重要角色。SpringBoot简化了Spring框架的配置,提供了快速启动和运行应用的方式,而Thymeleaf则是一种强大的模板引擎,它允许开发者在...

    thymeleaf_3.0.5_中文参考手册.pdf

    Thymeleaf 3.0.5 中文参考手册 Thymeleaf 是一个基于模板引擎的Java模板引擎,可以处理各种模板,例如HTML、XML、TXT等。Thymeleaf 的主要特点是它可以将模板解析为静态 HTML,然后将其传递给浏览器,从而提高页面...

    thymeleaf-spring5-3.0.10.RELEASE-API文档-中文版.zip

    赠送jar包:thymeleaf-spring5-3.0.10.RELEASE.jar; 赠送原API文档:thymeleaf-spring5-3.0.10.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-spring5-3.0.10.RELEASE-sources.jar; 赠送Maven依赖信息文件:...

    Spring boot + thymeleaf 后端直接给onclick函数赋值的实现代码

    "Spring Boot + Thymeleaf 实现后端直接给 onclick 函数赋值的知识点" Spring Boot 是一个基于 Java 的框架,用于构建基于 Web 的应用程序,而 Thymeleaf 是一个基于 XML 的模板引擎,用于生成 HTML 内容。在 ...

    Thymeleaf 官方参考手册

    Thymeleaf是一款强大的模板引擎,它在IT行业中被广泛应用于构建动态Web页面。作为Spring Boot官方推荐的解决方案,Thymeleaf以其独特的特性和易用性,使得开发者能够在前端和后端之间实现无缝协作。以下是对...

    Thymeleaf开发手册中文版

    ### Thymeleaf开发手册中文版知识点概览 #### 1. Thymeleaf简介 ##### 1.1 Thymeleaf是什么 Thymeleaf 是一个现代的、开源的 Java 模板引擎,适用于 Web 和非 Web 环境(如电子邮件、纯文本消息、PDF 文档等)。...

    Thymeleaf所需要的jar包

    - `thymeleaf-spring5.jar`(或`thymeleaf-servlet.jar`,取决于Spring版本):这个库是Thymeleaf与Spring框架集成的关键。它允许Thymeleaf与Spring MVC无缝协作,提供模型数据注入、视图解析等功能。 4. **...

    thymeleaf-spring5-3.0.12.RELEASE-API文档-中文版.zip

    赠送jar包:thymeleaf-spring5-3.0.12.RELEASE.jar; 赠送原API文档:thymeleaf-spring5-3.0.12.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-spring5-3.0.12.RELEASE-sources.jar; 赠送Maven依赖信息文件:...

Global site tag (gtag.js) - Google Analytics