1.创建如下数据库脚本

 --创建用户信息表
--编号,用户名,密码,年龄,性别,昵称,手机,地址,管理员,图像地址
create table users
(
id number(10) primary key,
username varchar2(20) not null,
password varchar2(40) not null,
age number(10) not null,
sex number(10) not null,
nickname varchar2(20) not null,
mobile varchar2(15) not null,
address varchar2(50) not null,
supper number(10) not null,
picpath varchar2(100) not null
); --创建微博表
--编号,内容,发布时间,用户编号
create table blog
(
id number(10) primary key,
content varchar2(1000) not null,
publishtime date not null,
userid number(10) references users(id)
); --创建序列
create sequence seq_users;
create sequence seq_blog; --插入数据
insert into users
(
id,username,password,age,sex,nickname,
mobile,address ,supper,picpath
)
values
(seq_users.nextval,'holly','',18,0,'holly上神',
'','雨花台铁心桥新河苑',0,'holly.jpg'); insert into users
(
id,username,password,age,sex,nickname,
mobile,address ,supper,picpath
)
values
(seq_users.nextval,'倩倩','',18,0,'倩倩上仙',
'','大桥北路',1,'qianqian.jpg'); insert into users
(
id,username,password,age,sex,nickname,
mobile,address ,supper,picpath
)
values
(seq_users.nextval,'死胖子','',28,1,'死盘子小仙',
'','湖北非洲',1,'sipangzi.jpg'); insert into users
(
id,username,password,age,sex,nickname,
mobile,address ,supper,picpath
)
values
(seq_users.nextval,'肉肉','',38,1,'肉肉小妖',
'','新街口八条巷',1,'rourou.jpg'); insert into users
(
id,username,password,age,sex,nickname,
mobile,address ,supper,picpath
)
values
(seq_users.nextval,'戴文','',38,1,'文文上仙',
'','东海瀛洲',1,'daiwen.jpg'); commit; insert into blog
(id,content,publishtime,userid)
values
(
seq_blog.nextval,'上神已经下凡渡劫失败...',
to_date('2017-01-01','yyyy-MM-dd'),1
); insert into blog
(id,content,publishtime,userid)
values
(
seq_blog.nextval,'上神已经去东海瀛洲去营救...',
to_date('2017-01-02','yyyy-MM-dd'),1
); insert into blog
(id,content,publishtime,userid)
values
(
seq_blog.nextval,'上神中午下凡去看团子...',
to_date('2017-01-03','yyyy-MM-dd'),1
); insert into blog
(id,content,publishtime,userid)
values
(
seq_blog.nextval,'上神中午已去十里桃源...',
to_date('2017-01-04','yyyy-MM-dd'),1
); insert into blog
(id,content,publishtime,userid)
values
(
seq_blog.nextval,'小仙已经去了诛仙台...',
to_date('2017-01-05','yyyy-MM-dd'),2
);
commit; select * from users u,blog b
where u.id=b.userid;

blog.sql

2.创建如下项目结构

3.在src下的com.pojo包下创建Users.java 类

 package com.pojo;

 import java.io.Serializable;
import java.util.HashSet;
import java.util.Set; /**
* 一方(一对多)
* 一方:引入多方集合
*@author 北大青鸟南京中博 Holly老师
*
*/
public class Users implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer id; //用户编号
private String username; //用户名
private String password; //用户密码
private Integer age; //年龄
private Integer sex; //性别
private String nickname; //昵称
private String mobile; //手机
private String address; //地址
private Integer supper; //是否是管理员
private String picpath; //头像名称
/*hibernte一对多*/
private Set<Blog> blogset=new HashSet<Blog>(); public Users() {
} public Users(String username, String password, Integer age, Integer sex,
String nickname, String mobile, String address, Integer supper,
String picpath) {
this.username = username;
this.password = password;
this.age = age;
this.sex = sex;
this.nickname = nickname;
this.mobile = mobile;
this.address = address;
this.supper = supper;
this.picpath = picpath;
} public Users(Integer id, String username, String password, Integer age,
Integer sex, String nickname, String mobile, String address,
Integer supper, String picpath) {
this.id = id;
this.username = username;
this.password = password;
this.age = age;
this.sex = sex;
this.nickname = nickname;
this.mobile = mobile;
this.address = address;
this.supper = supper;
this.picpath = picpath;
} public Users(Integer id, String username, String password, Integer age,
Integer sex, String nickname, String mobile, String address,
Integer supper, String picpath, Set<Blog> blogset) {
super();
this.id = id;
this.username = username;
this.password = password;
this.age = age;
this.sex = sex;
this.nickname = nickname;
this.mobile = mobile;
this.address = address;
this.supper = supper;
this.picpath = picpath;
this.blogset = blogset;
} public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getSupper() {
return supper;
}
public void setSupper(Integer supper) {
this.supper = supper;
}
public String getPicpath() {
return picpath;
}
public void setPicpath(String picpath) {
this.picpath = picpath;
} public Set<Blog> getBlogset() {
return blogset;
} public void setBlogset(Set<Blog> blogset) {
this.blogset = blogset;
} @Override
public String toString() {
return "Users [address=" + address + ", age=" + age + ", blogset="
+ blogset + ", id=" + id + ", mobile=" + mobile + ", nickname="
+ nickname + ", password=" + password + ", picpath=" + picpath
+ ", sex=" + sex + ", supper=" + supper + ", username="
+ username + "]";
} }

Users.java

4.在src下的com.pojo包下创建Blog.java类

 package com.pojo;

 import java.io.Serializable;
import java.util.Date; /**
* 多方:多对一
* 多方:配置对象
* @author 北大青鸟南京中博 Holly老师
*
*/
public class Blog implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer id;
private String content;
private Date publishtime; /*多方外建列:引入一方对象*/
private Users users; public Blog() {
} public Blog(String content, Date publishtime, Users users) {
this.content = content;
this.publishtime = publishtime;
this.users = users;
} public Blog(Integer id, String content, Date publishtime, Users users) {
this.id = id;
this.content = content;
this.publishtime = publishtime;
this.users = users;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public Date getPublishtime() {
return publishtime;
} public void setPublishtime(Date publishtime) {
this.publishtime = publishtime;
} public Users getUsers() {
return users;
} public void setUsers(Users users) {
this.users = users;
} @Override
public String toString() {
return "Blog [content=" + content + ", id=" + id + ", publishtime="
+ publishtime + "]";
} }

Blog.java

5.在src下的com.pojo包下创建Users.hbm.xml文件

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.pojo.Users" table="USERS">
<!-- 1.主键列 -->
<id name="id" type="java.lang.Integer" column="ID">
<generator class="sequence">
<param name="sequence">seq_users</param>
</generator>
</id> <!-- 2.普通字段配置 -->
<property name="username" type="java.lang.String" column="USERNAME"/>
<property name="password" type="java.lang.String" column="PASSWORD"/>
<property name="sex" type="java.lang.Integer" column="SEX"/>
<property name="age" type="java.lang.Integer" column="AGE"/>
<property name="nickname" type="java.lang.String" column="NICKNAME"/>
<property name="mobile" type="java.lang.String" column="MOBILE"/>
<property name="address" type="java.lang.String" column="ADDRESS"/>
<property name="supper" type="java.lang.Integer" column="SUPPER"/>
<property name="picpath" type="java.lang.String" column="PICPATH"/> <!-- 3.一对多: -->
<!--
name:一方引入对方set集合的对象名称
column:是多方的的外键列名
class:是一方引入对象集合的对象类型全路径
-->
<set name="blogset">
<key column="userid"/>
<one-to-many class="com.pojo.Blog"/>
</set>
</class>
</hibernate-mapping>

Users.hbm.xml

6.在src下的com.pojo包下创建Blog.hbm.xml文件

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.pojo.Blog" table="BLOG">
<!-- 1.主键配置 -->
<id name="id" column="ID" type="java.lang.Integer">
<!-- 主键是序列 -->
<generator class="sequence">
<param name="sequence">seq_blog</param>
</generator>
</id>
<!-- 2.普通字段配置 -->
<property name="content" column="CONTENT" type="java.lang.String"/>
<property name="publishtime" column="PUBLISHTIME" type="java.util.Date"/> <!-- 3.多对一配置 -->
<!--
name:是Blog类引入一方类对象名,
column:是blog表中引入一方的外键列列名
class:是Blog类引入一方对象的属性名的类全路径
-->
<many-to-one name="users" class="com.pojo.Users" column="USERID" />
</class>
</hibernate-mapping>

Blog.hbm.xml

7.在src下创建hibernate.cfg.xml主配置文件

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<!-- 1.数据库驱动 -->
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<!-- 2.数据库url -->
<property name="connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:orcl
</property>
<!-- 3.数据库的用户名 -->
<property name="connection.username">holly</property>
<!-- 4.数据库密码 -->
<property name="connection.password">sys</property>
<!-- 5.数据库方言 -->
<property name="dialect">
org.hibernate.dialect.Oracle10gDialect
</property>
<!-- 6.显示sql -->
<property name="show_sql">true</property>
<!-- 7.sql格式化 -->
<property name="format_sql">true</property> <!-- 8.注册xml文件 -->
<mapping resource="com/pojo/Blog.hbm.xml"/>
<mapping resource="com/pojo/Users.hbm.xml"/>
</session-factory>
</hibernate-configuration>

hibernate.cfg.xml

8.在src下的com.util包下创建HibernateUtil.java 获取Session的工具类

 package com.util;

 import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; /**
* hiberante获取Session的工具类
* @author 北大青鸟南京中博 Holly老师
*
*/
public class HibernateUtil {
//1.创建线程池(存放session对象)
private static ThreadLocal<Session> threadLocal=new ThreadLocal<Session>();
//2.定义Configuration对象解析主配置文件
private static Configuration configuration=null;
//3.定义SessionFactory工厂对象
private static SessionFactory sessionFactory=null;
//4.static中解析xml获取SessionFactory
static{
try {
configuration=new Configuration().configure("hibernate.cfg.xml");
sessionFactory=configuration.buildSessionFactory();
} catch (HibernateException e) {
System.out.println("sessionFactory 解析hibernate.cfg.xml error");
e.printStackTrace();
}
}
//5.获取session对象
public static Session getSession(){
Session session=threadLocal.get();
if(session==null){
session=sessionFactory.openSession();
threadLocal.set(session);
}
return session;
}
//6.关闭session对象
public static void closeSession(){
Session session=threadLocal.get();
threadLocal.set(null);
session.close();
} }

HibernateUtil.java

9.在src下的com.dao包下创建UsersDao.java接口

 package com.dao;

 import java.util.List;

 import com.pojo.Users;
/**
* 用户数据访问层接口
@author 北大青鸟南京中博 Holly老师
*
*/
public interface UsersDao {
/**
* 一方只需要提供下拉列表的集合即可
* @param pageno
* @param pagesize
* @param id
* @return
*/
List<Users> findAllBlog(); }

UsersDao.java

10.在src下的com.dao包下创建BlogDao.java接口

 package com.dao;

 import java.util.List;

 import com.pojo.Blog;
/**
* 博客数据访问层接口
@author 北大青鸟南京中博 Holly老师
*
*/
public interface BlogDao {
/**
* 分页查询
* @param pageno
* @param pagesize
* @param userid
* @return
*/
List<Blog> findAllBlogPage(Integer pageno,Integer pagesize,Integer userid);
/**
* 统计数据条数
* @param userid
* @return
*/
Integer getTotalCount(Integer userid);
}

BlogDao.java

11.在src下的com.dao.impl包下创建UsersDaoImpl.java

 package com.dao.impl;

 import java.util.List;

 import org.hibernate.Query;
import org.hibernate.Session; import com.dao.UsersDao;
import com.pojo.Users;
import com.util.HibernateUtil;
/**
* 用户数据访问层实现类
@author 北大青鸟南京中博 Holly老师
*
*/
public class UsersDaoImpl implements UsersDao {
/**
* 一方只需要提供下拉列表的集合即可
* @return
*/
public List<Users> findAllBlog() {
Session session=HibernateUtil.getSession();
Query query=session.createQuery("from Users");
//查询所有 return query.list();
} }

UsersDaoImpl.java

12.在src下的com.dao.impl包下创建BlogDaoImpl.java

 package com.dao.impl;

 import java.util.List;

 import org.hibernate.Query;
import org.hibernate.Session; import com.pojo.Blog;
import com.util.HibernateUtil;
/**
* 博客数据访问层实现类
@author 北大青鸟南京中博 Holly老师
*
*/
public class BlogDaoImpl implements com.dao.BlogDao {
/**
* 分页查询
* @param pageno
* @param pagesize
* @return
*/
public List<Blog> findAllBlogPage(Integer pageno, Integer pagesize,
Integer userid) {
Session session=HibernateUtil.getSession();
Query query=null; if(userid!=0){
//条件分页
query=session.createQuery("from Blog where userid=:userid");
query.setParameter("userid",userid);
}else{
//普通分页
query=session.createQuery("from Blog"); }
//1.设置页面大小
query.setMaxResults(pagesize); //2.设置分页起始行
query.setFirstResult((pageno-1)*pagesize); //3.分页查询
return query.list(); }
/**
* 统计数据条数
* @param userid
* @return
*/
public Integer getTotalCount(Integer userid) {
Session session=HibernateUtil.getSession();
Query query=null;
if(userid!=0){
//统计某个用户下的信息
query=session.createQuery("select count(*) from Blog where userid=:userid");
query.setParameter("userid",userid);
}else{
//统计所有用户下的信息
query=session.createQuery("select count(*) from Blog");
} //查询总条数
String strcount=query.uniqueResult().toString();
Integer totalcount=Integer.valueOf(strcount);
return totalcount;
} }

BlogDaoImpl.java

13.在src下的com.servlet包下创建BlogServlet.java控制类

 package com.servlet;

 import java.io.IOException;
import java.io.PrintWriter;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import com.dao.BlogDao;
import com.dao.UsersDao;
import com.dao.impl.BlogDaoImpl;
import com.dao.impl.UsersDaoImpl;
import com.pojo.Blog;
import com.pojo.Users;
/**
* 博客控制层类
@author 北大青鸟南京中博 Holly老师
*
*/
public class BlogServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html"); String flag=request.getParameter("flag");
BlogDao blogdao=new BlogDaoImpl();
UsersDao usersdao=new UsersDaoImpl();
//1.查询
if(flag==null){ System.out.println("findAll"); //分页
String no=request.getParameter("pageno");
Integer pagesize=3;
Integer pageno=1;
if(no!=null && no!=""){
pageno=Integer.valueOf(no);
} //条件分页
String id=request.getParameter("userid");
System.out.println("userid:"+id);
Integer userid=0; //一方集合 if(id!=null){
userid=Integer.valueOf(id);
} //某个用户下的微博信息条数
Integer totalcount=blogdao.getTotalCount(userid); Integer totalpage=totalcount%pagesize==0?totalcount/pagesize:totalcount/pagesize+1; //某个用户下的所有微博信息和所有用户关联的微博信息
//微博的条件查询和查询所有
List<Blog> bloglist=blogdao.findAllBlogPage(pageno, pagesize, userid); //查询所有的用户集合:目的用于下拉列表(查询所有)
List<Users> userslist=usersdao.findAllBlog(); if(userslist!=null){
System.out.println("findall success...");
request.setAttribute("bloglist", bloglist);
request.setAttribute("pageno", pageno);
request.setAttribute("totalcount", totalcount);
request.setAttribute("totalpage", totalpage);
request.setAttribute("userid", userid); HttpSession session=request.getSession();
session.setAttribute("userslist", userslist);
request.getRequestDispatcher("index.jsp").forward(request, response); }else{
System.out.println("findall bloglist error..."); } } } }

BlogServlet.java

14.在WebRoot下的WEB-INF下的web.xml配置servlet

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>BlogServlet</servlet-name>
<servlet-class>com.servlet.BlogServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>BlogServlet</servlet-name>
<url-pattern>/BlogServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>BlogServlet</welcome-file>
</welcome-file-list>
</web-app>

web.xml

15.在WebRoot下创建index.jsp页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<CENTER>
<fieldset>
<legend style="font-size:36px;font-weight:bold;">&lt;&lt;三生三世十里桃花&gt;&gt;管理系统</legend>
<h3><a href="add.jsp">加入仙班</a></h3>
<form action="BlogServlet" method="post">
昵称:
<select name="userid">
<option value="0" selected="selected">--请选择--</option>
<c:forEach var="i" items="${userslist}">
<c:choose>
<c:when test="${userid eq i.id}">
<option value="${i.id }" selected="selected">${i.nickname }</option>
</c:when>
<c:otherwise>
<option value="${i.id }">${i.nickname }</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
<input type="submit" value="搜"/>
</form>
<table border="1">
<tr>
<td>用户头像</td>
<td>微博内容</td>
<td>发布时间</td>
<td>用户昵称</td>
<td>用户性别</td>
<td>联系方式</td>
<td>管理员?</td>
<td>操作</td>
</tr>
<c:forEach var="i" items="${bloglist}">
<tr>
<td><img src="${basePath}image/${i.users.picpath}" alt="${i.users.picpath}"/></td>
<td>${i.content}</td>
<td>${i.publishtime}</td>
<td>${i.users.nickname}</td>
<c:choose>
<c:when test="${i.users.sex eq 0}">
<td>女</td>
</c:when>
<c:otherwise>
<td>男</td>
</c:otherwise>
</c:choose>
<td>${i.users.mobile }</td>
<c:choose>
<c:when test="${i.users.supper eq 0}">
<td>是</td>
</c:when>
<c:otherwise>
<td>否</td>
</c:otherwise>
</c:choose>
<td>
<a href="BlogServlet?flag=findbyid&id=${i.id}">修改</a>
&nbsp;|&nbsp;
<a href="BlogServlet?flag=delete&id=${i.id}">删除</a>
</td>
</tr>
</c:forEach>
</table>
第${pageno}/${totalpage}页
&nbsp;&nbsp;
<a href="BlogServlet?pageno=1&userid=${userid}">首页</a>
&nbsp;&nbsp;
<c:choose>
<c:when test="${pageno>1}">
<a href="BlogServlet?pageno=${pageno-1}&userid=${userid}">上一页</a>
</c:when>
<c:otherwise>
<a href="javascript:alert('已经是第一页!');">上一页</a>
</c:otherwise>
</c:choose> &nbsp;&nbsp;
<c:choose>
<c:when test="${pageno<totalpage}">
<a href="BlogServlet?pageno=${pageno+1}&userid=${userid}">下一页</a>
</c:when>
<c:otherwise>
<a href="javascript:alert('已经是最后一页!');">下一页</a>
</c:otherwise>
</c:choose>
&nbsp;&nbsp;
<a href="BlogServlet?pageno=${totalpage}&userid=${userid}">末页</a>
&nbsp;&nbsp;
共${totalcount }条
</fieldset>
</CENTER>
</body>
</html>

index.jsp

16.运行页面

17. 点击下一页

18.在昵称下拉列表选择

19.点击下一页

-------------------------------------------------------------------------------------------------

以上代码纯属原创 ,为了能够共同进步互相学习,如有问题或更好建议可以联系holly老师:

QQ/微信:964918306

想学习java,安卓,大数据,数据库,web开发,前端开发 可以联系Holly老师!

15.Hibernate一对多双向关联映射+分页的更多相关文章

  1. Hibernate一对多双向关联映射

    建立多对一的单向关联关系    Emp.java            private Integer empNo //员工编号            private String empName / ...

  2. Hibernate从入门到精通(九)一对多双向关联映射

    上次的博文Hibernate从入门到精通(八)一对多单向关联映射中,我们讲解了一下一对多单向映射的相关内容,这次我们讲解一下一对多双向映射的相关内容. 一对多双向关联映射 一对多双向关联映射,即在一的 ...

  3. Hibernate(九)一对多双向关联映射

    上次的博文Hibernate从入门到精通(八)一对多单向关联映射中,我们讲解了一下一对多单向映射的相关 内容,这次我们讲解一下一对多双向映射的相关内容. 一对多双向关联映射 一对多双向关联映 射,即在 ...

  4. hibernate 一对多双向关联 详解

    一.解析: 1.  一对多双向关联也就是说,在加载班级时,能够知道这个班级所有的学生. 同时,在加载学生时,也能够知道这个学生所在的班级. 2.我们知道,一对多关联映射和多对一关联映射是一样的,都是在 ...

  5. Hibernate 一对多双向关联Demo

    以Classes[班级]和Student[学生]为例的Demo //Classes.java public class Classes implements Serializable { privat ...

  6. Hibernate一对多单向关联和双向关联映射方法及其优缺点 (待续)

    一对多关联映射和多对一关联映射实现的基本原理都是一样的,既是在多的一端加入一个外键指向一的一端外键,而主要的区别就是维护端不同.它们的区别在于维护的关系不同: 一对多关联映射是指在加载一的一端数据的同 ...

  7. Hibernate从入门到精通(八)一对多单向关联映射

    上次的博文Hibernate从入门到精通(七)多对一单向关联映射我们主要讲解了一下多对一单向关联映射,这次我们继续讲解一下一对多单向映射. 一对多单向关联映射 在讲解一对多单向关联之前,按照我们的惯例 ...

  8. Hibernate(八)一对多单向关联映射

    上次的博文Hibernate从入门到精通(七)多对一单向关联映射我们主要讲解了一下多对一单向关联映射, 这次我们继续讲解一下一对多单向映射. 一对多单向关联映射 在讲解一对多单向关联之前,按 照我们的 ...

  9. Java进阶知识12 Hibernate多对多双向关联(Annotation+XML实现)

    1.Annotation 注解版 1.1.应用场景(Student-Teacher):当学生知道有哪些老师教,老师也知道自己教哪些学生时,可用双向关联 1.2.创建Teacher类和Student类 ...

随机推荐

  1. Cocoa pods的安装和使用

    现在网上关于cocoapods的安装使用资料有很多,有些方法能用,有些是用不了的,别问为什么,因为我就是从坑里走出来的.在此自己整理了一些方法: 一般需要先升级Ruby环境: 第一步:安装rvm $  ...

  2. 【Android】ListView 优化

    重用 ListView Item ListView创建时其会创建屏幕可容纳数量的 Item.ListView 滚动时,刚消失的 item 会被保存到回收池中.新出现的 item 从回收池中获取避免反复 ...

  3. 【iOS开发系列】NSObject方法介绍

    NSObject是OC中的基类,全部类都继承于此,这里面也给我们提供了非常多与"类"和"方法"相关的方法,本文将解说几个非常有用的方法. 正文: Person. ...

  4. VC问题 IntelliSense:“没有可用的附加信息”,[请參见“C++项目 IntelliSense 疑难解答”,获得进一步的帮助]

    在XP上安装VS2010 后发现 IntelliSense不能使用,但在Windows7上是能够正常使用这功能的.关于IntelliSense不能使用的问题已有网友提出了是由于KB2876217这个补 ...

  5. 【NOIP2018】为什么这么无力啊

    菜鸡又要爆零了 辛辛苦苦背板子结果考时候脑子一片空白 第一题线段树调了半小时 看完三道题两道写暴搜一道写暴力(说是暴搜,觉得更像写了个背包) 别提暴搜还忘记剪枝. . . . . . 我觉得考场上最菜 ...

  6. Android Calendar的运用

    import java.text.DateFormat; import java.text.ParsePosition; import java.text.SimpleDateFormat; impo ...

  7. Window.open()打开一个窗体不被拦截

    Window.open()打开一个窗体不被拦截     在DataGrid中建一个模板列,在模板列中放一个客户端的Button,或者直接写你要的字句,然后用<a href>连接例:< ...

  8. Codeforces--629B--Far Relative’s Problem(模拟)

    Far Relative's Problem Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I ...

  9. 【POJ 3074】 Sudoku

    [题目链接] http://poj.org/problem?id=3074 [算法] 将数独问题转化为精确覆盖问题,用Dancing Links求解 转化方法如下 : 我们知道,在一个数独中 : 1. ...

  10. hdu 4297

    有两个基础需要掌握: RMQ,以及LCA. RMQ:dp[i][j]表示下标从i开始,长度为2^j的一段元素中的最值.则易得状态转移如下:dp[i][j]=max/min(dp[i][j-1],dp[ ...