-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.java
More file actions
43 lines (30 loc) · 1.21 KB
/
UserController.java
File metadata and controls
43 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.springboot_rt.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.springboot_rt.entity.R;
import com.springboot_rt.entity.User;
import com.springboot_rt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@PostMapping("/login")
public R login(HttpServletRequest request,@RequestBody User user){
String password = user.getPassword();
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(User::getUsername,user.getUsername());
User user1 = userService.getOne(queryWrapper);
if(user1 == null) {
return R.error("用户名未找到");
}
if(!user1.getPassword().equals(password)){
return R.error("密码错误,登录失败");
}
request.getSession().setAttribute("userid",user1.getId());
return R.success(user1);
}
}