当前位置: 首页 > 知识库问答 >
问题:

增加了Spring Security CORS过滤器-从DB检索的日期显示为数值

明利
2023-03-14

正如Hendy Irawan所建议的那样,我添加了这两个类来解决CORS问题:Spring security CORS Filter(第一个)答案。

第二个类(公共类MyFilter extends OncePerRequestFilter)有一点不同,我使用了Arrays.Aslist(“...”)而不是IMMUTABLELIST.of(“...”)

@RestController
public class UsersProfileController {
   @Autowired UserProfInterface userProfInterface;

   @GetMapping("/connector/{username}/users")
    public List<UserProfilesEntity> getAllUsers(
            @PathVariable String username) {
        return userProfInterface.getAllUsers();
    }
<?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 https://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.3.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bootcamp</groupId>
    <artifactId>connector</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>connector</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-data-rest</artifactId>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我使用的是Spring Security5.3.3版本

我是Stackoverflow的长期访客,这是我第一次询问,所以任何反馈都将不胜感激。

共有1个答案

洪高阳
2023-03-14

您可以使用“@JSONFormat”来显示您所期望的内容。关于Spring Security性,我不确定它是否会影响日期的格式

 类似资料:
  • 问题内容: 我正在使用日期输入字段,并使用Angular在我的ui中格式化所选日期。但是格式化日期总是比所选日期少1天。为什么会这样,我该如何解决? HTML: JS: 我有一个小提琴来演示这个问题:http : //jsfiddle.net/wittersworld/uY3s9/ 编辑: 我用一个有效的解决方案更新了小提琴:http : //jsfiddle.net/wittersworld/u

  • 问题内容: 我检索两个日期之间的数据,当我选择带有月份的日期时,它如何获得正确的结果,以及如何输出空列表视图,但是当我选择一个月以上的日期时,下面的输出空列表视图是我的代码 在这里我在DB类中声明变量 创建表语句 输入数据方法 在这里我访问ExEntry方法 在这里,我面临着这两个日期变量之间的问题 我像下面这样访问 问题答案: 有两种主要解决方案。所有解决方案的共同点是,必须以某种方式对包含日期

  • 我从postgres获取带有时区值的时间戳,在java中,我将结果存储在timestamp变量中。但是日期和时间会有一些变化。我没有得到最初的价值。 表 表数据 用户名=超人 日期时间=2016-12-12 10:06:39.582-08 sql 字符串uname=“超人”; String sql1=“从日志中选择日期时间”登录失败,其中用户名=““uname””; 我正在得到的结果 尝试日期时间

  • 问题内容: 我想使用swift在xcode中使用datePicker将星期几仅存储为字符串。 问题答案:

  • filter命令未按预期工作。如何重构代码以获得请求的输出? 在

  • 我是FHIR上的Smart新手,并使用fhirclient创建了一个用于培训目的的演示应用程序。js。我需要获得一些特定的患者重要信息,比如特定日期(过去3个月)的温度、体重等。 让我知道如何在这个搜索api中包含日期过滤器?