jpa@Query()参数设置,:冒号⽅式、?NO.问号⽅式、实体
类对象参数设置
⼀、service层事务(update/delete)
@Transactional(rollbackFor = Exception.class)
⼆、@Query()参数设置
x  和:XX不能混⽤
package st;
import org.springframework.pository.JpaRepository;
import org.springframework.pository.JpaSpecificationExecutor;
import org.springframework.pository.Modifying;
import org.springframework.pository.Query;
import org.pository.query.Param;
public interface StuDao extends JpaRepository<Stu, Long>, JpaSpecificationExecutor<Stu> {
//主键类型
@Modifying
@Query(value = "update Stu wxpay set stu.name = :name, stu.alias = :alias, " +
"stu.age = :age where stu.id = :id")
void updatePayState(@Param("name") String stuName,
@Param("alias") String stuAlias,
@Param("age") int stuAge,
@Param("id") String stuId);
@Modifying
@Query(value = "update Stu wxpay set stu.name = ?1, stu.alias = ?3, " +
"stu.age = ?2 where stu.id = ?4")
void updatePayState(String stuName,
int stuAge,
String stuAlias,
String stuId);
@Modifying
@Query(value = "update Stu s set s.name = :#{#stu.name}, s.age = :#{#stu.age}, " +
"s.alias = :#{#stu.alias} where s.id = :#{#stu.id}")
int updatePayState2(@Param("stu") Stu stu);
}
2.实体类
package st;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "tbl_stu", indexes = {@Index(name = "idx_索引名字", columnList = "建⽴索引的属性")})
public class Stu {
@TableGenerator(
name = "StuGenerator",
table = "tbl_stu",
pkColumnName = "app_seq_name",
pkColumnValue = "tbl_stu_seq",
valueColumnName = "app_seq_value",
initialValue = 1000,
allocationSize = 1
)
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "WxpayFundFlowGenerator")    private Long id;
@Column(columnDefinition = "varchar(10) COMMENT '名字'")
private String name;
//省略
private int age;springframework事务
private String alias;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。