gpt4 book ai didi

java - 我的项目中缺少什么注释?

转载 作者:行者123 更新时间:2023-12-01 19:08:02 25 4
gpt4 key购买 nike

我读过类似的问题,但找不到解决方案。

我正在使用 Vaadin 和 Spring Boot。我之前有一个项目运行良好,没有收到此白标签消息,并且我使用相同的注释和所有内容。在入口点 Spring Boot 类中,我定义了 @SpringBootApplication。

“此应用程序没有/error 的显式映射,因此您将其视为后备。

2019 年欧洲中部时间 12 月 28 日星期六 18:56:32出现意外错误(类型=未找到,状态=404)。无可用消息”

同时我认为问题出在我的 POM 上。

感谢您的帮助,以免下次再犯同样的问题。

我的服务类别:

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;


@Component
public class PersonService {

@Autowired
private JdbcTemplate JdbcTemplate;

public List<Person>

findAll() {
return JdbcTemplate.query(
"SELECT Név, Mérkőzések_száma, Győzelmek_száma, Vereségek_száma FROM Darts",
(rs, rowNum) -> new Person(rs.getString("nev"),
rs.getInt("games"), rs.getInt("wins"), rs.getInt("loses")));
}
public void update(Person person) {
JdbcTemplate.update(
"UPDATE Darts SET Mérkőzések_száma=?, Győzelmek_száma=?, Vereségek_száma=? WHERE Név=?)",
person.getGames(), person.getWins(), person.getLoses(), person.getName());
}

}

我的人物类:

public class Person {

private String name;
private int games;
private int wins;
private int loses;

public Person(String name, int games, int wins, int loses) {
this.name = name;
this.games = games;
this.wins = wins;
this.loses = loses;
}

public int getLoses() {
return loses;
}

public void setLoses(int loses) {
this.loses = loses;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getGames() {
return games;
}

public void setGames(int games) {
this.games = games;
}

public int getWins() {
return wins;
}

public void setWins(int wins) {
this.wins = wins;
}



}

我的 MainView 类:

import com.vaadin.data.Binder;
import com.vaadin.flow.router.Route;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.*;
import com.vaadin.spring.annotation.SpringUI;
import org.springframework.beans.factory.annotation.Autowired;


@SpringUI
public class MainView extends UI {

@Autowired
private PersonService service;

private TextField name = new TextField("Name");
private TextField games = new TextField("Game");
private TextField wins = new TextField("Win");
private TextField loses = new TextField("Lose");

private Person person;

private final Binder<Person> bind = new Binder<>(Person.class);
private final Grid<Person> grid = new Grid<>(Person.class);



@Override
protected void init(VaadinRequest request) {

grid.setColumns("name", "games", "wins", "loses");

VerticalLayout layout = new VerticalLayout(grid, name, games, wins, loses);

setContent(layout);


}
}

POM:

<?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.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.benjaminhalasz</groupId>
<artifactId>darts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>darts</name>
<description>Demo project for Spring Boot</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<vaadin.version>14.1.3</vaadin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</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>com.vaadin</groupId>
<artifactId>vaadin-spring</artifactId>
<version>3.0.1</version>
<type>jar</type>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

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

</project>

编辑:应用程序属性:

spring.datasource.url=jdbc:mysql://localhost/vizsgadb_HB
spring.datasource.username=vizsgauser_HB
spring.datasource.password=12345678
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

最佳答案

经过一番研究,似乎:

  • 在您的 POM 中,您应该删除依赖项 vaadin-spring。它与 vaadin-spring-boot-starter 导入的版本不同。使用启动器时,尝试仅使用启动器,不要使用其他东西。它们旨在承载您需要的所有依赖项。
  • 您应该将@SpringUI替换为@Route。欲了解更多信息,请查看:https://www.baeldung.com/spring-boot-vaadin

请告诉我这是否有效。

关于java - 我的项目中缺少什么注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59513572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com