hibernte(hibernateTemplate)组合查询
HSL语句:
String queryString="select new com.dio.blog.dto.UserDto(fu.id,fu.username,fu.password) from FriendUser fu where fu.username=?";
选择出的字段保存在UserDto对象里面,UserDto类必须包含该所有字段的构造方法
UserDto代码如下:
package com.dio.blog.dto;/** * 用户登录数据传输对象 * @author Administrator * */public class UserDto {private String id;private String username;private String password;/** * 引用数据传输对象,必须有构造方法 * @param id * @param username * @param password */public UserDto(String id, String username, String password) {super();this.id = id;this.username = username;this.password = password;}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}