You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
softegg/src/后端/java/User/controller/UsersController.java

120 lines
4.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.softegg.freetogo.User.controller;
import com.softegg.freetogo.User.bean.Users;
import com.softegg.freetogo.User.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.service.annotation.GetExchange;
import java.util.List;
/**
* @description:Users控制类用于前后端交互
* @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,
int status) {
Users user = new Users();
setUsers(name, email, psw, ct, rpt, phone, nkn, idc, gender, type, user, status);
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(
String name,
String email,
String psw,
String ct,
int rpt,
String phone,
String nkn,
String idc,
boolean gender,
boolean type,
int status) {//@RequestBody Map<String,Object> map){//HttpServletRequest user) {
// int id = Integer.parseInt(user.getParameter("uid"));
// String name=user.getParameter("name");
// String email=user.getParameter("email");
// String psw=user.getParameter("password");
// String ct=user.getParameter("createtime");
// int rpt=Integer.parseInt(user.getParameter("reputation"));
// String phone=user.getParameter("phone");
// String nkn=user.getParameter("nickname");
// String idc=user.getParameter("IDCard");
// boolean gender=false;
// boolean type=false;
// int status=Integer.parseInt(user.getParameter("status"));
// String phone = map.get("phone").toString();
// String name = map.get("name").toString();
// String email = map.get("email").toString();
// String psw=map.get("password").toString();
// String ct=map.get("createtime").toString();
// int rpt=Integer.parseInt(map.get("reputation").toString());
// String nkn=map.get("nickname").toString();
// String idc=map.get("IDCard").toString();
// boolean gender = true;
// boolean type = false;
// int status = Integer.parseInt(map.get("status").toString());
Users User = usersService.getUserByPhone(phone);
System.out.println(User);
setUsers(name, email, psw, ct, rpt, phone, nkn, idc, gender, type, User, status);
usersService.update(User);
return "更新成功";
}
@GetMapping("getByPhone")
public Users getByPhone(String phone){
return usersService.getUserByPhone(phone);
}
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, int status) {
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);
user.setStatus(status);
}
}