小编Jil*_*ill的帖子

是否可以通过 Python 将 JavaScript 代码放入 JS 文件中?

with open("C:scripts/CUAppVersion.js", 'a') as file:
file.write("if [CUID] = -1 then"
    "function GetCUID() { return 0; }"
"else"
    "function GetCUID() { return [CUID] });")
Run Code Online (Sandbox Code Playgroud)

那是我的代码,它成功地将 JS 放入了 JS 文件中,但它把它放在了一行上,而不是像我上面输入的那样。我知道我的 JS 代码不完全正确,我确实需要修复它。

如何将该代码放入具有正确布局的 JS 文件中?

javascript python file

4
推荐指数
1
解决办法
3093
查看次数

如何显示使用Spring Boot Thymeleaf的当前登录用户?

我试图显示当前用户的详细信息,但是我不断收到错误消息。我尝试从模板访问经过身份验证的用户,但是由于出现此错误,该操作不起作用:

在org.springframework.security.core.userdetails.User类型上找不到方法getFirstName()

我试图从控制器中获取信息,然后将其保存在字符串中并将该字符串传递给模板,但这都不起作用。

这是我的SecurityConfig类:

    @Configuration
 public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private UserService userService;

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
                .antMatchers(
                        "/registration",
                        "/js/**",
                        "/css/**",
                        "/img/**",
                        "/webjars/**").permitAll()
                .anyRequest().authenticated()
            .and()
                .formLogin()
                    .loginPage("/login")
                        .permitAll()
            .and()
                .logout()
                    .invalidateHttpSession(true)
                    .clearAuthentication(true)
                    .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                    .logoutSuccessUrl("/login?logout")
            .permitAll();
}

@Bean
public BCryptPasswordEncoder passwordEncoder(){
    return new BCryptPasswordEncoder();
}

@Bean
public DaoAuthenticationProvider authenticationProvider(){
    DaoAuthenticationProvider auth = new DaoAuthenticationProvider();
    auth.setUserDetailsService(userService);
    auth.setPasswordEncoder(passwordEncoder());
    return auth;
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(authenticationProvider());

}
Run Code Online (Sandbox Code Playgroud)

这是我的UserService类:

 public interface …
Run Code Online (Sandbox Code Playgroud)

spring login spring-security thymeleaf spring-boot

3
推荐指数
2
解决办法
4454
查看次数

Ruby-On-Rails如何从单选按钮进行布尔性别选择在show.html中显示为字符串(M或F)

在创建新用户时,他们使用单选按钮选择女性男性.当我进入节目视图时,他们的性别显示为真或假,而不是男性或女性.

_form.html.erb
  <%= f.label :gender %><br />
 <%= f.label :gender, "Male", :value => "true"  %>
<%= f.radio_button :gender, true %>
<%= f.label :gender, "Female", :value => "false" %>
<%= f.radio_button :gender, false %>


Show.html.erb
<p>
  <strong>Gender:</strong>
  <%= @user.gender %>
</p>
Run Code Online (Sandbox Code Playgroud)

boolean ruby-on-rails

0
推荐指数
1
解决办法
1752
查看次数