在春季发生异常后,所有表中的所有记录都已删除

时间:2018-11-22 23:49:42

标签: spring

我是Spring框架的新成员。 我有问题,有人可以帮助我吗?

我不明白为什么在所有例外之后,所有表中的所有记录都被删除。

实施JPA存储库。没有任何代码删除。

@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
    User findByEmail(String email);
    User findByUsername(String username);
}

定义的用户实体。此类实现UserDetails。

@Entity
@Table(name = "user")
@Access(AccessType.FIELD)
public class User implements UserDetails, Serializable {
    private static final long serialVersionUID = 3921735010416402747L;

    @Basic
    @Column(name = "username", nullable = false, length = 60)
    private String username;

    @Basic
    @Column(name = "password", nullable = false, length = 60)
    private String password;

    @ManyToMany()
    @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
    @JsonIgnore
    private Set<Role> roles;

    }

LoginController执行登录。

RestController
@RequestMapping("/login/")
public class LoginController extends BaseController {

    private static final String jwtTokenCoookieName = "JWT-TOKEN";
    private static final String signingkey = "tokenkekeke";
    private static final Map<String, String> credentials = new HashMap<>();

    @Autowired
    private LoginService loginService;

    @RequestMapping(value = "login")
    @PostMapping()
    ResponseEntity<String> login(@RequestBody LoginData loginData, HttpServletRequest request, HttpServletResponse response) {
        System.out.print("start login...");
        loginService.login(loginData);

        CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
        if (csrfToken != null) {

            Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
            String token = csrfToken.getToken();
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (cookie != null || token != null && token.equals(cookie.getValue())
                    && (authentication != null && authentication.isAuthenticated())) {

                cookie = new Cookie("XSRF-TOKEN", token);
                cookie.setPath("/");
                response.addCookie(cookie);
            }
        }

        return new ResponseEntity<>("Login Successful", null, HttpStatus.OK);
    }
}

0 个答案:

没有答案