1、错误描述
sql.append("select cdp.id id,cdp.distributionMapLegend distributionMapLegend,cdp.siteMarker siteMarker, ");
sql.append("hd.type horizontalAxisUnit,cdp.mapPop mapPop,cdp.searchStrip searchStrip,cdp.isRainsProcessNum isRainsProcessNum, ");
sql.append("ld.type legendType,p.productName productName,pd.type productType,cdp.requestPath requestPath,cdp.pictureRequestPath pictureRequestPath, " +
"asd.type isAreaChoice, ssd.type siteType from climate_disaster_product cdp ");
sql.append("left join product p on p.productId = cdp.id " +
"left join sys_dict hd on hd.id = cdp.horizontalAxisUnit " +
"left join sys_dict ld on ld.id = cdp.legendType " +
"left join sys_dict asd on asd.id = cdp.isAreaChoice " +
"left join sys_dict asd on ssd.id = cdp.siteType " +
"left join sys_dict pd on pd.id = p.productType ");
sql.append("where cdp.isDelete = '0' and cdp.publishFlag = '1' and cdp.id=?");
2、错误原因
在拼接SQL语句时,给sys_dict 取别名时,都取asd
导致数据库表别名重复
3、解决办法
将两个表的别名改为不一样的,如ssd
4、解决问题
sql.append("select cdp.id id,cdp.distributionMapLegend distributionMapLegend,cdp.siteMarker siteMarker, "); sql.append("hd.type horizontalAxisUnit,cdp.mapPop mapPop,cdp.searchStrip searchStrip,cdp.isRainsProcessNum isRainsProcessNum, "); sql.append("ld.type legendType,p.productName productName,pd.type productType,cdp.requestPath requestPath,cdp.pictureRequestPath pictureRequestPath, " + "asd.type isAreaChoice, ssd.type siteType from climate_disaster_product cdp "); sql.append("left join product p on p.productId = cdp.id " + "left join sys_dict hd on hd.id = cdp.horizontalAxisUnit " + "left join sys_dict ld on ld.id = cdp.legendType " + "left join sys_dict asd on asd.id = cdp.isAreaChoice " + "left join sys_dict ssd on ssd.id = cdp.siteType " + "left join sys_dict pd on pd.id = p.productType "); sql.append("where cdp.isDelete = '0' and cdp.publishFlag = '1' and cdp.id=?");