小编Dan*_*iel的帖子

如何在 Spring Boot 中使用 Mapstruct 映射父级和子级?

我有父级(产品)和子级(书籍、家具),并且希望将产品实体映射到产品 DTO。如您所见,产品被映射并存储在数据库中的单个表中。如何映射具有子项额外详细信息的父项产品?

我看过这个这个这个来得到一些想法,但没有运气

实体

@Entity
@Table(name = "product")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Product {
  @Id
  private long id;
  private String productName;
}

@Entity
@DiscriminatorValue("Book")
public class Book extends Product { 
  private String author;
  ...
}
@Entity
@DiscriminatorValue("Furniture")
public class Furniture extends Product {
  String color;
  ...
}
Run Code Online (Sandbox Code Playgroud)

数据传输组织

public class ProductDto {
  private long id;
  private String productName;
  ...
}

public class BookDto extends ProductDto {
  private String author;
  ...
}
public class …
Run Code Online (Sandbox Code Playgroud)

java spring-boot mapstruct

10
推荐指数
1
解决办法
2万
查看次数

如何在 dart 中创建多个构造函数?

我想通过调用具有不同数量参数的构造函数来创建不同的对象。我怎样才能在 Dart 中实现这一目标?

class A{
  String b,c,d;

  A(this.b,this.c)
  A(this.b,this.c,this.d)

}
Run Code Online (Sandbox Code Playgroud)

dart flutter

2
推荐指数
1
解决办法
2587
查看次数

如何在flutter中应用MVC或设计模式?

我正在尝试使用local_auth包包含生物识别身份验证。这在应用程序启动时使用。指纹用于确定用户是否为手机的所有者。如果确认,他们将被带到主页。下面的代码有效,但我想在下面的代码中应用的是MVCor design pattern。有人可以指导我吗?

class LoginOptionState extends State<LoginOption> {
  final LocalAuthentication auth = LocalAuthentication();
  String _authorized = 'Not Authorized';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: new Container(
            child: Center(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          new Column(
            children: <Widget>[
              Text("Touch ID"),
              SizedBox(height: 10),
              GestureDetector(
                  child: Image.asset(
                    "assets/",
                  ),
                  onTap: _authenticate),
            ],
          ),
        ],
      ),
    )));
  }

  Future<void> _authenticate() async {
    bool authenticated = false;
    try {
      authenticated = await auth.authenticateWithBiometrics(
          localizedReason: 'Scan your fingerprint …
Run Code Online (Sandbox Code Playgroud)

dart flutter

2
推荐指数
1
解决办法
7536
查看次数

标签 统计

dart ×2

flutter ×2

java ×1

mapstruct ×1

spring-boot ×1