直接上码!
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来明确地指定字段/别名 ...
returning-DOM-elements-javascript-源码.rar
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. ...
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. ...
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. ...
本例可以实现对手机摄像头采集的视频数据硬编码成h.264格式,可以在vlc和EsEye分析工具正常查看。只有视频,没有音频。
返回-DOM-元素-javascript
注意:此处 this 指代的是 DOM 对象而非 jQuery 对象。 HTML 代码: <img/><img/> jQuery 代码: $("img").each(function(i){ this.src = "test" + i + ".jpg"; }); 结果: [ , <img src="test1.jpg" /> ] ---...
4.2 Functions Returning Non-integers 61 4.3 External Variables 63 4.4 Scope Rules 68 4.5 Header Files 69 4.6 Static Variables 70 4.7 Register Variables 71 4.8 Block Structure 71 4.9 Initialization 72 ...
在本文中,我们介绍了Spring Boot AOP中的@AfterReturning注解,它用于定义在目标方法成功返回后执行的切面逻辑。我们通过一个图书管理系统的实例演示了@AfterReturning的使用方式,并在成功查询图书时记录了查询的...
在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],笔者...
RSP-28616 [BadCG] Operator Assign should not allow non-default calling conventions RSP-28615 [BadCG] In the absence of Initialize, finalisation is not guaranteed for local variables RSP-28552 Poor ...
Functions Returning Non-integers External Variables Scope Rules Header Files Static Variables Register Variables Block Structure Initialization Recursion The C Preprocessor File Inclusion ...