直接上码!
public class OrderDao extends BaseDao<String, Orders> implements IOrderDao {
@SuppressWarnings("unchecked")
public List<OrderDTO> getOrdersByUsername(String username) {
String sql = "SELECT"
+ " BILLADDR1 as {billaddr1},"
+ "BILLADDR2 as {billaddr2},"
+ "BILLCITY as {billCity},"
+ "BILLCOUNTRY as {billCountry},"
+ "BILLSTATE as {billState},"
+ "BILLTOFIRSTNAME as {billToFirstName},"
+ "BILLTOLASTNAME as {billToLastName},"
+ "BILLZIP as {billZip},"
+ "SHIPADDR1 as {shipaddr1},"
+ "SHIPADDR2 as {shipaddr2},"
+ "SHIPCITY as {shipCity},"
+ "SHIPCOUNTRY as {shipCountry},"
+ "SHIPSTATE as {shipState},"
+ "SHIPTOFIRSTNAME as {shipToFirstName},"
+ "SHIPTOLASTNAME as {shipToLastName},"
+ "SHIPZIP as {shipZip},"
+ "CARDTYPE as {cardType},"
+ "COURIER as {courier},"
+ "CREDITCARD as {creditCard},"
+ "EXPRDATE as {exprdate},"
+ "LOCALE as {locale},"
+ "ORDERDATE as {orderDate},"
+ "ORDERS.ORDERID as {orderId},"
+ "TOTALPRICE as {totalPrice},"
+ "USERID as {userid},"
+ "STATUS as {status}"
+ " FROM ORDERS ,ORDERSTATUS"
+ " WHERE ORDERS.USERID = ?"
+ " AND ORDERS.ORDERID = ORDERSTATUS.ORDERID"
+ " ORDER BY ORDERDATE";
Query query = this.getSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(OrderDTO.class));
query.setString(0, username);
return query.list();
}
上面是ssh集成,hibernate查询。
返回非受管实体,结果转换器返回OrderDTO的列表。
以下是OrderDTO类:
public class OrderDTO implements Serializable {
private static final long serialVersionUID = 6321792448424424931L;
private int orderId;
// private String username;
private String userid;
private Date orderDate;
// private String shipAddress1;
// private String shipAddress2;
private String shipaddr1;
private String shipaddr2;
private String shipCity;
private String shipState;
private String shipZip;
private String shipCountry;
// private String billAddress1;
// private String billAddress2;
private String billaddr1;
private String billaddr2;
private String billCity;
private String billState;
private String billZip;
private String billCountry;
private String courier;
private BigDecimal totalPrice;
private String billToFirstName;
private String billToLastName;
private String shipToFirstName;
private String shipToLastName;
private String creditCard;
// private String expiryDate;
private String exprdate;
private String cardType;
private String locale;
private String status;
private List<LineItemDTO> lineItems = new ArrayList<LineItemDTO>();
get,set方法省略。
执行上面的查询,有语法错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near 'BILLADDR2 as ,BILLCITY as ,BILLCOUNTRY as ,BILLSTATE as ,BILLTOFIRSTNAME as ,BIL' at line 1
应该是不能取别名。
如果不用别名注射(alias injection names)
,OrderDTO中属性不能使用驼峰命名,属性必须全部小写才能正确返回。
求教育!求爽!
分享到:
相关推荐
16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 16.2.1. 使用return-property来明确地指定字段/别名 ...
16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 16.2.1. 使用return-property来明确地指定字段/别名 ...
16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 16.2.1. 使用return-property来明确地指定字段/别名 ...
16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 16.2.1. 使用return-property来明确地指定字段/别名 ...
python库。 资源全名:django_pg_returning-1.0.0-py2.py3-none-any.whl
16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 16.2.1. 使用return-property来明确地指定字段/别名 ...
16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 16.2.1. 使用return-property来明确地指定字段/别名 16.2.2. ...
标题 "returning-DOM-elements-javascript-源码.rar" 暗示了这是一个关于使用JavaScript操作和检索DOM元素的源代码集合。DOM(Document Object Model)是HTML和XML文档的结构化表示,允许通过编程方式访问和修改文档...
14.1.5. 返回非受管实体(Returning non-managed entities) 14.1.6. 处理继承(Handling inheritance) 14.1.7. 参数(Parameters) 14.2. 命名SQL查询 14.2.1. 使用return-property来明确地指定字段/别名 14.2.2. ...
16.1.5. 返回非受管实体(Returning non-managed entities) 16.1.6. 处理继承(Handling inheritance) 16.1.7. 参数(Parameters) 16.2. 命名SQL查询 16.2.1. 使用return-property来明确地指定字段/别名 16.2.2. ...
- 如何定义和使用Aspect,以及通知类型(Before、After、Around、After-Throwing、After Returning)? 5. **Spring MVC**: - Spring MVC的架构组件及其职责是什么? - DispatcherServlet、Controller、...
14.1.5. 返回非受管实体(Returning non-managed entities) 14.1.6. 处理继承(Handling inheritance) 14.1.7. 参数(Parameters) 14.2. 命名SQL查询 14.2.1. 使用return-property来明确地指定字段/别名 14.2.2. ...
【hibernate-aop】是将面向切面编程(Aspect Oriented Programming,AOP)的概念应用于Hibernate框架的一个项目。在Java开发中,Hibernate是一个强大的对象关系映射(Object-Relational Mapping,ORM)工具,它使得...
`returning-DOM-elements-javascript`这个主题主要聚焦于如何在JavaScript中获取和操作DOM元素。下面将详细讨论相关知识点。 1. **选择DOM元素** - `getElementById()`: 这是JavaScript中最基本的选择方法,通过...
这表明在 findBookById 方法成功执行并返回 Book 实例之后,logBookQuery 方法按预期记录了查询时间和返回的图书信息。 总结与最佳实践 1. **明确横切关注点**:在使用@AfterReturning 之前,确保你已经识别出了...
不可变对象一旦创建就不能被修改,因此不会引起上述问题。 3. **提供安全的访问方法**:为外部代码提供修改内部表示的安全接口,如`setContent()`方法,确保所有的修改都在控制之下。 4. **使用`Collections....
注意:此处 this 指代的是 DOM 对象而非 jQuery 对象。 HTML 代码: <img/><img/> jQuery 代码: $("img").each(function(i){ this.src = "test" + i + ".jpg"; }); 结果: [ , <img src="test1.jpg" /> ] ---...
本项目以"权限控制(struts2+hibernate+spring+struts-menu+valuelist)"为主题,采用一系列成熟的技术栈来实现这一目标。下面我们将深入探讨这些技术及其在项目中的应用。 首先,Struts2作为MVC框架,负责处理HTTP...
在arduino ide实现单片机读取mysql数据库数据时报错libraries\MySQL_Connector_Arduino\src\MySQL_Encrypt_Sha1.cpp:95:1: error: no return statement in function returning non-void [-Werror=return-type],笔者...