首页 > 编程知识 正文

jpa更新数据,jpa实体类注解

时间:2023-05-06 16:38:33 阅读:106047 作者:424

在@Modifying注释中修改(UPDATE或DELETE )操作(注意:不支持新添加) springdatajpa —— JPA repository添加删除更改(请参见):http://blog.csdn.csdn

示例package com.newc APEC.Dao.repository.pay; import com.newc APEC.Dao.domain.user enroll; importorg.spring framework.data.JPA.repository.JPA repository; importorg.spring framework.data.JPA.repository.jpaspecificationexecutor; importorg.spring framework.data.JPA.repository.modifying; importorg.spring framework.data.JPA.repository.query; importorg.spring framework.data.repository.query.param; importorg.spring framework.stereotype.repository; importorg.spring framework.transaction.annotation.transactional; import java.util.Date; import java.util.List; /** * @Title:用户注册计费信息--Dao * @ class name : com.newc APEC.Dao.repository.pay repository.jav a * @ descriptor y @ copyright 2016-2017-powered by研发中心* @ author : zrdqd * @ date 33602017-12-1612336035 * @ versionv1. @ repositorypublicinterfacepayrepositoryextendsjparepositoryuserenroll,Long, jpaspecificationexecutoruserenroll {/* * @为了成功支付* @ method name : updateuserenrollpaysuccess * @ parampaytime * @ parartime @ return int * @ deee ternt * @ author : zrdqd * @ date :2017-12-188:41 */http://www.Sina.com/3http://ww.Sina orderno=: ordernowherelocalorderno=: local orderno ' ) intupdateuserenrollpaysuccess (@ param (pay time ) ) date pate }测试: package com.newcapec.dao; import com.newc APEC.Dao.domain.user enroll; import com.newc APEC.Dao.repository.pay.pay repository; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; importorg.spring framework.beans.factory.annotation.auto wired; importorg.spring framework.boot.test.context.springboottest; importorg.spring framework.test.context.JUnit4. spring runner; import java.util.Date; import java.util.List; /** * @Title:用户注册计费信息--DAO测试* @ class name : com.newc APEC.Dao.payrepositorytest.jav a* @ description 3360 @Copyright 2016-2017 - Powered By研发中心* @ author : zrd qd * @ date 33602017-12-161:29 * @ versionv 1.0 */@ run witw /** * @Title:更新用户注册计费信息,成功支付* @ method name : testupdateuserenrollpaysuccess * @ param * @ return void * @ dele @ date :2017-12-188336021 */@ testpublicvoidtestupdateuserenrollpaysuccess ({ inti=pay repository.update user enery ) System.out.println (更新条数: ' I ); assert.assert equals (2017121613345689,userEnroll.getOrderno ); }注意:

)1)可以通过自定义JPQL进行UPDATE和DELETE操作。 注意: JPQL不支持使用INSERT; )2)在@Query注释中记述JPQL语句,但必须用@Modifying进行修饰。 这是为了通知SpringData这是UPDATE或DELETE操作)3)在UPDATE或DELETE操作中需要使用事务,在这种情况下需要定义Service层,JPA在Service中实现的Dao in 但是,那是环境,事务一般会添加到服务层;

)4)缺省情况下,SpringData中的每个方法都有一个事务,但它是只读事务。 他们无法完成修改操作。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。