Advertisement
Guest User

Untitled

a guest
May 31st, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. save
  2. findOne
  3. exists
  4. findAll
  5. count
  6. delete
  7. deleteAll
  8.  
  9. package ua.samuliak.messenger.entity;
  10.  
  11. import org.hibernate.annotations.GenericGenerator;
  12.  
  13. import javax.persistence.*;
  14.  
  15. @Entity
  16. @Table(name = ""user"")
  17. public class User {
  18.  
  19. @Id
  20. @GeneratedValue(generator = "increment")
  21. @GenericGenerator(name = "increment", strategy = "increment")
  22. private long id;
  23.  
  24. @Column(nullable = false, length = 20)
  25. private String login;
  26.  
  27. @Column(nullable = false, length = 20)
  28. private String password;
  29.  
  30. @Column(length = 2)
  31. private String country;
  32.  
  33. @ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
  34. @JoinColumn(name = "room_id")
  35. private Room room;
  36.  
  37. public Room getRoom() {
  38. return room;
  39. }
  40.  
  41. public void setRoom(Room room) {
  42. this.room = room;
  43. }
  44.  
  45. public User() {}
  46.  
  47. public long getId() {
  48. return id;
  49. }
  50.  
  51. public void setId(long id) {
  52. this.id = id;
  53. }
  54.  
  55. public String getLogin() {
  56. return login;
  57. }
  58.  
  59. public void setLogin(String login) {
  60. this.login = login;
  61. }
  62.  
  63. public String getPassword() {
  64. return password;
  65. }
  66.  
  67. public void setPassword(String password) {
  68. this.password = password;
  69. }
  70.  
  71. public String getCountry() {
  72. return country;
  73. }
  74.  
  75. public void setCountry(String country) {
  76. this.country = country;
  77. }
  78. }
  79.  
  80. .....
  81. @RequestMapping(value = "/user/{name}", method = RequestMethod.GET)
  82. @ResponseBody
  83. public User getUserByName(@PathVariable("name") String userLogin){
  84. return userService.getByLogin(userLogin);
  85. }
  86. .....
  87.  
  88. package ua.samuliak.messenger.repository;
  89.  
  90.  
  91. import org.springframework.data.jpa.repository.JpaRepository;
  92. import org.springframework.data.jpa.repository.Query;
  93. import ua.samuliak.messenger.entity.User;
  94.  
  95. public interface UserRepository extends JpaRepository<User, Long>{
  96. @Query("FROM User WHERE login = :name ")
  97. User findByName(String name);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement