接着昨天的项目继续开发:
新闻实体类:
@Entity
@Table(name = "t_news")
public class News {
@Id //主键标识
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@Basic(fetch = FetchType.LAZY) //懒加载
@Lob
private String content;
private String firstPicture;
private String flag;
private String views;
private boolean appreciation;
private boolean shareStatement;
private boolean commentabled;
private boolean published;
private boolean recommend;
@Temporal(TemporalType.TIMESTAMP) //年月日-时分秒
private Date createTime;
@Temporal(TemporalType.TIMESTAMP)
private Date updateTime;
@ManyToOne
private Type type;
@ManyToOne
private User user;
@ManyToMany(cascade = CascadeType.PERSIST) //级联
private List<Tag> tags=new ArrayList<>();
@Transient //该注解表示不会被映射到数据库中
private String tagIds;//接收前端页面传过来的标签Id
private String description;
}
创建vo包,VO是指value object值对象,通常用于业务层之间的数据传递,和PO一样也是仅仅包含数据而已。一般来说,PO只能用在数据层,VO用在商业逻辑层和表示层。在vo包下创建NewsQuery类,我们利用NewsQuery类专门处理新闻管理界面的条件查询。因为我们需要通过新闻的标题、类型以及是否被推荐作为条件来查询数据库里的新闻,所以我们就利用这三个属性来组成一个查询类。
public class NewQuery {
private String title;
private Long typeId;
private boolean recommend;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Long getTypeId() {
return typeId;
}
public void setTypeId(Long typeId) {
this.typeId = typeId;
}
public boolean isRecommend() {
return recommend;
}
public void setRecommend