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

Spring Boot不会创建@requestmapping(value=“/path”)中定义的路径

屠晟睿
2023-03-14
@RestController

@CrossOrigin()

@RequestMapping(value="/userinfo")

public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping()
    public ResponseEntity<UUID> insertUser(@Valid @RequestBody UserDTO UserDTO) {
        UUID personID = userService.insert(UserDTO);
        return new ResponseEntity<>(personID, HttpStatus.CREATED);
    }

    @PutMapping()
    public ResponseEntity<UUID> insertIntoUser(@Valid @RequestBody UserDTO UserDTO) {
        UUID personID = userService.insert(UserDTO);
        return new ResponseEntity<>(personID, HttpStatus.CREATED);
    }

    @GetMapping()
    public ResponseEntity<List<UserDTO>> getUser() {
        List<UserDTO> dtos = userService.findUser();
        for (UserDTO dto : dtos) {
            Link personLink = linkTo(methodOn(UserController.class)
                    .getUserByID(dto.getId())).withRel("personDetails");
            dto.add(personLink);
        }
        return new ResponseEntity<>(dtos, HttpStatus.OK);
    }

    @GetMapping(value = "userid/{id}")
    public ResponseEntity<UserDTO> getUserByID(@PathVariable("id") UUID TenantID) {
        UserDTO dto = userService.findUserById(TenantID);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }

    @GetMapping(value = "userrole/{role}")
    public ResponseEntity<UserDTO> getUserByRole(@PathVariable("role") int role) {
        UserDTO dto = userService.findUserByROle(role);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }

    @GetMapping(value = "/userinfoname/{name}")
    public ResponseEntity<UserDTO> getUserByName(@PathVariable("name") String role) {
        UserDTO dto = userService.findUserByName(role);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }

    @DeleteMapping(value = "deleteusername/{name}")
    public ResponseEntity<String> deleteUserByName(@PathVariable("name") String Tenantname){
        userService.deleteUserByname(Tenantname);
        String personID=Tenantname;
        return new ResponseEntity<>(personID, HttpStatus.CREATED);
    }

    @DeleteMapping(value = "deleteuserid/{id}")
    public ResponseEntity<String> deleteUserById(@PathVariable("id") UUID TenantID){
        userService.deleteUserById(TenantID);
        UUID personID=TenantID;
        return new ResponseEntity(personID, HttpStatus.CREATED);
    }




@RestController

  @CrossOrigin()

  @RequestMapping(value="/property")

  public class PropertyController {

    private final PropertyService propertyService;
    private final UserService userService;

    @Autowired
    public PropertyController(PropertyService propertyService,UserService userService) {
        this.propertyService = propertyService;
        this.userService = userService;
    }


    @PostMapping()
    public ResponseEntity<UUID> insertProperty(@Valid @RequestBody PropertyDTO PropertyDTO) {
        UUID personID = propertyService.insert(PropertyDTO);
        return new ResponseEntity<>(personID, HttpStatus.CREATED);
    }

    @PutMapping()
    public ResponseEntity<UUID> insertintoProperty(@Valid @RequestBody PropertyDTO PropertyDTO) {
        UUID personID = propertyService.insert(PropertyDTO);
        return new ResponseEntity<>(personID, HttpStatus.CREATED);
    }

    @GetMapping()
    public ResponseEntity<List<PropertyDTO>> getProperty() {

        List<PropertyDTO> dtos = propertyService.findProperty();

        for (PropertyDTO dto : dtos) {

            Link personLink = linkTo(methodOn(PropertyController.class)

                    .getProperty(dto.getId())).withRel("personDetails");

            dto.add(personLink);
        }
        return new ResponseEntity<>(dtos, HttpStatus.OK);
    }
    
    @GetMapping(value = "/{id}")
    public ResponseEntity<PropertyDTO> getProperty(@PathVariable("id") UUID PropertyID) {
        PropertyDTO dto = propertyService.findPropertyById(PropertyID);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }

    @GetMapping(value = "propertname/{name}")
    public ResponseEntity<PropertyDTO> getPropertyByName(@PathVariable("name") String   PropertyName) {
        PropertyDTO dto = propertyService.findPropertyByName(PropertyName);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }

    @GetMapping(value = "propertowner/{name}")
    public ResponseEntity<PropertyDTO> getPropertyByUser(@PathVariable("name") String UserName) {
        UserDTO dto = userService.findUserByName(UserName);
        Userinfo user= UserBuilder.toEntity(dto);
        PropertyDTO prdto = propertyService.findPropertyByUser(user);
        return new ResponseEntity<>(prdto, HttpStatus.OK);
    }


    @GetMapping(value = "propertylocation/{location}")
    // @RequestMapping(method=RequestMethod.GET)
    public ResponseEntity<PropertyDTO> getPropertyByLocation(@PathVariable("location") String PropertyLocation) {
        PropertyDTO dto = propertyService.findPropertyByLocation(PropertyLocation);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }

    @DeleteMapping(value = "/{name}")
    public ResponseEntity<String> deleteByname(@PathVariable("name") String Propertyname){
        propertyService.deletePropertyByname(Propertyname);
        String personID=Propertyname;
        return new ResponseEntity<>(personID, HttpStatus.CREATED);
    }

userinfoes
href“http://localhost:8080/userinfoes{?page,size,sort}”模板化的真预订
href“http://localhost:8080/bookings{?page,size,sort}”模板化的真属性
href“http://localhost:8080/profile”

我可以使用上面的地址只是基本的邮政和获得没有参数。如果添加了参数,则显示以下错误:

“cause”:{“cause”:null,“message”:“Invalid UUID string:name”},“message”:“未能将值'name'从类型[java.lang.string]转换为类型[java.util.UUID];嵌套异常为java.lang.IllegalArgumentException:Invalid UUID string:name”}

pom如下所示:

4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.3.发布com.rentbackend demo 0.0.1-final project jar的快照backEnd backEnd

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <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-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>6.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- TESTING -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>html" target="_blank">junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>

</dependencies>

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

    </plugins>
</build>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <configLocation>checkstyle.xml</configLocation>
            </configuration>
        </plugin>
    </plugins>
</reporting>

共有1个答案

班思源
2023-03-14
@GetMapping(value = "userid/{id}")
    public ResponseEntity<UserDTO> getUserByID(@PathVariable("id") UUID TenantID) {
        UserDTO dto = userService.findUserById(TenantID);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }

您的输入需要是有效的UUID。(因为UUID TenantID)

用户ID/62FE0290-3702-4B4B-BF02-42103DB90B0F

像这样的东西

 类似资料:
  • 我正在学习Spring Boot来构建应用程序。我试图用不同包中的控制器作为应用程序来构建我的第一个Spring Boot应用程序。Tomcat实例出现,但请求没有到达为URI注册的RestController。 以下是控制器类: 以下是应用程序类: Pom.xml tomcat启动时的日志: 我添加了基本包扫描,甚至尝试了注释,但当我点击URL(http://localhost:8080/abc

  • 我正在使用Spring Boot创建一个访问数据库的简单web应用程序。通过在中设置属性,我利用了DataSource的自动配置功能。这一切都很出色,而且非常快--伟大的工作伙计们@Spring! 我公司的政策是不应该有明文密码。因此,我需要对进行加密。经过一番深入研究,我决定创建一个实现,该实现创建一个jasypt,如下所示: 然后,我用文件将其打包到它自己的jar中,如下所示: 当在maven

  • 我试图在我的应用程序中使用JPA,但当我添加JPA并启动应用程序时,我遇到了这个错误。我在stackoverflow和其他网站上看到了与相同错误相关的问题,建议了许多答案,但没有运气解决这个错误。。我不明白我哪里做错了。 POM。XML 实体类 存储库类 控制器类 我得到的错误是 我试过了 创建在类路径资源中定义的名为“entityManagerFactory”的bean时出错:调用init方法失

  • 我在REST WebService工作。我浏览了一些博客,在那里我看到将URL映射到一个方法,他们使用了不同的注释。有些地方使用,有些地方使用。两者有何不同?

  • 我从Spring.io生成了一个springboot项目,并从Spring.io添加了一个web服务和jpa,我使用IntelliJ13,我的数据库是db2,但是当运行一个应用程序时,我出现了这个错误,请帮助我: spring Initializr: 下面给出了详细的误差 控制器

  • 我的Java程序()的目录下有一堆文本文件(如ss1.txt、ss2.txt、ss3.txt等)? 我想将我的txt文件移动到一个尚未创建的新目录。我有一个字符串地址为我的所有文件,我想我可以把它们变成路径使用 是否将复制到新目录?