@ManyToOne (默认加载方式为直接加载内存,即fetch =FetchType.EAGER)
若是直接加载,则session关闭后仍可获取对象的属性值。当设置为懒加载时,session关闭后,就无法获取,报错。
@OneToMany (默认加载方式为lazy,即fetch =FetchType.LAZY)
(处理json时,由于hibernate的懒加载机制(双向关联时),会出现问题,2种解决方法)
1.若使用springmvc的@ResponseBody,则加载方式需设为直接加载(不能为懒加载),
同时为防止关联的两个对象(User,Exam)重复在数据库查询(会造成死循环),
需在多(成员对象的变量,exams)的一端添加@JsonIgnore(处理json转换)。
2.若使用fastjson将对象转换成json字符串时,需在exams前添加@JSONField(serialize=false),
并且在使用JSON.toJSONString(Object,SerializerFeature)设SerializerFeature.DisableCircularReferenceDetect
避免json字符串中使用"$ref"的引用。
常用设计模式:
单例模式
工厂模式
观察者模式
策略模式
动态代理模式:(用到JDK中的Proxy类和InvocationHandler接口)
UserDao ud =new UserDaoImpl();
java.lang.reflect.InvocationHandler h =new MyProxyHandler(ud);
UserDao up =(UserDao) java.lang.reflect.Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{UserDao.class}, h);
up.sayHello();
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
mvn-web.rar (63个子文件)
mvn-web
pom.xml 5KB
target
test-classes
maven-status
maven-compiler-plugin
compile
default-compile
inputFiles.lst 898B
createdFiles.lst 0B
m2e-wtp
web-resources
META-INF
maven
com.vamy
mvn-web
pom.xml 5KB
pom.properties 208B
MANIFEST.MF 114B
classes
springmvc.xml 2KB
jdbc.properties 127B
log4j.properties 2KB
com
spring
dao
UserDao.class 276B
ExamDao.class 541B
impl
UserDaoImpl.class 2KB
ExamDaoImpl.class 6KB
model
User.class 2KB
Exam.class 2KB
ExamInfo.class 2KB
test
Test.class 1KB
LogInterceptor.class 729B
MyProxyHandler.class 1KB
controller
MyInterceptor.class 2KB
StartController.class 938B
BaseController.class 7KB
service
UserService.class 773B
UserServiceImpl.class 3KB
spring-hibernate.xml 3KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.core.resources.prefs 57B
org.eclipse.wst.common.component 572B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.validation.prefs 50B
.jsdtscope 639B
org.eclipse.jdt.core.prefs 430B
src
test
resources
java
com
spring
test
MyProxyHandler.java 516B
LogInterceptor.java 322B
Test.java 848B
main
webapp
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 1KB
jsp
query_exams.jsp 2KB
error_500.jsp 434B
add_exam.jsp 815B
success.jsp 346B
lib
index.jsp 69B
resources
springmvc.xml 2KB
jdbc.properties 127B
log4j.properties 2KB
spring-hibernate.xml 3KB
java
com
spring
dao
UserDao.java 251B
ExamDao.java 459B
impl
ExamDaoImpl.java 5KB
UserDaoImpl.java 1KB
model
User.java 1KB
ExamInfo.java 1KB
Exam.java 1KB
controller
StartController.java 520B
MyInterceptor.java 1KB
BaseController.java 5KB
service
UserServiceImpl.java 2KB
UserService.java 683B
.project 1KB
readMe.txt 1KB
.classpath 1KB
共 63 条
- 1
资源评论
- juniot2018-04-03初学者正参考着学习,问一下为什么没有spring的xml配置文件的?
- 超me2018-05-21不错,可以看看
may_2014
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功