xyc
2026-08-14 1f4a6cc6045f47861c3e8d49a782afc3e11e3843
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
package com.trafficaudit.security.controller;
 
import com.trafficaudit.common.Result;
import com.trafficaudit.security.utils.JwtUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
 
@RestController
@RequestMapping("/api/auth")
public class LoginController {
 
    @Resource
    private JwtUtils jwtUtils;
 
    @PostMapping("/login")
    public Result<Map<String, Object>> login(@RequestBody Map<String, String> params) {
        String username = params.get("username");
        String password = params.get("password");
 
        if ("admin".equals(username) && "admin123".equals(password)) {
            String token = jwtUtils.generateToken(username);
            Map<String, Object> data = new HashMap<>();
            data.put("token", token);
            data.put("username", username);
            return Result.ok(data);
        }
        return Result.error(401, "用户名或密码错误");
    }
}