dao

Dao层和Service层设计

心不动则不痛 提交于 2020-01-19 09:17:44
1、Dao接口层 public interface IBaseDao<T, ID extends Serializable>{    public abstract Serializable save(T t); /*其他接口*/ } 2、StudentDao接口层 public interface IStudentDao extends IBaseDao<Student,Serializable> {   /*只有特殊的接口才在这里声明*/ } 3、BaseDao实现层 为了让BaseDaoImpl实现大部分的数据操作逻辑,必须要从泛型T获取实际的领域对象的类型,关键是理解getGenericSuperclass。 getGenericSuperclass() : 通过反射获取当前类表示的实体(类,接口,基本类型或void)的直接父类的Type,这里如果打印genType,结果为 com.huawei.happycar.dao.impl.BaseDaoImpl<com.huawei.happycar.domain.Student, java.io.Serializable> getActualTypeArguments(): 返回参数数组,参数中的第一个就是我们需要的领域对象类,打印entryClass,结果为 class com.huawei.happycar.domain

jdbcTemplate的Dao层封装

时光怂恿深爱的人放手 提交于 2020-01-19 09:16:47
1 package com.easyrail.base.dao; 2 3 import java.io.Serializable; 4 import java.lang.reflect.Field; 5 import java.lang.reflect.ParameterizedType; 6 import java.sql.Types; 7 import java.util.LinkedHashMap; 8 import java.util.List; 9 import java.util.Map; 10 11 import org.springframework.jdbc.core.BeanPropertyRowMapper; 12 import org.springframework.jdbc.core.JdbcTemplate; 13 import org.springframework.jdbc.core.RowMapper; 14 15 public abstract class BaseDaoImpl<T>{ 16 /** 设置一些操作的常量 */ 17 public static final String SQL_INSERT = "insert"; 18 public static final String SQL_UPDATE = "update"; 19

20200103——继续复习mybatis

╄→尐↘猪︶ㄣ 提交于 2020-01-19 03:55:22
mybatis与hibernate区别 hibernate是一个标准的orm框架(对象关系映射)不需要写sql语言。 但是如果需要对sql语句进行优化,比较困难 应用场景:适用于需求变化不多的小中型项目,比如后台管理系统 mybatis:专注于sql本身,需要程序员自己编写sql语句,优化比较方便 应用场景:需求变化较多的,互联网项目 mybatis开发dao方法 sqlsession使用范围 通过fatory创建sqlsession 工厂通过builder进行创建 使用单例模式管理sqlsessionFactory(工行内模式 将来使用spring与mybatis整合之后,使用单例模式管理sqlsessionFactory sqlsession是一个面向用户的接口你 用于操作数据库的方法 selectOne selecttList sqlsession是不安全的 还有数据域属性 原始开发dao方法 程序员需要写dao接口和实现类 需要向dao实现类中注入sqlsessionfatory,在方法体内通过sqlsessionfatory创建sqlsession dao接口 public interface UserDao { //根据id查询用户信息 public User findUserById(int id) throws Exception; //添加用户信息 public

使用springboot写项目,报Invalid bound statement (not found)错误的解决方案

微笑、不失礼 提交于 2020-01-17 04:14:48
@ TOC 一般来说报这种错误,都会通过下面几种方法查找。 检查Mapper.xml的命名空间是否正确。这个主要检查的是namespace中的名字和其dao层的接口类是否对应。 检查dao层的方法名和Mapper.xml中的方法名是否一致。 检查Mapper.xml中的parameterType和resultMap/resultType是否正确。 查看mybatis的xml路径配置是否正确 mapper-locations:冒号后面要加空格 classpath:冒号后面不用加空格 来源: CSDN 作者: 从此再无江湖啊 链接: https://blog.csdn.net/weixin_44115555/article/details/104009974

How can I fix ORA: 01013 (user requested cancel…) when trying to link Oracle tables in MS Access?

 ̄綄美尐妖づ 提交于 2020-01-16 18:11:42
问题 I have installed Oracle Express (XE, version 18) on a Windows 10 (64-bit) machine with Office 365 (32-bit) installed. I have installed the correct Oracle Instant Client (18_3) and its ODBC package (32-bit versions). I successfully created a DSN using the ODBC Data Source Administrator (32-bit) tool in windows. When I attempt to link tables into an Access database, I get error ORA: 01013. If I remove the timeout from the DSN configuration, it simply spins with the Oracle RDBMS kernel eating up

Java中Entity、DAO层、Service层和Controller层的区别

≡放荡痞女 提交于 2020-01-16 05:06:19
Entity:存放一些普通javabean,其中有一些属性及其getter和setter方法的类,没有业务逻辑,也不允许有业务方法,也不能携带有connection之类的方法。 DAO层: DAO层叫数据访问层,全称为data access object,属于一种比较底层,比较基础的操作,具体到对于某个表的增删改查,也就是说某个DAO一定是和数据库的某一张表一一对应的,其中封装了增删改查基本操作,建议DAO只做原子操作,增删改查。 Service层: Service层叫服务层,被称为服务,粗略的理解就是对一个或多个DAO进行的再次封装,封装成一个服务,所以这里也就不会是一个原子操作了,需要事物控制。 Controler层: Controler负责请求转发,接受页面过来的参数,传给Service处理,接到返回值,再传给页面。 总结: 个人理解DAO面向表,Service面向业务。后端开发时先数据库设计出所有表,然后对每一张表设计出DAO层,然后根据具体的业务逻辑进一步封装DAO层成一个Service层,对外提供成一个服务。 来源: CSDN 作者: 童话ing 链接: https://blog.csdn.net/dl962454/article/details/103989156

How to create a decimal field in MsAccess using DAO?

五迷三道 提交于 2020-01-15 10:08:28
问题 I need to create a decimal field in MsAccess 2003 through DAO. How do I do that? Other fields I can create using following codesnippet, but not decimal. How do I set type, precision and scale? NOTE : a decimals datatype = 20, but setting a datatype to 20 results in invalid data type Dim db As DAO.Database Dim tbl As TableDef Dim fld As Field Set db = CurrentDb tbl = database.CreateTableDef("Test") fld = tbl.CreateField( .... ) 回答1: You may find this useful: http://allenbrowne.com/ser-49.html#

How to create a decimal field in MsAccess using DAO?

一笑奈何 提交于 2020-01-15 09:58:07
问题 I need to create a decimal field in MsAccess 2003 through DAO. How do I do that? Other fields I can create using following codesnippet, but not decimal. How do I set type, precision and scale? NOTE : a decimals datatype = 20, but setting a datatype to 20 results in invalid data type Dim db As DAO.Database Dim tbl As TableDef Dim fld As Field Set db = CurrentDb tbl = database.CreateTableDef("Test") fld = tbl.CreateField( .... ) 回答1: You may find this useful: http://allenbrowne.com/ser-49.html#

Android Room Generic DAO

强颜欢笑 提交于 2020-01-15 08:10:53
问题 Good day Stack, i'm working on an Android project that uses Android's Room 1.0.0 Alpha 5, the main issue that i'm facing is that every time i need to call one of the DAO from room i need to do something like this: Activity.java: ... AppDatabase db = Room.databaseBuilder(context, AppDatabase.class, "Storage").build(); Table1 table = new Table1(); table.setId(1); table.setName("Hello"); new AccessDB().execute(1); /* Generic AccessDB needed */ private class AccessDB extends AsyncTask<Integer

Android Room Generic DAO

安稳与你 提交于 2020-01-15 08:09:15
问题 Good day Stack, i'm working on an Android project that uses Android's Room 1.0.0 Alpha 5, the main issue that i'm facing is that every time i need to call one of the DAO from room i need to do something like this: Activity.java: ... AppDatabase db = Room.databaseBuilder(context, AppDatabase.class, "Storage").build(); Table1 table = new Table1(); table.setId(1); table.setName("Hello"); new AccessDB().execute(1); /* Generic AccessDB needed */ private class AccessDB extends AsyncTask<Integer