@NamedNativeQueries({
@NamedNativeQuery(
name = "getNativeNutShellInfo", //需要调用的name
query = "{call cp_syslogin_web(?,?,?)}", //存储过程,返回的List字段对应的值@EntityResult此处填充实体的属性值
resultSetMapping = "ReturnColumnEntityList"
)
}) @SqlResultSetMappings({
@SqlResultSetMapping(
name = "ReturnColumnEntityList",
entities = {
@EntityResult(entityClass = NutShellInfo.class,fields={ //返回的List字段对应的值此处填充实体的属性值
@FieldResult(name = "aguid", column = "aguid"),
@FieldResult(name = "user", column = "htkusr"),
@FieldResult(name = "qty", column = "qtynow"),
@FieldResult(name = "registered", column = "breg"),
@FieldResult(name = "hint", column = "hint"),
@FieldResult(name = "ver", column = "ver"),
@FieldResult(name = "overQty", column = "boverqty"),
@FieldResult(name = "timeout", column = "btimeout"),
@FieldResult(name = "host", column = "htkwww")
}) } )
}) @Entity
public class NutShellInfo {
@Id
private String aguid;
@Column(name = "htkusr")
private String user;
@Column(name = "qtynow")
private double qty;
@Column(name = "breg")
private boolean registered;
private String hint;
private String ver;
@Column(name = "boverqty")
private boolean overQty;
@Column(name = "btimeout")
private boolean timeout;
@Column(name = "htkwww")
private String host;
@Transient
private String password;//这个字段不对数据库操作 public String getUser() {
return user;
} public void setUser(String user) {
this.user = user;
} public double getQty() {
return qty;
} public void setQty(double qty) {
this.qty = qty;
} public boolean isRegistered() {
return registered;
} public void setRegistered(boolean registered) {
this.registered = registered;
} public String getHint() {
return hint;
} public void setHint(String hint) {
this.hint = hint;
} public String getVer() {
return ver;
} public void setVer(String ver) {
this.ver = ver;
} public boolean isOverQty() {
return overQty;
} public void setOverQty(boolean overQty) {
this.overQty = overQty;
} public boolean isTimeout() {
return timeout;
} public void setTimeout(boolean timeout) {
this.timeout = timeout;
} public String getHost() {
return host;
} public void setHost(String host) {
this.host = host;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} =========================dao=========================
@Service
public class PubBaseDaoImpl<T> implements PubBaseDao<T> {
private EntityManager em = null; @PersistenceContext
public void setEm(EntityManager em) {
this.em = em;
} @Override
public List<T> qryNamedQuery(String nativeName,Object[] params) {
Query q = em.createNamedQuery(nativeName);
setQueryParams(q, params);
return q.getResultList();
} public void setQueryParams(Query query, Object[] params) {
try {
if (params != null && params.length > ) {
for (int i = ; i < params.length; i++) {
query.setParameter(i + , params[i]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} =================services===================================
@Override
public void qryInfo(String userId, String machineCode) {
List<NutShellInfo> list = baseDao.qryNamedQuery("getNativeNutShellInfo",new Object[] { userId, machineCode, }); } JPA 原生态SQL 的复杂查询之createNamedQuery,select * from查询,返回的List字段对应的填充实体
============实体类==========================
@NamedNativeQueries({
@NamedNativeQuery(
name = "getNativeNutShellInfo", //需要调用的name
query = "select * from NutShellInfo where aguid=? and htkusr=? and btimeout=? ", //存储过程,返回的List字段对应的值@EntityResult此处填充实体的属性值
resultSetMapping = "ReturnColumnEntityList"
)
}) @SqlResultSetMappings({
@SqlResultSetMapping(
name = "ReturnColumnEntityList",
entities = {
@EntityResult(entityClass = NutShellInfo.class,fields={ //返回的List字段对应的值此处填充实体的属性值
@FieldResult(name = "aguid", column = "id"),
@FieldResult(name = "user", column = "htkusr"),
@FieldResult(name = "qty", column = "qtynow"),
@FieldResult(name = "registered", column = "breg"),
@FieldResult(name = "hint", column = "hint"),
@FieldResult(name = "ver", column = "ver"),
@FieldResult(name = "overQty", column = "boverqty"),
@FieldResult(name = "timeout", column = "btimeout"),
@FieldResult(name = "host", column = "htkwww")
}) } )
}) @Entity
public class NutShellInfo {
@Id
private String aguid;
@Column(name = "htkusr")
private String user;
@Column(name = "qtynow")
private double qty;
@Column(name = "breg")
private boolean registered;
private String hint;
private String ver;
@Column(name = "boverqty")
private boolean overQty;
@Column(name = "btimeout")
private boolean timeout;
@Column(name = "htkwww")
private String host;
@Transient
private String password;//这个字段不对数据库操作 public String getUser() {
return user;
} public void setUser(String user) {
this.user = user;
} public double getQty() {
return qty;
} public void setQty(double qty) {
this.qty = qty;
} public boolean isRegistered() {
return registered;
} public void setRegistered(boolean registered) {
this.registered = registered;
} public String getHint() {
return hint;
} public void setHint(String hint) {
this.hint = hint;
} public String getVer() {
return ver;
} public void setVer(String ver) {
this.ver = ver;
} public boolean isOverQty() {
return overQty;
} public void setOverQty(boolean overQty) {
this.overQty = overQty;
} public boolean isTimeout() {
return timeout;
} public void setTimeout(boolean timeout) {
this.timeout = timeout;
} public String getHost() {
return host;
} public void setHost(String host) {
this.host = host;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} =========================dao=========================
@Service
public class PubBaseDaoImpl<T> implements PubBaseDao<T> {
private EntityManager em = null; @PersistenceContext
public void setEm(EntityManager em) {
this.em = em;
} @Override
public List<T> qryNamedQuery(String nativeName,Object[] params) {
Query q = em.createNamedQuery(nativeName);
setQueryParams(q, params);
return q.getResultList();
} public void setQueryParams(Query query, Object[] params) {
try {
if (params != null && params.length > ) {
for (int i = ; i < params.length; i++) {
query.setParameter(i + , params[i]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} =================services===================================
@Override
public void qryInfo(String userId, String machineCode) {
List<NutShellInfo> list = baseDao.qryNamedQuery("getNativeNutShellInfo",new Object[] { userId, machineCode, }); } JPA 原生态SQL 的复杂查询之createNamedQuery,select xxx,xxx from查询,返回的List字段对应的填充实体
============实体类==========================
@NamedNativeQueries({
@NamedNativeQuery(
name = "getNativeNutShellInfo", //需要调用的name
query = "select aguid,htkusr from NutShellInfo where aguid=? and htkusr=? and btimeout=? ", //存储过程,返回的List字段对应的值@EntityResult此处填充实体的属性值
resultSetMapping = "ReturnColumnEntityList"
)
}) @SqlResultSetMappings({
@SqlResultSetMapping(
name = "ReturnColumnEntityList",
entities = {}
columns = {
@ColumnResult(name = "aguid"),
@ColumnResult(name = "htkusr"),
}
)
}) @Entity
public class NutShellInfo {
@Id
private String aguid;
@Column(name = "htkusr")
private String user;
@Column(name = "qtynow")
private double qty;
@Column(name = "breg")
private boolean registered;
private String hint;
private String ver;
@Column(name = "boverqty")
private boolean overQty;
@Column(name = "btimeout")
private boolean timeout;
@Column(name = "htkwww")
private String host;
@Transient
private String password;//这个字段不对数据库操作 public String getUser() {
return user;
} public void setUser(String user) {
this.user = user;
} public double getQty() {
return qty;
} public void setQty(double qty) {
this.qty = qty;
} public boolean isRegistered() {
return registered;
} public void setRegistered(boolean registered) {
this.registered = registered;
} public String getHint() {
return hint;
} public void setHint(String hint) {
this.hint = hint;
} public String getVer() {
return ver;
} public void setVer(String ver) {
this.ver = ver;
} public boolean isOverQty() {
return overQty;
} public void setOverQty(boolean overQty) {
this.overQty = overQty;
} public boolean isTimeout() {
return timeout;
} public void setTimeout(boolean timeout) {
this.timeout = timeout;
} public String getHost() {
return host;
} public void setHost(String host) {
this.host = host;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} =========================dao=========================
@Service
public class PubBaseDaoImpl<T> implements PubBaseDao<T> {
private EntityManager em = null; @PersistenceContext
public void setEm(EntityManager em) {
this.em = em;
} @Override
public List<T> qryNamedQuery(String nativeName,Object[] params) {
Query q = em.createNamedQuery(nativeName);
setQueryParams(q, params);
return q.getResultList();
} public void setQueryParams(Query query, Object[] params) {
try {
if (params != null && params.length > ) {
for (int i = ; i < params.length; i++) {
query.setParameter(i + , params[i]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} =================services===================================
@Override
public void qryInfo(String userId, String machineCode) {
List<NutShellInfo> list = baseDao.qryNamedQuery("getNativeNutShellInfo",new Object[] { userId, machineCode, }); }

最新文章

  1. gerrit 为每个工程设置提交的reviewer
  2. Navicat 回复 psc 文件 Mysql
  3. HDU2546(01背包饭卡)
  4. Technical notes fornight
  5. Zabbix监控Linux磁盘I/O
  6. HTML、JS、CSS之特殊字符
  7. MIPI D-PHY 简写收集
  8. FZU 2104 (13.11.28)
  9. VB.NET中vbcr 是回车、vbcrlf 是回车和换行的结合、vblf 是换行
  10. BZOJ 3668: [Noi2014]起床困难综合症【贪心】
  11. remote: Permission to user_name/Code.git denied to other_user_name. fatal: unable to access &#39;https://github.com/user_name/Code.git/&#39;: The requested URL returned error: 403
  12. 解题(DirGraCheckPath--有向图的遍历(深度搜索))
  13. Python运维开发:运算符与数据类型(二)
  14. JAVA核心技术I---JAVA基础知识(列表List)
  15. struts2简单入门-参数传递的三种方式
  16. 一些mysql小技巧总结
  17. 剑值offer:最小的k个数
  18. jQuery的init都做了些什么
  19. 在visual studio中查看源代码
  20. Linux学习笔记:cat、tac、more、less、head、tail查看文件内容

热门文章

  1. SecureCRT 滚动条设置
  2. 【HTML5 1】39个让你受益的HTML5教程
  3. 【Shell脚本学习6】Shell变量:Shell变量的定义、删除变量、只读变量、变量类型
  4. leetcode 题解 Add Two Numbers(两个单链表求和)
  5. cat命令的作用
  6. Java克隆--深克隆与浅克隆的区别
  7. Scoket
  8. mina 字节数组编解码器的写法 I
  9. UIBootatrap:是由AngularJS UI团队编写的纯AngularJS实现的Bootstrap组件
  10. 怒刷DP之 HDU 1114