小编Com*_* v2的帖子

如何在 Spring Boot 中启用 CORS - 不工作

我正在尝试在我的 Spring Boot 应用程序中启用 CORS,但它根本不起作用。


我试过了

我不知道此时如何解决这个问题,也不知道 CORS 不起作用的问题是什么。


我的代码

控制器

@RestController
public class DbController {

    @Autowired
    private IDAO conn;

    @CrossOrigin
    @GetMapping("/foo")
    public List<Foo> getFoo() {
        return conn.getFooFromDao();
    }
}
Run Code Online (Sandbox Code Playgroud)

    @Repository
    public class DaoImpl implements IDAO {

    @Autowired
    private JdbcTemplate temp;

    public List<Foo> getFooFromDao() {

        List<Foo> data = new ArrayList<>();

        String sql = "SELECT fooName FROM BigFoo ORDER BY fooName ASC;";

        data.addAll(temp.query(sql, new BeanPropertyRowMapper(BigFoo.class)));
        return data;
    }
} …
Run Code Online (Sandbox Code Playgroud)

java spring cors spring-boot

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

如何从 Angular 材质对话框获取数据?

如何从 Angular 材质对话框内的输入字段获取数据?

这是我的代码:

TS

import { Component, OnInit, Inject } from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
  selector: 'app-test',
  templateUrl: './foo.component.html',
  styleUrls: ['./foo.component.scss']
})

export class SomeComponent implements OnInit {

  name: String;

  constructor(public dialog: MatDialog) { }

  ngOnInit() {
  }

  openDialog(): void {
    const dia = this.dialog.open(SomeDialogComponent, {
      width: "250px",
      data: { name: this.name }
    });

    dia.afterClosed().subscribe(result => {
      console.log("The dialog was closed");
      console.log("Your Name: " + this.name);
      this.name = result;
    });
  }
}

@Component({ …
Run Code Online (Sandbox Code Playgroud)

user-interface components user-input angular-material angular

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

通过 Yaml 配置 H2 数据库 - Spring Boot

我有一个 Spring Boot 应用程序,我想用 Yaml 配置我的 H2 数据库。每当我运行它时它都会崩溃。

我的 app.yml 文件:

spring:
  database: h2
  console: true
  path: /h2

datasource:
  platform: h2
  url: jdbc:h2://localhost:8080/h2
  username: sa
  password: 1234
  driverClassName: org.h2.Driver
Run Code Online (Sandbox Code Playgroud)

pom.xml

<dependencies>

    <!-- H2 Database -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>

....
</dependencies>
Run Code Online (Sandbox Code Playgroud)

不知道如何很好地使用yaml,我需要帮助看看我的yaml是否可以修复以合并H2数据库。

我正在尝试这样做: https //dzone.com/articles/integrate-h2-database-in-your-spring-boot-applicat

但是用app.yml代替app.properties.

提前致谢!

编辑:这是我的崩溃,

java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.session.SessionAutoConfiguration$ServletSessionConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3b764bce]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:507) ~[spring-core-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:404) ~[spring-core-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:389) ~[spring-core-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:447) ~[spring-core-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1751) ~[na:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:738) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE] …
Run Code Online (Sandbox Code Playgroud)

java yaml h2 maven spring-boot

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

角材料垫芯片未设置为可拆卸

问题陈述

我的问题是,当我使用 Angular Material's 时mat-chip,即使我将其设置为 true,它似乎也无法设置为可移动。


代码

<mat-form-field>
 <input matInput [matChipInputFor]="chipList" (matChipInputTokenEnd)="addOption($event)"
type="number" maxlength="4" placeholder="Enter an amount here">
 </mat-form-field>

<mat-chip-list>
<mat-chip #chipList *ngFor="let option of options" [removable]="true"
(removed)="removeOption(option)">{{option}}
</mat-chip>
</mat-chip-list>
Run Code Online (Sandbox Code Playgroud)

RemoveOption 方法

removeOption(option: String) {
    const index = this.options.indexOf(option);

    if (index >= 0) {
      this.options.splice(index, 1);
    }
  }
Run Code Online (Sandbox Code Playgroud)

代码说明

如您所见,我已设置[removable]为 true 并(removed)使用了一种removeOption方法。由于某些奇怪的原因,这些东西不起作用。

我从这里复制了示例:https://material.angular.io/components/chips/examples,示例部分命名为:“带输入的芯片”


实际产量

芯片在右侧显示了很多删除按钮:

在此处输入图片说明


预期产出

右边有一个小的移除按钮的芯片:

在此处输入图片说明

html angular-material angular

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

@RequestBody 未将 JSON 映射到 Java 对象 - Spring Boot

我无法将我的 JSON 从帖子的方法体转换为我的 POJO,@RequestBody在我的控制器类中。

我调试了错误,我看到某些字段被映射而其他字段没有。像这样(POJO)

name: null, typeOfPlan: null, Email: example@gmail.com, PhoneNum: 123456789, Website: test.org, Username: null, password: 1234,这很奇怪。

JSON:

{
    "confirmPassword": "1234",
    "email": "example@gmail.com",
    "password": "1234",
    "phoneNum": "123456789",
    "name": "Hello world",
    "typeOfPlan": "Test",
    "userName": "user",
    "website": "test.org"
}
Run Code Online (Sandbox Code Playgroud)

控制器

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SomeController {

    @Autowired
    private Service foo;

    @CrossOrigin
    @PostMapping(value = "/create")
    private void createAccount(@RequestBody BigFoo bigFoo) {
        foo.createAccount(bigFoo);
    }
}
Run Code Online (Sandbox Code Playgroud)

从这里,我调用我的服务,然后调用 DAO 类。 …

java mapping json spring-boot spring-restcontroller

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

如何将地图设置为以标记为中心?- 角度谷歌地图

地理编码后,我无法将我的 Google 地图放在标记上。

我有两个标记:初始标记(一个居中,不改变),另一个根据地理编码而变化,地理编码后,每次都以中心为中心。

我的代码:TS

zoom = 10;

addressData: FormGroup;
submitted = false;
success = false;

lat: number;
lng: number;

userLat: number;
userLng: number;

currentCenter = { lat: null, lng: null };

private geoCoder: google.maps.Geocoder;

@ViewChild('googleMap') googleMap: AgmMap;

constructor(private maps: MapsAPILoader, private bulider: FormBuilder) { }

ngOnInit() {
    this.addressData = this.bulider.group({
        address: ["", Validators.required],
    });

    this.maps.load().then(() => {
        this.geoCoder = new google.maps.Geocoder();
    });
}

getAddress() {

    this.submitted = true;

    if (this.addressData.invalid) {
        return;
    }

    this.success = true;

    this.googleMap.mapReady.subscribe(map => …
Run Code Online (Sandbox Code Playgroud)

geolocation marker angular-google-maps angular

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

类型错误:this._chipList.registerInput 不是函数 - Angular Material

问题陈述

我试图从<input>标签获取输入并将其显示为 GUI 中的芯片,但控制台给出错误:"TypeError: this._chipList.registerInput is not a function"


代码

<mat-form-field>
<h3 class="sizeHeading">Add a size</h3>
<input matInput [matChipInputFor]="sizes" (matChipInputTokenEnd)="addSize($event)" <= Crash happens here
[(ngModel)]="data.size" class="sizeInput"><br><br>
</mat-form-field>

.... <!-- More code here but it is not part of the problem and what I am trying to show -->

<!-- Sizes display as chips -->
<div *ngIf="!displayOptions">
<mat-chip-list>
<mat-chip #sizes *ngFor="let size of sizes" [removable]="removable"
(removed)="removeSize(size)">
{{size}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
</mat-chip-list>
</div>
Run Code Online (Sandbox Code Playgroud)

代码解释

在 HTML 代码的顶部块中,我试图获取用户输入并将其显示为 GUI …

html angular-material angular

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

角度材质表:类型“ContentComponent”上不存在属性“displayedColumns”

问题陈述

我有一个 Angular 材料表,我想显示数据,但它在这些行上中断:

<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
Run Code Online (Sandbox Code Playgroud)

并说:

类型“ContentComponent”上不存在属性“displayedColumns”。


代码

超文本标记语言

<mat-table [dataSource]="students">

    <ng-container>
        <mat-header-cell *matHeaderCellDef>First name</mat-header-cell>
        <mat-cell *matCellDef="let student"> {{student.firstName}} </mat-cell>
    </ng-container>

    <ng-container>
        <mat-header-cell *matHeaderCellDef>Last name</mat-header-cell>
        <mat-cell *matCellDef="let student"> {{student.lastName}} </mat-cell>
    </ng-container>

    <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
    <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
Run Code Online (Sandbox Code Playgroud)

.TS文件

import { Component, OnInit, Input } from '@angular/core';
import { Student } from '../Models/Student';

@Component({
  selector: 'app-content',
  templateUrl: './content.component.html',
  styleUrls: ['./content.component.css']
})
export class ContentComponent implements OnInit {

  constructor() { }

  ngOnInit(): void { …
Run Code Online (Sandbox Code Playgroud)

angular-material angular mat-table

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

有没有办法禁用自动完成输入?- 角材料

autocomplete在 Angular 材料中有以下内容:

 <!-- Drop Down menu -->
          <mat-form-field>
            <input placeholder="Select one" [matAutocomplete]="auto" matInput>

            <mat-autocomplete #auto="matAutocomplete">
              <mat-option value="Cars">Cars</mat-option>
              <mat-option value="Books">Books</mat-option>
            </mat-autocomplete>
          </mat-form-field>
Run Code Online (Sandbox Code Playgroud)

有没有办法禁用输入,input以便用户不会破坏下拉菜单的目的?现在,用户只需键入内容而不是选择选项,甚至可以在选择时编辑选项。

autocomplete angular-material angular

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

一条 SQL 语句中存在多个 WHERE 条件

我在使用许多WHERE条件时遇到困难,因为我确实需要在一个语句中组合8 个条件。 Where

我当前的SQL:

SELECT * 
FROM Table 
WHERE ID = ?
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

SELECT * 
FROM Table 
WHERE ID = ?, WHERE COL2 = ?, WHERE COL3 = ?, ... WHERE COL8 = ?
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个目标?我被困住了。

sql conditional-statements

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

PLS-00103:在预期以下情况之一时遇到符号“ON”

请注意:我尝试过其他堆栈溢出问题,但没有解决我的问题......

我收到此错误:PLS-00103: Encountered the symbol "ON" when expecting one of the following使用以下代码:


SET SERVEROUTPUT ON;

DECLARE
    v_province         VARCHAR(4) := &province;
    v_numberOfVisits   NUMBER;
    v_totallaborcost   NUMBER;
BEGIN
    findvisitsandlaborcost(v_numberofvisits, v_totallaborcost, v_province);
    dbms_output.put_line('Number of visits for province '
                         || v_province
                         || ': '
                         || v_numberofvisits);
    dbms_output.put_line('Total labor cost for province '
                         || v_province
                         || ': '
                         || v_totallaborcost);
END;
/
Run Code Online (Sandbox Code Playgroud)

findvisitsandlaborcost定义:

CREATE OR REPLACE PROCEDURE findvisitsandlaborcost (
    numberofvisits   OUT   NUMBER,
    totallaborcost   OUT   NUMBER,
    province         VARCHAR
) AS
    v_numberofvisits   si.servinv.servinvno%TYPE;
    v_totallaborcost   si.servinv.laborcost%TYPE; …
Run Code Online (Sandbox Code Playgroud)

oracle plsql compiler-errors

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

如何使用 Yaml 配置 Flyway?

我有一个spring boot项目,我需要在我的application.yml文件中配置Flyway 。

有谁知道如何用 Yaml 做到这一点?

configuration yaml flyway spring-boot

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