美文网首页
flutter floor数据库查询有结果,实体对象没有值

flutter floor数据库查询有结果,实体对象没有值

作者: smallLabel | 来源:发表于2021-06-30 15:31 被阅读0次

今天在做数据库查询时,能返回正确的查询条数和实体对象,但是实体对象里都是空值,最后发现是因为实体对象没有创建构造函数导致的,新建一个构造函数就完美解决。记录一下。
附上我的实体类对象代码:

import 'package:floor/floor.dart';

@entity
class Beacon {
  @PrimaryKey(autoGenerate: true)
  int? id;
  String? major;
  String? minor;
  double? dx;
  double? dy;
  String? name;
  String? floorName;
  bool? indoor = true;
  int? gid;
  int? userid;
  String? projectionId;
  String? floorid;
  // 是否有修改
  bool? modified = false;
  String? mapId;

  void clear() {
    major = '';
    minor = '';
    dx = 0.0;
    dy = 0.0;
    name = null;
    floorName = null;
    gid = 1;
    projectionId = null;
    floorid = null;
    modified = false;
  }

  Beacon(
      {this.id,
      this.major,
      this.minor,
      this.dx,
      this.dy,
      this.name,
      this.floorName,
      this.floorid,
      this.indoor,
      this.gid,
      this.userid,
      this.projectionId,
      this.modified,
      this.mapId});

  @override
  bool operator ==(other) {
    if (other is! Beacon) {
      return false;
    }
    final Beacon beacon = other;
    return beacon.major == this.major &&
        beacon.minor == this.minor &&
        beacon.dx == this.dx &&
        beacon.dy == this.dy &&
        this.name == beacon.name &&
        this.floorName == beacon.floorName &&
        this.indoor == beacon.indoor &&
        this.gid == beacon.gid &&
        this.floorid == beacon.floorid &&
        this.projectionId == beacon.projectionId;
  }

  factory Beacon.fromJson(Map<String, dynamic> json) {
    String? major = json['deviceAttributes']['major'] as String?;
    String? minor = json['deviceAttributes']['minor'] as String?;
    double dx = (json['deviceAttributes']['x'] as num).toDouble();
    double dy = (json['deviceAttributes']['y'] as num).toDouble();
    bool indoor =
        json['deviceAttributes']['place'] as String == '室内' ? true : false;
    String projectionId = json['proId'] as String;
    String mapId = json['mapId'] as String;
    int userid = json['userId'] as int;
    String name = json['deviceName'];
    int gid = json['level'] ?? 1;
    String floorid = json['floorId'] as String;
    bool modified = false;
    Beacon beacon = Beacon(
        gid: gid,
        major: major,
        minor: minor,
        dx: dx,
        dy: dy,
        indoor: indoor,
        projectionId: projectionId,
        mapId: mapId,
        userid: userid,
        name: name,
        floorid: floorid,
        modified: modified);

    return beacon;
  }
}

相关文章

  • flutter floor数据库查询有结果,实体对象没有值

    今天在做数据库查询时,能返回正确的查询条数和实体对象,但是实体对象里都是空值,最后发现是因为实体对象没有创建构造函...

  • floor flutter数据库操作库

    floor flutter数据库操作库 github地址 Floor为您的Flutter应用程序提供了一个简洁的S...

  • flutter floor数据库的简单使用

    引入floor插件在pubspec.yaml中引入floor插件image.png 创建数据库实体类,实体类在数据...

  • Mybatis之ObjectWrapper接口

    该接口用来对数据库查询到的值设置到实体对象或Map对象的属性中。接口定义如下: 实现该接口的类结构图如下所示: 其...

  • Mybatisday02

    特殊情况示栗: 修改实体类 我们运行 findAll() 查询结果如下 查出上面结果的原因是数据库字段与实体类没有...

  • DDD

    实体与值对象的区别: 实体拥有标识,而值对象没有。 相等性测试方式不同。实体根据标识判等,而值对象根据内部所有属性...

  • 领域模型核心概念:实体、值对象和聚合根(未完工)

    聚合根、实体和值对象 实体有ID标识,有生命周期,有状态(用值对象来描述状态),实体通过ID进行区分聚合根是实体,...

  • 昨日bug

    多表关联查询数据库可以查出值,但是在jsp页面没有显示,也没有报错。原因是实体类中没有加入其他表所对应的值。 比如...

  • Spring Data JPA 分页查询 映射自定义对象

    1. Spring Data JPA 查询接收自定义对象 (非数据库对应的实体类)需要我们定义一个接收返回结果集的...

  • 利用切面关闭spring-data-jpa的自动更新入库

    当用了事务后,用jpa从数据库中查出来的实体对象,直接变更实体对象属性值,即使不调用repository.save...

网友评论

      本文标题:flutter floor数据库查询有结果,实体对象没有值

      本文链接:https://www.haomeiwen.com/subject/gsyrultx.html