为什么报401错误?怎么解决

代码如下
package com.itheima.springbootquickstart;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class SpringbootQuickstartApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootQuickstartApplication.class, args);
}
}
#数据源
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis
username: root
password: 123456
mybatis:
configuration:
map-underscore-to-camel-case: true #开启驼峰命名和下划线命名的转换
package com.itheima.springbootquickstart.service;
import com.itheima.springbootquickstart.pojo.User;
public interface UserService {
public User findById(Integer id);
}
package com.itheima.springbootquickstart.service.impl;
import org.springframework.stereotype.Service;
import com.itheima.springbootquickstart.mapper.UserMapper;
import com.itheima.springbootquickstart.pojo.User;
import com.itheima.springbootquickstart.service.UserService;
import com.itheima.springbootquickstart.utils.Md5Util;
import com.itheima.springbootquickstart.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import com.itheima.springbootquickstart.pojo.User;
import com.itheima.springbootquickstart.service.UserService;
import java.time.LocalDateTime;
import java.util.Map;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User findById(Integer id){
return userMapper.findById(id);
}
}
package com.itheima.springbootquickstart.pojo;
public class User {
private Integer id;
private String name;
private Short age;
private Short gender;
private String phone;
public User() {
}
public User(Integer id, String name, Short age, Short gender, String phone) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
this.phone = phone;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Short getAge() {
return age;
}
public void setAge(Short age) {
this.age = age;
}
public Short getGender() {
return gender;
}
public void setGender(Short gender) {
this.gender = gender;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", gender=" + gender +
", phone='" + phone + '\'' +
'}';
}
}
package com.itheima.springbootquickstart.mapper;
import com.itheima.springbootquickstart.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface UserMapper {
@Select("select * from user where id= #{id}")
public User findById(Integer id);
}
package com.itheima.springbootquickstart.controller;
import com.itheima.springbootquickstart.pojo.User;
import com.itheima.springbootquickstart.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.itheima.springbootquickstart.pojo.Result;
import com.itheima.springbootquickstart.utils.JwtUtil;
import com.itheima.springbootquickstart.utils.Md5Util;
import com.itheima.springbootquickstart.utils.ThreadLocalUtil;
import jakarta.validation.constraints.Pattern;
import org.hibernate.validator.constraints.URL;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
@RestController
@Validated
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/findById")
public User findById(Integer id){
return userService.findById(id);
}
}