dao

如何在应用程序中调用service

99封情书 提交于 2019-12-03 14:31:53
在web程序中,由于有struts2提供的插件,我们能够在action中通过get,set方法获取到service的实例,但是在应用程序中,没有struts的插件,而我们又需要用到事务的时候,如何获取到service的实例,为了避免遗忘,特写下此篇博客。 1.配置文件中配置了相应的dao,service <!-- dao --> <bean id="holdInfodao" class="com.sseinfo.marginvote.bg.holdinfo.deletehold.dao.HoldInfoDAOImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- service --> <bean id="holdInfoService" class="com.sseinfo.marginvote.bg.holdinfo.deletehold.service.HoldInfoServiceImpl"> <property name="holdInfodao" ref="holdInfodao"/> </bean> 2.工具类用来从配置文件中获取到service package com.sseinfo.marginvote.bg.holdinfo.util; import org

Spring与MyBatis整合

ε祈祈猫儿з 提交于 2019-12-03 14:23:30
Spring 与 MyBatis 整合 一、概述 将 MyBatis 与 Spring 进行整合,主要解决的问题就是将 SqlSessionFactory 对象交由 Spring 容器来管理,所以,该整合,只需要将 SqlSessionFactory 的对象生成器 SqlSessionFactoryBean 注册在 Spring 容器中,再将其注入给 Dao 的实现类即可完成整合。 二、 Mapper 动态代理实现整合 ( 1 )导入相关 jar 包、定义映射文件 mapper 在 Dao 接口的包中创建 MyBatis 的映射文件 mapper ,命名与接口名相同,本例为 IStudentDao.xml 。 mapper 中的 namespace 取值也为 Dao 接口的全限定性名。    ( 2 )定义 MyBatis 主配置文件 在 src 下定义 Mybatis 的主配置文件,命名为 mybatis.xml 。 注意两点: 1 ,主配置文件中不再需要数据源的配置了。因为数据源要交给 Spring 容器来管理了。 2 ,这里对 mapper 映射文件的注册,使用 package 标签,即只需给出 mapper 映射文件所在的包即可。因为 mapper 的名称与 Dao 接口名相同,可以使用这种简单注册方式。这种方式的好处是,若有多个映射文件,这里的配置也是不用改变的。当然

DAO pattern in java what is a Business Object

橙三吉。 提交于 2019-12-03 14:17:56
Directly from this oracle article about the J2EE DAO Pattern: Everything is very clear indeed but the Business Object "participant" (as they call it). Here I quote the bit I would like more insights about (especially would be useful a real life example (an easy one)). BusinessObject The BusinessObject represents the data client. It is the object that requires access to the data source to obtain and store data. A BusinessObject may be implemented as a session bean, entity bean, or some other Java object, in addition to a servlet or helper bean that accesses the data source. I am trying to use

Java EE DAO / DTO (Data Transfer Object) Design Patterns

不问归期 提交于 2019-12-03 13:36:51
问题 Currently I am using struts2 Framework for my work's project, and while designing my DAO classes I have a question in my mind to improve on the design patterns. On my search function, I have 3 kinds of search search with one parameter, and the other, search with multiple parameters, search without parameters. My question is, what is the best way to do the DAO method? in my struts2 method, I'm having public String execute() { //assuming these are passed in from JSP if ("searchByAnId".equals

Java DAO 模式

假装没事ソ 提交于 2019-12-03 13:36:32
https://www.runoob.com/note/27029 DAO 模式 DAO (DataAccessobjects 数据存取对象)是指位于业务逻辑和持久化数据之间实现对持久化数据的访问。通俗来讲,就是将数据库操作都封装起来。 对外提供相应的接口 在面向对象设计过程中,有一些"套路”用于解决特定问题称为模式。 DAO 模式提供了访问关系型数据库系统所需操作的接口,将数据访问和业务逻辑分离对上层提供面向对象的数据访问接口。 从以上 DAO 模式使用可以看出,DAO 模式的优势就在于它实现了两次隔离。 1、隔离了数据访问代码和业务逻辑代码。业务逻辑代码直接调用DAO方法即可,完全感觉不到数据库表的存在。分工明确,数据访问层代码变化不影响业务逻辑代码,这符合单一职能原则,降低了藕合性,提高了可复用性。 2、隔离了不同数据库实现。采用面向接口编程,如果底层数据库变化,如由 MySQL 变成 Oracle 只要增加 DAO 接口的新实现类即可,原有 MySQ 实现不用修改。这符合 "开-闭" 原则。该原则降低了代码的藕合性,提高了代码扩展性和系统的可移植性。 一个典型的DAO 模式主要由以下几部分组成。 1、DAO接口: 把对数据库的所有操作定义成抽象方法,可以提供多种实现。 2、DAO 实现类: 针对不同数据库给出DAO接口定义方法的具体实现。 3、实体类:用于存放与传输对象数据

在普通类中调用Service,Dao的方法

烂漫一生 提交于 2019-12-03 12:27:06
本方法摘取自开源项目: ThinkGem 王震 / JeeSite https://git.oschina.net/thinkgem/jeesite 首先引入jar包 创建SpringContextHolder类 /** * Copyright © 2012-2013 All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); */ package com.code.platform.common.utils; import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; /** * 以静态变量保存Spring ApplicationContext,

MVC-Mode2

醉酒当歌 提交于 2019-12-03 11:14:16
开发步骤   Pojo:Plain Object java Object; 原型对象 ; 实体类 (Entity),Domain;      一个 pojo 对应一张表 ;     Pojo 的类名和表名一样      Pojo 的属性和表的字段一样      Pojo 的对象相当于表里面的一条记录 ;    Dao:DataAccess Object: 数据访问层 ;      一个 dao 对应一张表 ;      Dao 里面存储的是表的 crud 操作 ;      绝对不允许 a 表的 dao 操作 b 表 ;    Service: 一个 Service 对应多张表 ( 模块的意思 )    单元测试类 :main 方法测试      一个 Service 对应一个 main 方法    Servlet: 一个 Servlet 持有多个 Service;( 交叉 )    Jsp: 一个 Servlet 有多个 jsp; 重要:   读别人代码的时候,是从上往下读   自己开发:从下往上开发 来源: https://www.cnblogs.com/zxz666666/p/11793094.html

DAO pattern - where do transactions fit in?

隐身守侯 提交于 2019-12-03 10:50:29
问题 So I've got this generic DAO thing going on and at face value it appears to be ok. It's basically modeled after the CaveatEmptor sample application from the Hibernate guys. On top of that I have a business layer...the guts of the application. It's completely unaware of any specific DAO implementation. Everything up to this point seems fine, until I start thinking about transactions. If transactions are left to the client to implement, then how in the world do I maintain the nice separation I

JOOQ initializing DAO Best Approach

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to know Best practices for initilizing JOOQ generated DAO. Now,I am using following approach for initilization of JOOQ generated DAO. In following case StudentDao is JOOQ generated. public class ExtendedStudentDAO extends StudentDao { public ExtendedStudentDAO () { super(); } public ExtendedStudentDAO (Connection connection) { Configuration configuration = DSL.using(connection, JDBCUtils.dialect(connection)).configuration(); this.setConfiguration(configuration); } //adding extra methods to DAO using DSL public String getStudentName

One DAO per thread or threadsafe DAO?

本小妞迷上赌 提交于 2019-12-03 08:58:52
I'm wondering if there's an approved practice in a multi-threaded app. Should I have one DAO per thread or simply make one DAO a thread safe singleton. This really depends a lot on the mechanism you're using for data access. If you have a very scalable data access, and lots of threads, using some form of thread static data access can be advantageous. If you don't have scalable data access, your provider doesn't support multiple threads per process, or you just don't need the scalability at that point, using a singleton with appropriate synchronization is simpler and easier to implement. For