嗨,我是springboot新手,我试图用它创建RESTful API,当我用它创建controller时,它已经起作用了,但当我试图在pom.xml中添加这一行时
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<?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.3.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.movie.db</groupId>
<artifactId>KotakKantorMovieDB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>KotakKantorMovieDB</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>13</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-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-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.movie.db.KotakKantorMovieDB.controllers;
import com.movie.db.KotakKantorMovieDB.models.Customer;
import com.movie.db.KotakKantorMovieDB.repository.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class CustomerController {
@Autowired
private CustomerRepository repository;
@GetMapping("/customer")
public Customer findCustomer() {
return repository.findByFirstName("cactuspot");
}
@PostMapping("/addcustomer")
public Customer addCustomer(@RequestBody Customer newCustomer ) {
return repository.save(newCustomer);
}
}
package com.movie.db.KotakKantorMovieDB.models;
import org.springframework.data.annotation.Id;
public class Customer {
@Id
public String id;
public String firstName;
public String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
package com.movie.db.KotakKantorMovieDB.repository;
import java.util.List;
import com.movie.db.KotakKantorMovieDB.models.Customer;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface CustomerRepository extends MongoRepository<Customer, String> {
public Customer findByFirstName(String firstName);
public List<Customer> findByLastName(String lastName);
}
我错过了什么?如果我添加spring-boot-starter-data-rest
,是否有一些不应该使用的依赖项?
我试图删除:
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
这个依赖项,它解决了错误,我不知道为什么这个依赖项会导致错误,我也不知道为什么需要这个依赖项,我运行我的应用程序,没有这个依赖项,它就能正常工作。也许和Hateoas有关。如果有人能向我解释,我会接受它作为答案
这是我的申请 数据源:类型:com.zaxxer.hikari.HikariDataSource主要: 这是我的入门: 这是我的例外: 2017-11-21 10:10:33.126线程“main”中的表现:java.lang.运行时异常: java.lang.ClassCastException: 无法将 com.mysql.cj.jdbc.Driver to javax.sql.DataSou
很抱歉,我对Java知之甚少。我得到了这个代码来接管。基本上,我在 当我运行代码时。 下面是解析XML的块 这是Improts,不确定是否需要这样做 这是XML文件
然后,我创建了注释代码。 结果 原因:java.lang.StringIndexOutOfBoundsException:长度=0;指数=-6 说真的,我和这个代码斗争了7小时30分钟。
URL类 来自服务器的最终响应:
库mysql-connector-java-8.0.25.jar,jsoup-1.13.1.jar 线程“main”java.lang.indexoutOfboundsException:在java.base/jdk.internal.util.preconditions.outofbounds(preconditions.java:64),在java.base/jdk.internal.util