search

Home  >  Q&A  >  body text

mysql - jsp+servlet实现多表联合查询,如何建立javabean

1,数据库表为(员工<主键id,员工姓名name>,部门<主键id,外键em_id,部门department,职位post>);
2,实现按员工姓名查询,得出所属部门和职位
3,按部门查询,得出该部门所有的人员

巴扎黑巴扎黑2888 days ago921

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:36:40

    First of all, you must determine the relationship between tables;
    One-to-many, many-to-one or many-to-many.
    Employee employee table Department department table
    Then the entity can be created like this:
    Class Employee {
    private String id;
    private String name;
    private List< ;Department> depts;
    }

    Class Department {
    private String id;
    private String post;
    private List<Employee> employee;
    }
    This is the most standard way of writing, If the diagram is simple, you can write all the fields involved into a class;
    The next step depends on the SQL statement you write. Are you using mybaits or Hibernate or something else.

    reply
    0
  • Cancelreply