dao

flask-restplus

馋奶兔 提交于 2020-01-04 12:08:43
flask-restplus 定义 Flask-RESTPlus is an extension for Flask that adds support for quickly building REST APIs 安装 pip install flask-restplus 插件2015年就有。 例子: from flask import Flask from flask_restplus import Api, Resource, fields app = Flask(__name__) api = Api(app, version='1.0', title='TodoMVC API', description='A simple TodoMVC API', ) ns = api.namespace('todos', description='TODO operations') todo = api.model('Todo', { 'id': fields.Integer(readOnly=True, description='The task unique identifier'), 'task': fields.String(required=True, description='The task details') }) class TodoDAO(object): def

Spring WS interceptors with injected DAO's @Transactional not working

元气小坏坏 提交于 2020-01-04 05:58:18
问题 We have a legacy XML based configuration spring-ws application that contains endpointInterceptors that have DAOs injected to obtain configuration from the database. These DAOs have the hibernate sessionFactory injected. When we have upgraded to spring 4.2.0.RELEASE (from spring 3.2.5.RELEASE) and spring-ws 2.2.1.RELEASE (from spring-ws 2.1.4.RELEASE) I noticed that the DAO was not a proxy object and it seemed that the intercetor was going to the AnnotationActionEndpointMapping class instead

How to update entity using hibernate

我们两清 提交于 2020-01-03 15:31:25
问题 I have entity user: @Entity @Table(name = "entity_user") @AttributeOverride(name = "id", column = @Column(name = "user_id")) public class User extends BaseObject implements Serializable { /** * Login, unique */ private String email; private String username; /** * Secret for signing-in */ private String password; /** * Type of user */ private UserType userType; @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL}) @JoinTable(name = "view_user_to_requestSet", joinColumns = {

Aop第一节

跟風遠走 提交于 2020-01-03 01:09:06
什么是AOP AOP(Aspect-OrientedProgramming,面向方面编程),可以说是OOP(Object-Oriented Programing,面向对象编程)的补充和完善。OOP引入封装、继承和多态性等概念来建立一种对象层次结构,用以模拟公共行为的一个集合。当我们需要为分散的对象引入公共行为的时候,OOP则显得无能为力。也就是说,OOP允许你定义从上到下的关系,但并不适合定义从左到右的关系。例如日志功能。日志代码往往水平地散布在所有对象层次中,而与它所散布到的对象的核心功能毫无关系。对于其他类型的代码,如安全性、异常处理和透明的持续性也是如此。这种散布在各处的无关的代码被称为横切(cross-cutting)代码,在OOP设计中,它导致了大量代码的重复,而不利于各个模块的重用。 而AOP技术则恰恰相反,它利用一种称为“横切”的技术,剖解开封装的对象内部,并将那些影响了多个类的公共行为封装到一个可重用模块,并将其名为“Aspect”,即方面。所谓“方面”,简单地说,就是将那些与业务无关,却为业务模块所共同调用的逻辑或责任封装起来,便于减少系统的重复代码,降低模块间的耦合度,并有利于未来的可操作性和可维护性。AOP代表的是一个横向的关系,如果说“对象”是一个空心的圆柱体,其中封装的是对象的属性和行为;那么面向方面编程的方法,就仿佛一把利刃,将这些空心圆柱体剖开

SpringMVC常用注解@Controller,@Service,@repository,@Component

别等时光非礼了梦想. 提交于 2020-01-02 16:40:25
spring注解的作用: spring作用在类上的注解有:@Component、@Responsity、@Service以及@Controller; 而@Autowired和@Resource是用来修饰字段、构造函数或者设置方法,并做注入的。 当注解作用在类上时,表明这些类是交给spring容器进行管理的,而当使用@Autowired和@Resource时,表明我需要某个属性、方法或字段,但是并不需要我自己去new一个,只需要使用注解, spring容器会自动的将我需要的属性、方法或对象创造出来。这就是通 所说的依赖注入和控制反转。 controller层使用@controller注解 @Controller 用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller 对象。分发处理器将会扫描使用了该注解的类的方法。通俗来说,被Controller标记的类就是一个控制器,这个类中的方法,就是相应的动作。 @RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。 比如图一中,跳转到登录页面的路径就是localhost:8080/xxx/ payInfo /xxx service采用@service注解 例:@Service注解:默认名称是类名(头字母小写),可以

CurrentDb.RecordsAffected returns 0. Why?

孤街醉人 提交于 2020-01-02 01:30:11
问题 If I use RecordsAffected with CurrentDb.Execute, it always returns 0. If I first make a instance of a Database object it works properly. Why? Like this: Dim Db As Database Set Db = CurrentDb Db.Execute "DELETE * FROM [Samples] WHERE Sample=5" If Db.RecordsAffected = 0 Then MsgBox "Error" End If Instead of: CurrentDb.Execute "DELETE * FROM [Samples] WHERE Sample=5" If CurrentDb.RecordsAffected = 0 Then MsgBox "Error" End If I'm using Access 2007 and the Microsoft Office 12.0 Access database

Hibernate 5.2 version -> A lot of Query methods deprecate?

纵饮孤独 提交于 2020-01-02 00:53:05
问题 I'm new to Hibernate. I'm trying to get a list of first name and last name of all administrators. There are two warnings in my following code. I already tried to search a lot online. 1) Query is a raw type. References to generic type Query should be parameterized. 2) The method list() from the type Query is deprecated. public List<Object> loadAllAdmins() { List<Object> allAdmins = new ArrayList<Object>(); try { HibernateUtil.beginTransaction(); Query q = currentSession.createQuery("SELECT

Mybatis Dao开发方法(二)

我的未来我决定 提交于 2020-01-01 12:35:30
使用Mapper代理的方式进行开发 Mapper开发的原理   使用Mybatis的Mapper代理方式进行开发,使用该方式,只需要编写Mapper接口,不再需要编写实现类,由Mybatis框架通过接口定义来自动生成接口的动态代理对象。 Mapper代理开发要遵循的原则   1. Mapper.xml文件中的namespace要和Mapper接口的类路径相同。   2. Mapper接口中的方法名称要和Mapper.xml中定义的每个statement的id相同。   3. Mapper接口的输入参数类型要和Mapper.xml文件中定义的相对应sql的parameterType的类型相同。   4. Mapper接口的输出参数类型要和Mapper.xml文件中定义的相对应的sql的resultType的类型相同。 Mapper代理开发过程  1. 创建UserMapper.xml文件 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:Mapper接口类的路径--> <mapper namespace="com

myBatis自动生成mapping,dao和model

一世执手 提交于 2020-01-01 12:20:47
myBatis没有自动封装实体类。所以都需要自己编写,但是表数据过多时。编写难度就会增加,错误率也会增加! 所以myBatis提供mybatis-generator-core-1.3.2-bundle能够自动封装实体并生成相应的mapping。 首先在百度上下载mybatis-generator-core-1.3.2-bundle。 进入lib目录下 然后打开generatorConfig.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <!-- 配置mysql 驱动jar包路径.用了绝对路径 --> <classPathEntry location="mysql-connector-java-5.1.17-bin.jar" /> <context id="yihaomen_mysql_tables" targetRuntime="MyBatis3"> <!--

Using JSF, JPA and DAO. Without Spring?

旧城冷巷雨未停 提交于 2020-01-01 10:15:49
问题 till now i still worked with JSF and JPA without DAOs. Now i'd like to use DAOs. But how can i initialize the EntityManager in the DAO-Classes? public class AdresseHome { @PersistenceContext private EntityManager entityManager; public void persist(Adresse transientInstance) { log.debug("persisting Adresse instance"); try { entityManager.persist(transientInstance); log.debug("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } } } Have I to use