场景

Vue+ElementUI+SpringBoot+Mysql

需要设计一些属性为是否,即只有两个选择的属性字段。

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

首先设计Mysql数据库,此字段设计为长度为1的tinyint

 

 

 

然后在SpringBoot中的实体类中

 private Boolean sfkt;

将其设置为Boolean

这样在使用代码生成器等时会自动将0映射为false,将1映射为true。

这样在mapper的xml中仍然可以使其作为查询条件

    <select id="selectKqBcglList" parameterType="KqBcgl" resultMap="KqBcglResult">
        <include refid="selectKqBcglVo"/>
        <where>
            <if test="bcbh != null  and bcbh != ''"> and bcbh = #{bcbh}</if>
            <if test="sfkt != null  and sfkt != ''"> and sfkt = #{sfkt}</if>
            <if test="xss != null  and xss != ''"> and xss = #{xss}</if>
            <if test="sfyb != null  and sfyb != ''"> and sfyb = #{sfyb}</if>
        </where>
    </select>

在Element中通过axios请求接口后获取数据时获取的是0和1。

如果此时不加格式化的化就会在页面上显示1和0。

所以在

<el-table-column label="是否跨天" align="center" prop="sfkt" :formatter="sfktFormate" />

添加formatter属性对应的sfktFormate是一个方法

    sfktFormate(row, index) {
      if (row.sfkt == 1) {
        return "";
      } else {
        return "";
      }
    },

其中row就是传递的当前行对象,row.sfkt要对应上面prop的sfkt

这样就能格式化显示为是和否

 

 

posted on 2020-07-30 10:20  霸道流氓  阅读(296)  评论(0编辑  收藏  举报

Live2D