parent
2e1475fb0a
commit
ded46a1389
@ -1,42 +0,0 @@
|
|||||||
package com.softegg.freetogo.Login;
|
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description:
|
|
||||||
* @author:zhanglinhao
|
|
||||||
* @date:2024/5/9 9:35
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
//@CrossOrigin(origins = "*")
|
|
||||||
@RequestMapping("/Login")
|
|
||||||
public class LoginController {
|
|
||||||
@Autowired
|
|
||||||
LoginService loginService;
|
|
||||||
|
|
||||||
@PostMapping("login")
|
|
||||||
public String Login(@RequestBody Map<String,Object> map){
|
|
||||||
System.out.println(map);
|
|
||||||
System.out.println(map.get("username").toString());
|
|
||||||
System.out.println(map.get("password").toString());
|
|
||||||
return switch (loginService.loginAccount( map.get("username").toString(), map.get("password").toString())) {
|
|
||||||
case 1000 -> "登陆成功";
|
|
||||||
case 1001 -> "密码错误";
|
|
||||||
case 1002 -> "未注册";
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("register")
|
|
||||||
public String Register(@RequestBody Map<String,Object> map){
|
|
||||||
return switch (loginService.registerAccount(map.get("username").toString(), map.get("password").toString())) {
|
|
||||||
case 1003 -> "已注册";
|
|
||||||
case 1004 -> "注册成功";
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.softegg.freetogo.Login;
|
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description:
|
|
||||||
* @author:zhanglinhao
|
|
||||||
* @date:2024/5/9 8:37
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public interface LoginService {
|
|
||||||
int loginAccount(String phone,String password);
|
|
||||||
int registerAccount(String phone,String password);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package com.softegg.freetogo.Login;
|
|
||||||
|
|
||||||
import com.softegg.freetogo.Users;
|
|
||||||
import com.softegg.freetogo.UsersService;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description:
|
|
||||||
* @author:zhanglinhao
|
|
||||||
* @date:2024/5/9 9:33
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class LoginServiceImpl implements LoginService{
|
|
||||||
@Autowired
|
|
||||||
UsersService usersService;
|
|
||||||
/**
|
|
||||||
* @param phone
|
|
||||||
* @param password
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int loginAccount(String phone,String password){
|
|
||||||
if(usersService.isRegister(phone)){
|
|
||||||
if(usersService.getUserByPhone(phone).getPassword().equals(password))
|
|
||||||
return 1000;
|
|
||||||
else
|
|
||||||
return 1001;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 1002;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param phone
|
|
||||||
* @param password
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int registerAccount(String phone,String password) {
|
|
||||||
if (usersService.isRegister(phone))
|
|
||||||
return 1003;
|
|
||||||
else {
|
|
||||||
Users user = new Users();
|
|
||||||
user.setPhone(phone);
|
|
||||||
user.setPassword(password);
|
|
||||||
usersService.add(user);
|
|
||||||
return 1004;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
package com.softegg.freetogo;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description:UsersService接口实现类
|
|
||||||
* @author:zhanglinhao
|
|
||||||
* @date:2024/5/8 8:50
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class UserServiceImpl implements UsersService{
|
|
||||||
@Autowired
|
|
||||||
private UsersRepository usersRepository;
|
|
||||||
|
|
||||||
public List<Users> findAll(){
|
|
||||||
System.out.println("查询成功");
|
|
||||||
return usersRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Users user){
|
|
||||||
usersRepository.save(user);
|
|
||||||
System.out.println("添加成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteById(int id){
|
|
||||||
usersRepository.deleteById(id);
|
|
||||||
System.out.println("删除成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Users getUserById(int id) {
|
|
||||||
return usersRepository.findById(id).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(Users user){
|
|
||||||
usersRepository.save(user);
|
|
||||||
System.out.println("更新成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRegister(String phone){
|
|
||||||
Users users = usersRepository.findByPhone(phone);
|
|
||||||
System.out.println(users);
|
|
||||||
return users != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Users getUserByPhone(String phone){
|
|
||||||
return usersRepository.findByPhone(phone);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package com.softegg.freetogo;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description:数据库中表users的对应实体类
|
|
||||||
* @author:zhanglinhao
|
|
||||||
* @date:2024/5/7 15:36
|
|
||||||
*/
|
|
||||||
@Entity
|
|
||||||
@Table(name="users")
|
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Users {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Integer uid;
|
|
||||||
@Column
|
|
||||||
private String name;
|
|
||||||
@Column
|
|
||||||
private String email;
|
|
||||||
@Column
|
|
||||||
private String password;
|
|
||||||
@Column
|
|
||||||
private String createtime;
|
|
||||||
@Column
|
|
||||||
private String IDCard;
|
|
||||||
@Column
|
|
||||||
private int reputation;
|
|
||||||
@Column
|
|
||||||
private boolean gender;
|
|
||||||
@Column
|
|
||||||
private boolean membertype;
|
|
||||||
@Column
|
|
||||||
private String phone;
|
|
||||||
@Column
|
|
||||||
private String nickname;
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
package com.softegg.freetogo;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description:
|
|
||||||
* @author:zhanglinhao
|
|
||||||
* @date:2024/5/8 8:28
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
//@CrossOrigin(origins = "*")
|
|
||||||
@RequestMapping("/users")
|
|
||||||
public class UsersController {
|
|
||||||
@Autowired
|
|
||||||
private UsersService usersService;
|
|
||||||
|
|
||||||
@GetMapping("findAll")
|
|
||||||
public List<Users> findAll() {
|
|
||||||
return usersService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("add")
|
|
||||||
public String add(String name,
|
|
||||||
String email,
|
|
||||||
String psw,
|
|
||||||
String ct,
|
|
||||||
int rpt,
|
|
||||||
String phone,
|
|
||||||
String nkn,
|
|
||||||
String idc,
|
|
||||||
boolean gender,
|
|
||||||
boolean type) {
|
|
||||||
Users user = new Users();
|
|
||||||
setUsers(name, email, psw, ct, rpt, phone, nkn, idc, gender, type, user);
|
|
||||||
usersService.add(user);
|
|
||||||
return "添加成功";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("delbyid")
|
|
||||||
public String delById(int id) {
|
|
||||||
usersService.deleteById(id);
|
|
||||||
return "删除成功";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("findbyid")
|
|
||||||
public Users getUserById(int id) {
|
|
||||||
return usersService.getUserById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("update")
|
|
||||||
public String update(int id,
|
|
||||||
String name,
|
|
||||||
String email,
|
|
||||||
String psw,
|
|
||||||
String ct,
|
|
||||||
int rpt,
|
|
||||||
String phone,
|
|
||||||
String nkn,
|
|
||||||
String idc,
|
|
||||||
boolean gender,
|
|
||||||
boolean type){
|
|
||||||
Users user = usersService.getUserById(id);
|
|
||||||
setUsers(name, email, psw, ct, rpt, phone, nkn, idc, gender, type, user);
|
|
||||||
usersService.update(user);
|
|
||||||
return "更新成功";
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setUsers(String name, String email, String psw, String ct, int rpt, String phone, String nkn, String idc, boolean gender, boolean type, Users user) {
|
|
||||||
user.setName(name);
|
|
||||||
user.setGender(gender);
|
|
||||||
user.setPassword(psw);
|
|
||||||
user.setEmail(email);
|
|
||||||
user.setReputation(rpt);
|
|
||||||
user.setMembertype(type);
|
|
||||||
user.setCreatetime(ct);
|
|
||||||
user.setPhone(phone);
|
|
||||||
user.setNickname(nkn);
|
|
||||||
user.setIDCard(idc);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.softegg.freetogo;
|
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
/**
|
|
||||||
* @description:继承Jpa数据库接口类
|
|
||||||
* @author:zhanglinhao
|
|
||||||
* @date:2024/5/8 8:50
|
|
||||||
*/
|
|
||||||
public interface UsersRepository extends JpaRepository<Users, Integer> {
|
|
||||||
// @Query(value = "select * from users where phone = ?1",nativeQuery = true)
|
|
||||||
Users findByPhone(String phone);
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package com.softegg.freetogo;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description:Service接口类
|
|
||||||
* @author:zhanglinhaon
|
|
||||||
* @date:2024/5/7 16:06
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface UsersService {
|
|
||||||
List<Users> findAll();
|
|
||||||
void add(Users user);
|
|
||||||
void deleteById(int id);
|
|
||||||
Users getUserById(int id);
|
|
||||||
void update(Users user);
|
|
||||||
boolean isRegister(String phone);
|
|
||||||
Users getUserByPhone(String phone);
|
|
||||||
}
|
|
Loading…
Reference in new issue