import com.fasterxml.jackson.annotation.JsonView;
/**
* @author yunfeng.lu
* @create 2017/11/5.
*/
public class User {
public interface PrintUser{}
public interface PrintUserDetail extends PrintUser{}
private String name;
private String password;
@JsonView(PrintUser.class)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@JsonView(PrintUserDetail.class)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
@RestController
@RequestMapping("/user")
public class UserController {
// 只會(huì)去打印 name 如下圖所示
@GetMapping("/query")
@JsonView(User.PrintUser.class)
public List<User> query(){
List<User> list=new ArrayList<>();
list.add(new User());
list.add(new User());
list.add(new User());
return list;
}
// name 和 password 都會(huì)打印
@GetMapping("/get/info/{id:\\d+}")
@JsonView(User.PrintUserDetail.class)
public User getUserInfo(){
User user=new User();
user.setName("lucode");
return user;
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者