1、自定义对象
package com.spring.first.res; public class NodeForOther { private Long id; private String name; public NodeForOther(Long id, String name) { this.id = id; this.name = name; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
2、dao层sql,这里要用HQL,这里只查了node表的id、name字段
@Query(value = "select new com.spring.first.res.NodeForOther(n.id,n.name) from Node n where n.name like %?1%") @Modifying public List<NodeForOther> findByNameLike2(String name);