用户模型
@Entity
@Table(name = "user",uniqueConstraints = {@UniqueConstraint(columnNames = {"email"}) })
public class User implements Serializable{
/**
*
*/
private static final long serialVersionUID = 382892255440680084L;
private int id;
private String email;
private String userName;
private Set<Role> roles = new HashSet<Role>();
public User() {}
}
Run Code Online (Sandbox Code Playgroud)
我对应的用户仓库:
package hello.repository;
import org.springframework.data.repository.CrudRepository;
import hello.model.User;
public interface UserRepository extends CrudRepository<User,Long> {
}
Run Code Online (Sandbox Code Playgroud)
在控制器中我做:
@GetMapping(path="/all")
public @ResponseBody Iterable<User> getAllUsers() {
// This returns a JSON or XML with the users
return userRepository.findAll();
}
Run Code Online (Sandbox Code Playgroud)
我发现这会检索整个用户表。但这不是我想要的。我的要求只是用户表中的电子邮件列。
如何仅从用户表中检索电子邮件?---> …