javaWeb的多表操作

映射关系的建立

对象关系映射(Object Relation Mapping),指的是 数据库表和对象之间的一种映射关系。在建立对象映射 时,通常情况下会采用以下形式:

一对多

在一的一方,建立多的的一方的集合,由 于考虑到集合中的对象必须是唯一的,所 以通常会采用Set集合实现,由于一对多 的查询方式较为复杂而且不利于维护,所 以通常采用多对一的查询方式。

多对一

在多的一方,建立对一的一方的引用。

结论:一方存多方的集合,多方存一方的对象

新闻对象

package com.csi.journalism.domain;

import java.util.Date;

public class Journalism {

    private Integer j_id;

    private String j_title;

    private Date j_postedTime;

    private String j_source;

    private String j_content;

    private String j_compile;

    private int j_type_id;

//多方存一方的对象
    private J_type j_type;

    public Integer getJ_id() {
        return j_id;
    }

    public void setJ_id(Integer j_id) {
        this.j_id = j_id;
    }

    public String getJ_title() {
        return j_title;
    }

    public void setJ_title(String j_title) {
        this.j_title = j_title;
    }

    public Date getJ_postedTime() {
        return j_postedTime;
    }

    public void setJ_postedTime(Date j_postedTime) {
        this.j_postedTime = j_postedTime;
    }

    public String getJ_source() {
        return j_source;
    }

    public void setJ_source(String j_source) {
        this.j_source = j_source;
    }

    public String getJ_content() {
        return j_content;
    }

    public void setJ_content(String j_content) {
        this.j_content = j_content;
    }

    public String getJ_compile() {
        return j_compile;
    }

    public void setJ_compile(String j_compile) {
        this.j_compile = j_compile;
    }

    public int getJ_type_id() {
        return j_type_id;
    }

    public void setJ_type_id(int j_type_id) {
        this.j_type_id = j_type_id;
    }

    public J_type getJ_type() {
        return j_type;
    }

    public void setJ_type(J_type j_type) {
        this.j_type = j_type;
    }
}

新闻类型的对象

package com.csi.journalism.domain;

import java.util.Set;

public class J_type {

    private Integer j_type_id;

    private String j_type_name;

    private String j_type_explain;

    private String j_type_img;

    private Set<Journalism> journalismSet;//一方存多方的集合

    public Integer getJ_type_id() {
        return j_type_id;
    }

    public void setJ_type_id(Integer j_type_id) {
        this.j_type_id = j_type_id;
    }

    public String getJ_type_name() {
        return j_type_name;
    }

    public void setJ_type_name(String j_type_name) {
        this.j_type_name = j_type_name;
    }

    public String getJ_type_explain() {
        return j_type_explain;
    }

    public void setJ_type_explain(String j_type_explain) {
        this.j_type_explain = j_type_explain;
    }

    public String getJ_type_img() {
        return j_type_img;
    }

    public void setJ_type_img(String j_type_img) {
        this.j_type_img = j_type_img;
    }

    public Set<Journalism> getJournalismSet() {
        return journalismSet;
    }

    public void setJournalismSet(Set<Journalism> journalismSet) {
        this.journalismSet = journalismSet;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值