`
maxer025
  • 浏览: 75336 次
  • 性别: 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.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.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-...

    spring mvc整合thymeleaf示例

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

    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; ...

    thymeleaf使用+API

    Thymeleaf是一个面向web和独立环境的现代服务器端Java模板引擎。 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依赖信息文件:...

    thymeleaf-extras-java8time-3.0.1.RELEASE-API文档-中文版.zip

    赠送jar包:thymeleaf-extras-java8time-3.0.1.RELEASE.jar; 赠送原API文档:thymeleaf-extras-java8time-3.0.1.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-extras-java8time-3.0.1.RELEASE-sources.jar; 赠送...

    thymeleaf-extras-java8time-3.0.4.RELEASE-API文档-中英对照版.zip

    赠送jar包:thymeleaf-extras-java8time-3.0.4.RELEASE.jar; 赠送原API文档:thymeleaf-extras-java8time-3.0.4.RELEASE-javadoc.jar; 赠送源代码:thymeleaf-extras-java8time-3.0.4.RELEASE-sources.jar; 赠送...

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

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

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

    Thymeleaf中文文档,内容很详细,可用于做API参考。

    Springboot Thymeleaf模板文件调用Java类静态方法

    在模板文件的表达式中,可以使用“${T(全限定类名).方法名(参数)}”这种格式来调用Java类的静态方法。 开发环境:IntelliJ IDEA 2019.2.2 ... &lt;artifactId&gt;spring-boot-starter-thymeleaf &lt;/dependenc

    springboot项目实训源代码+thymeleaf+mysql+mybatis

    4、thymeleaf模板的配置,常用标签的使用,if,for,include,replace标签 6、用户管理:新增,修改,删除,查询功能 9、页面功能由html+thymeleaf实现 10、数据库脚本及数据在项目源代码主文件夹user.sql 课程资料...

    thymeleaf-3.0.5.zip

    thymeleaf-3.0.5中文文档,清晰无广告,官方中文翻译 1.Thymeleaf简介 2.示例项⽬:Good Thymes Virtual Grocery 3.使⽤⽂本 4.标准表达式语法 5.设置属性值 6.循环迭代 7.条件判断 8.模板布局 9.局部变量 10.属性...

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

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

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

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

    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;...

    SpringBoot2整合thymeleaf3及thymeleaf3语法.md

    ## springboot整合thymeleaf ### 1. 导入起步依赖 ```xml &lt;groupId&gt;org.springframework.boot &lt;artifactId&gt;spring-boot-starter-thymeleaf ``` ### 2. 更改引入版本 ```xml &lt;springboot-thymeleaf.version...

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

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

    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.14.RELEASE-API文档-中英对照版.zip

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

Global site tag (gtag.js) - Google Analytics