Jpa的@Id和@GeneratedValue的使用

Jpa的@Id和@GeneratedValue的使用

import lombok.Data;
import javax.persistence.*;
import java.math.BigInteger;

@Entity//将实体类首字母小写
@Table(name = "user")//要连接的数据库表名
@Data
public class UserCopy {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    //    @GeneratedValue 用于标注主键的生成策略,通过strategy 属性指定。默认情况下,JPA 自动选择一个最适合底层数据库的主键生成策略:SqlServer对应identity
//    IDENTITY:采用数据库ID自增长的方式来自增主键字段,Oracle 不支持这种方式;
    private Integer id;

    private String userId;
    private String password;
    private String userName;
    private String userType;
    private BigInteger createTime;
    private BigInteger updateTime;
   
}

SpringDataJPA之Repository接口


import com.hebutgo.refund.sampleUser.dto.UserListDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

public interface UserCopyRepository extends JpaRepository<UserCopy,Integer> {//<表名,id(主键)属性类型是Integer>

    @Transactional
    void deleteByUserId(String userId);

    UserCopy findByUserId(String userId);

    UserCopy findByUserIdAndPassword(String userId, String password);

    UserCopy findByUserName(String userName);


//    @Transactional
//    @Modifying
//    @Query(value = "update users set user_name=:userName where user_id=:userId ", nativeQuery = true)
//    void updateNameByUserIdNative(String userId, String userName);
//
//    List<User> findByUserIdIn(List<String> userIds);
//
//    User findByToken(String token);
//
//    @Query(value = "select new com.hebutgo.refund.sampleUser.dto.UserListDTO(t1.id, t1.userId, t1.userName, t1.userType, t1.gender, t1.mobile, t1.community, t1.doorNum, t1.birthday,t1.serviceHours,t1.token) from User t1 where t1.userId = :userId and t1.password = :password")
//    List<UserListDTO> login(@Param(value = "userId")String userId, @Param(value = "password") String password);

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值