dao

个人使用SpringMVC框架项目的心得

吃可爱长大的小学妹 提交于 2019-12-09 02:51:20
4月19日更新 : 已在Github中上传了精简的SpringMVC框架的MAVEN工程包。可以在进行简单配置后使用。 链接: springMVC 本文仅作SpringMVC框架使用过程中的一些个人总结。 项目结构 项目大致分为公共包(common-utils)、核心(core)、前端(web)三个工程。 大致目录: Worksapce |-common-utils |-core |-web 公共包 common-utils 全系统(包括其它模块)公用的部分: common-utils |-exception |-utils |-Generic |-GenericDao |-GenericService 异常处理 根据业务逻辑分成:系统异常 SystemException 、业务异常 BusinessException 两大类。 业务异常 通常指业务处理中可能出现的异常情况,通常是违反业务正常进行规则出现的异常,而不是系统错误。 应该给前台反馈适当的异常信息。而不是单纯的错误代码。且一般是业务逻辑判断后主动抛出的异常,而不是程序错误抛出的异常。 系统异常 一般是程序错误,或者违规操作造成程序无法继续运行的状况。为了提高用户体验,通常捕捉到程序异常 Exception 后记录日志系统, 然后将其包装成系统异常 BusinessException 抛给前台。这样反馈给用户的时异常的概述

SpringMVC Dao层注入到Service层,Service层注入到controller层及相关XML

大憨熊 提交于 2019-12-09 02:34:59
1 本人新手,刚开始学习SringMVC框架,需要各个层之间的注入。 举个例子: 最初,在dao层实现service的方式是,new出来一个(每个方法都要new一次)。 IServiceImpl service =new IServiceImpl(); service.fill();//fill是我服务中的方法 完成注入之后,每个方法使用service如下: service.fill();//service提前声明了。下面会 声明 2 Service层注入到controller层 首先在Service的实现类中添加如下代码: @Service("Service")//要添加的 public class IServiceImpl implements IService { //这是我的service实现类 然后,在controller类中添加如下代码: public class Testcontroller {//这是我的controller实现类 @Autowired//要添加的 @Qualifier("Service")//要添加的 private IServiceImpl service;//要添加的,这是上文提及的 声明 接下来你在controller的方法中就可以直接使用: service.fill();//fill是我服务中的方法 3 Dao层注入到Service层 和

实际接触springMVC后的简单理解

你。 提交于 2019-12-09 01:39:18
到现在为止已经实习半年(在一个单位实习半年,我都佩服自己),自己的java代码总算写的有点样子,不比以前在学校学习的时候,刚接触springMVC,总是听到各种术语,最多是一些小项目,所以对于mvc的思想理解还是有些懵懂,在实习期间,总算有了实际编程的经历,对于mvc总算有了一个概念,所以就想把自己体会到的几点用一种比较简单易懂的浅显语言写出来,一是加深自己的印象,二也是尝试一下写博客,毕竟这也是一种学习的方法,而且非常有效。 MVC翻译过来就是模型层、视图层、控制器,而在模型和控制器之间,其实还能细分持久层和服务层,如果对应项目结构的话就是 简单笼统的说,model中就是一些实体类(pojo,即没有什么接口继承的最简单的类),比如说学生类,班级类,数据源等;持久层就是操作数据库,增删改查,即dao;服务层包装功能,接收dao返回的信息,并给控制层提供接口,即service;控制层视图层的请求,然后分发、处理再返回数据到视图层,即controller;视图层,顾名思义,就是看到的界面,同时包括css,js,images等。这是把层次对应文件位置的说法。 具体的讲每层的功能,model中封装各种实体类,即学生类,其中学号,姓名等,给其他功能调用,这部分最简单,只要private int id,然后重写set,get方法,还有像equals,hashCode,toString等方法

DAO Design Pattern and Connection Handling

点点圈 提交于 2019-12-08 14:00:30
问题 I have EmployeeDAOImpl.java and DepartmentDAOImpl.java. Now I am calling this two from data service layer. EmployeeDAO and DepartmentDAO is interface and they have only abtract CRUD methods. In Service layer I have two method call createEmployee(Employee employee) and createDepartment(Department department) with in a method. These 2 calls should be in same transaction that means you cant close connection only after 2 calls succeeded. Now do you people have any idea how to supply a connection.

How would I obtain SessionFactory from the ServletContext in the DAO

被刻印的时光 ゝ 提交于 2019-12-08 13:55:53
问题 I have created a DAO like this: This is based from: Hibernate: CRUD Generic DAO public class Dao{ SessionFactory sessionFactory; // initialise session factory public User save(User o){ return (User) sessionFactory.getCurrentSession().save(o); } public User get(Long id){ return (User) sessionFactory.getCurrentSession().get(User.class, id); } public User void saveOrUpdate(User o){ sessionFactory.getCurrentSession().saveOrUpdate(o); } Now, this is all fine, if my sessionFactory is in the DAO or

JSON to Java conversion and mapping with DAO

痴心易碎 提交于 2019-12-08 11:54:27
问题 I have below JSON response and want convert into Java and then later saving the data to database. I looked at various tools but not able to come up with proper solution. I am doing something wrong but not able to understand where is the gap. Below is my JSON: { "release-1.0": [{ "id": 55, "resourceId": "126", "allGraphs": null, "isChecked": true }, { "id": 56, "resourceId": "125", "allGraphs": null, "isChecked": true }, { "id": 58, "resourceId": "140", "allGraphs": null, "isChecked": true }]

Spring Transactional not working

夙愿已清 提交于 2019-12-08 09:39:05
问题 I'v setup a Spring/Hibernate backend based on following example using Spring 4.1 and Hibernate 4.3.6: http://www.sivalabs.in/2011/02/springhibernate-application-with-zero.html I basically got everything working so far, but there is one little configuration problem I can't overcome: If I try to save an Entity I get the following StackTrace: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into

Uploading file from Access to SQL Server with DAO code - Object Required error

谁都会走 提交于 2019-12-08 07:46:43
问题 I have an Access 2016 database being used as the frontend for a SQL Server 2008 Express instance. The WATER_FILES table exists in the SQL Server database and includes a column Binary_File of type varbinary(MAX) . I'm attempting to write a VBA sub routine that will upload a file into that column. The following code causes an error Object Required at runtime. This code is based on this incomplete page: https://msdn.microsoft.com/en-us/vba/access-vba/articles/work-with-attachments-in-dao# What

which scope should a DAO typically have

爱⌒轻易说出口 提交于 2019-12-08 07:44:53
问题 its out of question that a dao will not hold any state. however, for easiest access to the class, is it better to use prototype( = new every time) or singleton? simple object creation is cheap for dao's.. it typically only holds a sessionfactory, accessing the object from a list of singletons may be equally expensive. clarfication: the focus of this question is, if there is a common convention to the scoping of daos. 回答1: If your question is about architecture , I'd go with scoping DAOs to

Unit testing of DAO

瘦欲@ 提交于 2019-12-08 06:44:49
问题 It is my first time to make a Unit testing so i'm trying to find references to how to make a Unit testing of a DAO. Can you guys make a simple example of the setUpBeforeClass , setUp and how to test a method that inserting new data in database using model for this . Just a simple example using easy mock. Thank you for your consideration 回答1: The idea of using mock objects to perform your unit testing strikes me as peculiar as all you are doing is testing your mock objects instead of your real