Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- save
- findOne
- exists
- findAll
- count
- delete
- deleteAll
- package ua.samuliak.messenger.entity;
- import org.hibernate.annotations.GenericGenerator;
- import javax.persistence.*;
- @Entity
- @Table(name = ""user"")
- public class User {
- @Id
- @GeneratedValue(generator = "increment")
- @GenericGenerator(name = "increment", strategy = "increment")
- private long id;
- @Column(nullable = false, length = 20)
- private String login;
- @Column(nullable = false, length = 20)
- private String password;
- @Column(length = 2)
- private String country;
- @ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
- @JoinColumn(name = "room_id")
- private Room room;
- public Room getRoom() {
- return room;
- }
- public void setRoom(Room room) {
- this.room = room;
- }
- public User() {}
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- public String getLogin() {
- return login;
- }
- public void setLogin(String login) {
- this.login = login;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- }
- .....
- @RequestMapping(value = "/user/{name}", method = RequestMethod.GET)
- @ResponseBody
- public User getUserByName(@PathVariable("name") String userLogin){
- return userService.getByLogin(userLogin);
- }
- .....
- package ua.samuliak.messenger.repository;
- import org.springframework.data.jpa.repository.JpaRepository;
- import org.springframework.data.jpa.repository.Query;
- import ua.samuliak.messenger.entity.User;
- public interface UserRepository extends JpaRepository<User, Long>{
- @Query("FROM User WHERE login = :name ")
- User findByName(String name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement