dao

DAO and dependency injection, advice?

吃可爱长大的小学妹 提交于 2019-12-01 06:06:03
This is the first time im using the DAO pattern. From what I've read so far, implementing this pattern will help me seperate my calling code (controller) from any persistence implementation - exactly what I want; that is, I don't want to be restrcited to the use of any particular database or 3rd party libraries. I'm creating some test code (in TDD fashion) using MongoDB and morphia (as an example), with morphia's provided BasicDAO class. As far as I can tell, extending BasicDAO<T, V> requires a constructor that accepts Morphia and Mongo objects; these are very specific (3rd party) types that I

Spring框架学习笔记(4)——SSM整合以及创建Maven自定义模版骨架

浪子不回头ぞ 提交于 2019-12-01 05:47:21
Spring+Spring MVC+MyBatis+Maven SSM整合的核心还是Spring+MyBatis的整合,回顾一下MyBatis操作数据库流程,我们是使用一个SQLSessionFactory对象来获得SQLSession,之后再进行CRUD操作。 现在,有了spring,我们就把SQLSessionFactory通过spring进行装载和管理。 如果是想直接使用的话,请去 SSM-Maven-Archetype 步骤 1.创建maven项目 2.添加依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.wan</groupId> <artifactId>SSM-Template</artifactId> <version>1.0

ORM and DAO - design question

醉酒当歌 提交于 2019-12-01 05:35:46
问题 I'm currently working on the project where this discussion came and I wanted to ask others what do they think about this. The DAO pattern is (according to wikipedia): "In computer software, a data access object (DAO) is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database.". But, using ORM this is clearly an ORM (eg. Hibernate) job. It exactly provides an abstract interface

mybatis入门百分百

对着背影说爱祢 提交于 2019-12-01 05:02:43
今天重新返回来看自己的mybatis,总结了一些更好入门的办法,下面用最简单的方法带领大家入门。 此处先引入类包的关系图片 1.构建一个==普通==maven项目 构建好之后向pom.xml添加一下依赖 <!--打包方式--> <packaging>jar</packaging> <dependencies> <!--引入mybatis--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.2</version> </dependency> <!--mysql--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.15</version> </dependency> <!--日志--> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <!--测试--> <dependency> <groupId>junit</groupId>

MyBatis—02—代替Dao层的mapper映射文件;MyBatis配置文件详解

谁说我不能喝 提交于 2019-12-01 04:48:59
     一. Mapper 映射文件 在JDBC中,我们会把访问数据库的代码放在Dao层,也就是建一个com.dao的package; 但在 MyBatis 中, 我们的包名推荐使用 mapper , 并且我们只需要写一个映射配置文件即可, 不需要写接口和实现类了. UserMapper.xml, 用于定义要执行的 SQL 语句, 同时设定返回结果的类型. 1.编写mapper层的xml映射文件 2. 在MyBatis核心配置文件中添加 mapper 扫描 3.测试 二. MyBatis 配置文件详解 1.MyBatis核心配置文件 (1)configuration 这是配置文件的根元素, 所有的其他元素都要在这个标签下使用. (2)environments 用于管理所有的环境, 并可以指定默认使用哪个环境. 通过default 属性来指定. (3)environment 用于配置环境, id 属性用于唯一标识当前环境 (4)transcationManager事务管理器: 用于配置事务管理器其中的type 属性用于指定 MyBatis 采用何种方式管理事务: a) JDBC: 表示 MyBatis 采用与原生 JDBC 一致的方式管理事务 b) MANAGED: 表示将事务管理交给其他容器进行, 例如 Spring1.5用于配置数据源, 设置 MyBatis 是否使用连接池技术

How to detect the last insert ID within a transaction in Yii using DAO?

纵然是瞬间 提交于 2019-12-01 03:47:50
That's the source code, I need to detect the ID (see the marked position between the two queries below). $connection = Yii::app()->db; $transaction=$connection->beginTransaction(); try { $q = "INSERT INTO `someTable1` .... "; $connection->createCommand($q)->execute(); // Single Row Inserted // HERE!! How to get the last insert ID from query above $q = "INSERT INTO `someTable2` .... WHERE id = LAST_INSERT_ID_FROM_FIRST_QUERY "; $connection->createCommand($q)->execute(); $transaction->commit(); } catch (Exception $e) { // react on exception $trans->rollback(); } What would be the most suitable

DAO and dependency injection, advice?

≡放荡痞女 提交于 2019-12-01 03:07:16
问题 This is the first time im using the DAO pattern. From what I've read so far, implementing this pattern will help me seperate my calling code (controller) from any persistence implementation - exactly what I want; that is, I don't want to be restrcited to the use of any particular database or 3rd party libraries. I'm creating some test code (in TDD fashion) using MongoDB and morphia (as an example), with morphia's provided BasicDAO class. As far as I can tell, extending BasicDAO<T, V> requires

Dao层系列-4-Hibernate Spring Annotation

浪尽此生 提交于 2019-12-01 02:43:27
之前几篇文章主要是介绍 Hibernate、Hibernate Annotation、Hibernate Spring 集成 这篇文章主要是:Hibernate和Spring集成后都使用注解的方式。 Hibernate使用注解进行关系映射,Spring使用注解进行Bean的依赖注入。 Spring的配置如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring

IDEA SpringBoot多模块项目搭建详细过程

天涯浪子 提交于 2019-11-30 23:13:01
项目源码: 链接: https://pan.baidu.com/s/1Gp9cY1Qf51tG9-5gUZsnHQ 提取码: 5izt CSDN源码下载: https://download.csdn.net/download/zcf980/10719615 1. 项目介绍: 本项目包含一个父工程 demo 和 四 个子模块(demo-base, demo-dao, demo-service, demo-web), demo-base 为其他三个模块的公共内容, 四个模块都依赖父模块, demo-dao 依赖 demo-base; demo-service 依赖 demo-dao, 间接依赖 demo-base; demo-web 依赖 demo-service, 间接依赖demo-base和demo-dao 2. 搭建思路: 先创建一个 Spring Initializr 工程 demo 作为 父工程, 然后在父工程再建四个子 Module (demo-base, demo-demo-dao, demo-service), 其实他们就是四个普通的Spring Initializr工程 3.开始搭建 首先,创建一个Spring Initializr项目 和 子Module !!!!注意: 修改demo 的 pom 文件中的打包方式为 pom 好戏开始:

MyBatis学习笔记 初步

梦想与她 提交于 2019-11-30 23:07:14
1.框架: Def:它是我们软件开发中的一套解决方案,不同的框架解决的是不同的问题。 Mybatis解决的是持久层的问题 https://blog.csdn.net/ycgslh/article/details/80050025   使用框架的好处: 框架封装了很多的细节,使开发者可以使用极简的方式实现功能。大大提高开发效率。 2.三层架构 表现层:展示数据 类似JSP 业务层:处理业务需求 类似Service层 持久层:与数据库交互 类似DAO层 JDBC技术: Connection PreparedStatement ResultSet Spring的JdbcTemplate: Spring中对jdbc的简单封装 Apache的DBUtils: 它和Spring的jdbcTemplate很像,也是对jdbc的简单封装 以上这些都不是框架 JDBC是规范 Spring的JdbcTemplate和Apache的DBUtils都只是工具类 3.mybatis的概述 mybatis是一个持久层框架,用java编写的。 它封装了jdbc操作的很多细节,使开发者只需要关注sql语句本身,而无需关注注册驱动,创建连接等繁杂过程 它使用了ORM思想实现了结果集的封装。 mybatis通过配置.xml或注解的方式将要执行的各种Statement配置起来