若依框架复选框根据数据库回显选中状态(只需要修改前端页面即可)

若依框架复选框根据数据库回显选中状态:

这是我在做自己的项目的时候遇到的前端复选框回显的问题:通过函数调用显示复选框的选中状态,根据数据字典和实体类中的属性相对应


排雷

我这是用到的若以自动生成的代码,然后引入到项目中的修改页面,与新增页面一致,只是增加了checked这个方法:

<div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">建筑类型:label>
                        <div class="col-sm-8">
                            <div class="check-box" th:each="dict : ${@dict.getType('gongcheng_jzlx')}">
                                <input type="checkbox"  name="jzlx" th:id="${dict.dictCode}" th:value="${dict.dictValue}" th:attr ='checked=${pmsGongcheng.jzlx!=null&&pmsGongcheng.jzlx.contains(dict.dictValue)?true:false}'>
                                <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}">label>
                            div>
                        div>
                    div>
                div>

我在此提供两种回显函数:

th:attr ='checked=${你的实体类.你的实体类中显示复选框的属性名!=null&&你的实体类.你的实体类中显示复选框的属性名.contains(dict.dictValue)?true:false}'
th:checked="${你的实体类.你的实体类中显示复选框的属性名!=null&&#arrays.contains(#strings.arraySplit(你的实体类.你的实体类中显示复选框的属性名,','),#strings.toString(dict.dictValue))}"

解决:

你所要做的就是把th:checked后面的判断写成我所写的一样,修改自己的实体类以及类中的属性,后端的控制层不需要做任何的改变,你的xml层需要做一点修改:你回显的属性名一定不可以加if里面的约束条件,如果加了约束条件,他会在你点击取消的时候仍然显示你最后保留的一个复选框,一定不要加if约束

<update id="updatePmsGongcheng" parameterType="com.lrkj.pms.ztjg.common.domain.PmsGongcheng">
        update pms_gongcheng
        <trim prefix="SET" suffixOverrides=",">
            <if test="gcmc != null">gcmc = #{gcmc},if>
            <if test="gcbh != null">gcbh = #{gcbh},if>
            <if test="deptId != null">dept_id = #{deptId},if>
            <if test="wtdw != null">wtdw = #{wtdw},if>
            <if test="dtsl != null">dtsl = #{dtsl},if>
            <if test="lxr != null">lxr = #{lxr},if>
            <if test="lxrphone != null">lxrphone = #{lxrphone},if>
            <if test="gcxz != null">gcxz = #{gcxz},if>
            <if test="wtbh != null">wtbh = #{wtbh},if>
            jzlx = #{jzlx},


你可能感兴趣的:(若依,java,前端,xml)