小编Mai*_*sad的帖子

InvalidDataAccessApiUsageException: 没有枚举常量

我有一个 Role 枚举,如下所示:

public enum Role{
    admin('a'),
    member('m'),
    pending('p');
    char role;
    Role(char a) {
        this.role = a;
    }
    public char getRole() {
        return role;
    }
    public static Role getByRole(char role) {
        return Arrays.stream(Role.values())
                .filter(Role -> Role.getRole() == role)
                .findFirst()
                .orElse(Role.pending);
    }
}
Run Code Online (Sandbox Code Playgroud)

为了支持转换,我创建了一个名为 RoleConverter 的类:

@Converter
public class RoleConverter implements AttributeConverter<Role, Character> {
    @Override
    public Character convertToDatabaseColumn(Role Role) {
        return Role.getRole();
    }
    @Override
    public Role convertToEntityAttribute(Character dbData) {
        System.out.println(dbData);
        return Role.getByRole(dbData);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的 Target 对象中,我添加了适当的注释:

    @Convert(converter = RoleConverter.class)
    @Enumerated(EnumType.STRING) …
Run Code Online (Sandbox Code Playgroud)

spring jpa h2 spring-data-jpa spring-boot

3
推荐指数
1
解决办法
4440
查看次数

Spring Boot + Spring Security + CORS 中没有“Access-Control-Allow-Origin”

我正在尝试使用 Spring security 进行 CORS。这是我的 WebSecurityConfigurerAdapter :


@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .cors()
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .oauth2Login();
    }
    @Bean
    public CorsConfigurationSource corsConfigurationSource() {
        final CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowedOrigins(List.of("*"));
        configuration.setAllowedMethods(List.of("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"));
        configuration.setAllowCredentials(true);
        configuration.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type"));
        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 WebMvcCofigurer :

@EnableWebSecurity
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer
{
    @Override
    public void …
Run Code Online (Sandbox Code Playgroud)

spring-security cors oauth-2.0 reactjs spring-boot

2
推荐指数
1
解决办法
1万
查看次数

TailwindCSS 在单击时淡入元素

所以我正在制作这个应用程序,当我单击按钮时,我需要淡入菜单。我使用状态在单击时呈现它,但无法让它在单击时淡入/淡出。当我opacity在 Chrome 开发控制台中编辑值时,转换工作正常,但当我想使用状态更改它时,它却不起作用。

有什么帮助吗?提前致谢!

import React, { useState } from "react";
import { useRouter } from "next/router";
import { MenuIcon, XIcon } from "@heroicons/react/outline";

function Header() {
  const router = useRouter();

  const [popCard, setPopCard] = useState("hidden");
  const [fade, setFade] = useState(true);

  const handleMenuClick = () => {
    setPopCard("inline-block");
    setFade(true);
  };

  const handleXClick = () => {
    setPopCard("hidden");
    setFade(false);
  };

  return (
    <div className="text-center">
      <header className="sticky z-50 top-0  shadow-md bg-white border-b p-5">
        <div className="flex justify-between items-center">
          <h1
            className="text-6xl text-red-500 …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js tailwind-css

2
推荐指数
1
解决办法
2万
查看次数

Django 查询中条件求和

我们想在 django 中编写这个查询

SELECT sum(recommended='1') AS YES,sum(recommended='0') AS NO FROM `rating` WHERE applied_users = 32500 
Run Code Online (Sandbox Code Playgroud)

我们不知道如何使用 sum "= 1"

Rating.objects.filter(applied_id = 32500).aggregate(YES=Sum('recommended'))
Run Code Online (Sandbox Code Playgroud)

mysql django

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

C# 执行、等待、读取命令的输出

我正在尝试使用 C# 读取 Windows 电脑上的所有系统信息。这是我的代码:

 public static string GetSystemInfo()
        {
            String command = "systeminfo";
            ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe");
            cmdsi.Arguments = command;
            Process cmd = Process.Start(cmdsi);
            cmd.WaitForExit();
            return cmd.StandardOutput.ReadToEnd();
        }
Run Code Online (Sandbox Code Playgroud)

但它只是打开一个控制台,不执行systeminfo命令。

如何解决这个问题?

.net c# cmd process

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

antd V4中如何设置Form.List下的多个FormItem

antd 中的单个 FormItem 演示:https ://ant.design/components/form/#components-form-demo-dynamic-form-item 。每次只动态生成一个FormItem。

而且,这里是我想要实现什么。

但我总是遇到一些错误,比如错误的交互、错误的验证或错误的表单值。

我的代码:

<Form.List name="passenger">
    {(fields, { add, remove }) => {
      return (
        <div>
          {fields.map((field, index) => (
            <Form.Item
              {...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
              label={index === 0 ? 'Passengers' : ''}
              required={false}
              key={field.key}
            >
              <Form.Item
                {...field}
                validateTrigger={['onChange', 'onBlur']}
                rules={[
                  {
                    required: true,
                    whitespace: true,
                    message: "Please input passenger's name or delete this field.",
                  },
                ]}
                noStyle
              >
                <Input placeholder="passenger name" style={{ width: '40%' }} />
              </Form.Item>

              <Form.Item
                name={['age', index]}
                validateTrigger={['onChange', …
Run Code Online (Sandbox Code Playgroud)

reactjs antd

1
推荐指数
1
解决办法
2万
查看次数

y 中人口最少的类只有 1 个成员,太少了。任何班级的最少小组人数不能少于2人。该怎么办

在此输入图像描述

我正在 covid 19 数据集上制作 ML 项目并收到这样的错误

from sklearn.model_selection import StratifiedShuffleSplit
split = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state=42)
for train_index, test_index in split.split(covid, covid['Death Ratio']):
    strat_train_set = covid.loc[train_index]
    strat_test_set = covid.loc[test_index]
Run Code Online (Sandbox Code Playgroud)

我尝试了很多方法来解决,但我没能做到

ValueError                                Traceback (most recent call last)
<ipython-input-31-42056912ab46> in <module>
      1 from sklearn.model_selection import StratifiedShuffleSplit
      2 split = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state=42)
----> 3 for train_index, test_index in split.split(covid, covid['Death Ratio']):
      4     strat_train_set = covid.loc[train_index]
      5     strat_test_set = covid.loc[test_index]

c:\users\hp\appdata\local\programs\python\python37\lib\site-packages\sklearn\model_selection\_split.py in split(self, X, y, groups)
   1385         """
   1386         X, y, groups = indexable(X, …
Run Code Online (Sandbox Code Playgroud)

python machine-learning scikit-learn

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

使用 strtok 将字符串拆分为双指针

char **params;
for (int i = 0; i < 100; i++) {
    params++ = NULL;
}

int i = 0;
char* parn = strtok(all_p, " ");
           
while (parn != NULL) {
    params++ = parn;
    parn = strtok(NULL, " ");
}
            
for (int i = 0; params[i] !=NULL; i++) {
    printf("--%s--\n", *params);
}
Run Code Online (Sandbox Code Playgroud)

我只是想在分割字符串/字符数组后创建一个双指针,其中有空间。

但在编译过程中它给了我一个错误:error: expression is not assignable。关于喜欢NULLparn任务。我该如何解决这个问题?

c strtok

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

React.js 设置默认路由

我的中有这段代码index.js

const routing = (
<Router>
    <Switch>
        <Route exact path="/">
            <Redirect to="/a" />
        </Route>
        <Route path="/a" component={A} />
        <Route path="/b" component={B} />
        <Route path="/c" component={C} />
    </Switch>
</Router>
)
Run Code Online (Sandbox Code Playgroud)

它直接降落,我也/a可以去。/b/c

如果我尝试转到“/something”,它不会呈现任何内容,因为该路径的组件未定义。

我想要实现的是,我不想授予对“/something”的访问权限,尽管它什么也没有提供,也没有呈现任何内容。我希望如果有人尝试访问“/something”,他会自动重定向到“/default”。

是否可以 ?

reactjs react-router react-router-dom

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

c中的三元运算符和goto,同时执行

我正在尝试在三元运算符中实现 goto:

所以这就是我在做什么:

(a<5 && done==0) ? ({goto dd;}) : ({goto ee;});
Run Code Online (Sandbox Code Playgroud)

使用这些大括号,我试图将语句转换为表达式。

问题是,两个标签都在执行。为什么?

这是代码(Ideone 链接):

#include<stdio.h>
int main()
{
    int a=0,sum=0;
    int done=0;

    (a<5 && done==0) ? ({goto dd;}) : ({goto ee;});

    dd:
        printf("%d - %d -- %d\n",a,sum,done);
        ++a,sum+=a;
    ee:
        printf("done\n");
        done=1;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c goto conditional-operator

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

Spring Boot 安全性不允许我访问 h2-console

我正在尝试在 Spring Boot 中实现 JWT。出于某些调试目的,我需要 H2 控制台。

所以在我的WebSecurityConfiguration中,我写道:

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        //httpSecurity.headers().frameOptions().disable();
        httpSecurity.authorizeRequests().antMatchers("/h2").permitAll();
        httpSecurity
                .csrf().disable()
                .authorizeRequests()
                .antMatchers("/auth/check/username").permitAll()
                .antMatchers("/auth/signup").permitAll()
                .antMatchers("/auth/login").permitAll()
                .anyRequest().authenticated().and()
                .exceptionHandling().and().sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
        httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);

    }
Run Code Online (Sandbox Code Playgroud)

在我的应用程序属性中,我有以下配置:

spring.h2.console.enabled=true
spring.h2.console.path=/h2
Run Code Online (Sandbox Code Playgroud)

当我点击“:8080/h2”时,它给了我403

所以问题仍然是,如何正确配置 Spring Boot Web Security。

包含后/h2/**,我得到这个用户界面:

Spring Boot 阻止 h2 控制台

spring h2 spring-security spring-boot

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

this.setState()不能正常工作-react.js

componentWillMount() {
        let dID=this.props.match.params.datumID;
        this.setState({datumID: dID});
        console.log(dID);
        console.log(this.state.datumID);
    }
Run Code Online (Sandbox Code Playgroud)

我只是在尝试使用setState()方法。

但是问题是它不起作用。

这是我得到的输出:

First console.log() : 66
Second console.log(): null
Run Code Online (Sandbox Code Playgroud)

reactjs

-2
推荐指数
2
解决办法
67
查看次数