我正在使用带有 Spring security 的 Thymeleaf 模板引擎。我还使用 Thymeleaf Spring Security 集成模块来使用 sec:authorize 功能,但由于某种原因它不起作用。我没有收到任何错误,但无论用户具有哪个角色,html div 块中的所有代码都会执行。
例如,当我以员工身份登录时,我还会看到“转到领导者”和“转到系统”按钮,但我不希望员工看到这些按钮。
这是我的 pom.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>security</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>security</name>
<description>Demo project for Spring Boot security</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId> …Run Code Online (Sandbox Code Playgroud) 我正在编写一个博客应用程序,但我在使用 Hibernate 时遇到了问题。当我的用户表中有 2 行具有相同的 role_id 时,就会出现问题。添加具有相同 id 的第三个用户后,抛出异常。
我试图设置 Lazy init。但它似乎不起作用。
这是我的用户类。
@NoArgsConstructor
@Getter
@Setter
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
private String password;
private String email;
private String dateCreated;
private String createdBy;
private String dateModified;
private String modifiedBy;
@Transient
private Position position;
@ManyToMany(mappedBy = "users", cascade = CascadeType.ALL)
private Set<Blog> blogs = new HashSet<>();
@OneToMany(mappedBy = "user")
private Set<Post> posts = new HashSet<Post>();
@OneToMany(mappedBy = "user")
private Set<Comment> comments …Run Code Online (Sandbox Code Playgroud)