mirror of
https://gitee.com/many2many/java-web.git
synced 2025-01-11 14:40:55 +08:00
add register impl code
This commit is contained in:
parent
3b2df2be35
commit
8e4db3d25b
@ -0,0 +1,30 @@
|
||||
package com.lk.paopao.controller;
|
||||
|
||||
|
||||
import com.lk.paopao.entity.User;
|
||||
import com.lk.paopao.service.AuthService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v1/auth")
|
||||
public class AuthController {
|
||||
|
||||
@Autowired
|
||||
private AuthService authService;
|
||||
|
||||
@PostMapping("/register")
|
||||
public Map<String, Object> register(@RequestBody User req) {
|
||||
User user = authService.register(req);
|
||||
|
||||
Map<String,Object> data = Map.of("username",user.getUsername(),"id",user.getId());
|
||||
|
||||
return Map.of("code","0", "msg","success","data", data);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
private String username;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String password;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.lk.paopao.service;
|
||||
|
||||
import com.lk.paopao.entity.User;
|
||||
import com.lk.paopao.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AuthService {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
// 注册
|
||||
public User register(User user){
|
||||
return userRepository.save(user);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user