笔者最近被坑了好几次!这个坑简单的说就是字符串与数字不能相等,即使他们表达的值是一样的!
笔者遇到这个坑的地方有:
1、java中:
String suid="1"
Long luid=1L;
suid.equal(luid);
这里不报错!但是永远是不等的!
2、redis中
redisTemplate.opsForSet().add("set","1");
redisTemplate.opsForSet().isMember("set",1);
这里也不报错!但是永远返回false!
3、vue中
<el-form-item label-width="80px" label="类型">
<el-select v-model="topic.state" @change="changeTopicState(indexTopic)">
<el-option v-for="item in topicStates" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
</el-form-item>
其中topicStates为
topicStates:[
{id:'0',name:'单选题'},
{id:'1',name:'多选题'},
{id:'3',name:'填空题'},
],
本来3没有什么问题,但是后台topic对象的state在数据库中保存的类型为Number,java中的类型为Integer,向前台传时也没有格式化成string,则该下拉选中显示的是0/1/3,而不是文字