2016-10-21 4 views
2

으로 내 응용 프로그램을 사용 스프링 부팅을 작동하지.
도와주세요. 감사합니다. 코드 :봄 부팅 RestController는 좋은 작품, 롬복 롬복

@RestController 
@RequestMapping("/user") 
public class UserController { 

    @GetMapping("/{id}") 
    public User query(@PathVariable long id) { 
     if (id == 1L) { 
      return new User(1l); 
     } else { 
      return new User(2L); 
     } 
    } 

} 

@Data 
public class User { 
    private long userId; 
    private String userName; 
    private String password; 
    private String mobile; 
    private String address; 

    public User() { 
    } 
    public User(long userId){ 
     this(userId, "zhengfc", "pwd", "13322222222", "shanghai-zhengjiang"); 
    } 
    public User(long userId, String userName, String password, String mobile, String address) { 
     this.userId = userId; 
     this.userName = userName; 
     this.password = password; 
     this.mobile = mobile; 
     this.address = address; 
    } 

} 
+1

다음과 관련이있을 수 있습니다 : http://stackoverflow.com/a/37842512/475116 그럼'롬복 '이 잘 구성되어 있습니까? getter와 setter를 생성하지 않는 것 같습니다. – Pau

+0

개인적인 경험으로는 lombok Getters/Setters 주석이 완벽하게 작동하지만 데이터에 오류가 발생하는 경우가 있습니다. 속성 수준에서 Getter/Setter를 사용하는 것이 좋습니다 – cralfaro

+0

대답 해 주셔서 감사합니다. Intellij 아이디어로 인해 발생합니다. 롬복은 잘 구성되어 있지 않다. – user3172755

답변

0

나에게 개인적인 경험을 위해 시도해 보았습니다.

모델

``` 패키지 info.xiaomo.website.controller이다;

import lombok.Data; 

/** 
* 把今天最好的表现当作明天最新的起点..~ 
* いま 最高の表現 として 明日最新の始発..~ 
* Today the best performance as tomorrow newest starter! 
* Created by IntelliJ IDEA. 
* 
* @author: xiaomo 
* @github: https://github.com/qq83387856 
* @email: [email protected] 
* @QQ_NO: 83387856 
* @Date: 2016/11/8 10:29 
* @Description: 用户实体类 
* @Copyright(©) 2015 by xiaomo. 
**/ 

@Data 
public class Test { 
    private long userId; 
    private String userName; 
    private String password; 
    private String mobile; 
    private String address; 

    public Test() { 
    } 
    public Test(long userId){ 
     this(userId, "zhengfc", "pwd", "13322222222", "shanghai-zhengjiang"); 
    } 
    public Test(long userId, String userName, String password, String mobile, String address) { 
     this.userId = userId; 
     this.userName = userName; 
     this.password = password; 
     this.mobile = mobile; 
     this.address = address; 
    } 

} 

은```

이 컨트롤러

```

package info.xiaomo.website.controller; 

import org.springframework.web.bind.annotation.GetMapping; 
import org.springframework.web.bind.annotation.PathVariable; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RestController; 

/** 
* 把今天最好的表现当作明天最新的起点..~ 
* いま 最高の表現 として 明日最新の始発..~ 
* Today the best performance as tomorrow newest starter! 
* Created by IntelliJ IDEA. 
* 
* @author: xiaomo 
* @github: https://github.com/qq83387856 
* @email: [email protected] 
* @QQ_NO: 83387856 
* @Date: 2016/11/8 10:29 
* @Description: 用户实体类 
* @Copyright(©) 2015 by xiaomo. 
**/ 

@RestController 
@RequestMapping("/test") 
public class TestController { 


    @GetMapping("/{id}") 
    public Test query(@PathVariable long id) { 
     if (id == 1L) { 
      return new Test(1l); 
     } else { 
      return new Test(2L); 
     } 

    } 
} 

```

내가 서버를 실행하고 http://localhost:8080/test/1

입니다

enter image description here

그래서 코드가 정확하다고 생각합니다. 여전히 오류가 발생하면 프로젝트 환경을 점검해야합니다.