> For the complete documentation index, see [llms.txt](https://65480539.gitbook.io/goft/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://65480539.gitbook.io/goft/jing-jian-ban-ling-yu-qu-dong/ling-yu-ceng-zhi-shi-ti.md).

# 领域层之实体

其实和我们常规的实体差别并不大，不要想的太复杂

## 建立领域模型的第一步就是需要识别出实体、值对象&#x20;

谁来识别？ 当然是饱受996的我们了。。。。。

譬如用户实体:UserModel

```
type UserModel struct {
   UserId int `gorm:"column:user_id;primary_key;auto_increment" json:"user_id"  xorm:"'user_id'"`
   UserName string `gorm:"column:user_name" json:"user_name" xorm:"'user_name'"`
   UserPwd string `gorm:"column:user_pwd" json:"-" xorm:"'user_pwd'"`
}
```

实体必须有唯一标识，譬如下面这个就不是实体，但不代表不能建立。你如果有特殊用途，这么建完全没问题。只不过它不是实体而已

```
type UserModel struct {
   UserPwd string `gorm:"column:user_pwd" json:"-" xorm:"'user_pwd'"`
}
```

## 在我们脚手架中实体和领域驱动的实体概念一致，不过需要有个接口

```
type IModel interface {
   Name() string
}
```

建立的所有实体，必须实现Name方法。返回实体名称
