src/main/resources/templates/index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org" xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Spring Security Example</title>
</head>
<body>
<h1>Welcome!</h1>
<p>Click <a th:href="@{/main}">here</a> to see a greeting.</p>
</body>
</html>
src/main/resources/templates/main.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
src/main/resources/templates/mylogin.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Spring Security Example </title>
</head>
<body>
<div th:if="${param.error}">
Invalid username and password.
</div>
<div th:if="${param.logout}">
You have been logged out.
</div>
<form th:action="@{/mylogin}" method="post">
<div><label> User Name : <input type="text" name="username"/> </label></div>
<div><label> Password: <input type="password" name="password"/> </label></div>
<div><input type="submit" value="Sign In"/></div>
</form>
</body>
</html>
package com.example.security;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MVCConfig implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/index").setViewName("index");
registry.addViewController("/").setViewName("index");
registry.addViewController("/main").setViewName("main");
registry.addViewController("/mylogin").setViewName("mylogin");
}
}
package com.example.security;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/main").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/mylogin")
.permitAll()
.and()
.logout()
.permitAll();
}
@Bean
@Override
public UserDetailsService userDetailsService() {
UserDetails user =
User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}
}
package com.example.security;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SecurityApplication {
public static void main(String[] args) {
SpringApplication.run(SecurityApplication.class, args);
}
}
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
你忘记了一个依赖关系。请添加
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
对你的依赖。
您可以在这里看到运行示例https://github.com/ozkanpakdil/spring-examples/tree/master/gradle-thymeleaf
循环视图路径[login]:将再次调度回当前处理程序URL[/login]。检查您的ViewResolver设置!(提示:这可能是由于默认视图名称生成而导致的未指定视图的结果。)
问题内容: 循环视图路径[登录]:将再次分派回当前的处理程序URL [/ login]。检查您的ViewResolver设置!(提示:由于默认视图名称的生成,这可能是未指定视图的结果。) 问题答案: 添加此依赖项
我正在使用基于Git的Spring Cloud项目。在这个项目中,我指出了https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls。 当我简单地启动URL:http://localhost:8888/actuator/s1rates/default或http://localhost:8888/s1rates/defaul
我通过cmd为Django设置网页。然而,我在访问127.0的索引页时遇到了问题。0.1:8001. 我试图更新URL。但是仍然有问题。 浏览器页面错误:找不到页面(404)请求方法:获取请求URL:http://127.0.0.1:8001/index使用barry中定义的URLconf。Django尝试了以下URL模式,顺序如下: 管理员/当前路径索引与这些路径中的任何一个都不匹配。
ServletException:循环视图路径[home]:将再次分派回当前处理程序URL[/home]。检查您的视图解析器设置!(提示:这可能是由于默认视图名称生成而导致的未指定视图的结果。)在org.springframework.web.servlet.view.internalResourceView.prepareforrendering(internalResourceView.jav
我的循环视图滚动太慢了。当我通过触摸Recyclerview开始滚动时,它会滞后,但当从上方的视图开始滚动时不会滞后。我还禁用了recyclerview上的嵌套滚动。 这是我的布局: 这是一个滞后的视频。就像滚动跳过了一些布局。