首页 新闻 会员 周边 捐助

Mybatis不能解析sql语句的占位符

0
[已关闭问题] 关闭于 2016-08-09 09:25

xml文件配置如下,sql语句放在数据库界面端可以完美运行,

并且如果在配置语句里,把占位符替换为

WHERE bd.building_name='实际数据'

把占位符换成#{}也没有用

程序便能执行成功,第一次用Mybatis和Mysql,实在不明白,求解答

 

<select id="getBuildingByBuildingName" parameterType="String" resultType="buildingInfo" statementType="STATEMENT">
           SELECT
           bd.building_name AS buildingName,
           bd.building_addr AS buildingAddr,
           bd.completion_date AS completionDate,
           bd.building_storey AS buildingStorey,
           bd.building_function AS buildingFunction,
           bd.gross_floor_area AS grossFloorArea,
           bd.heating_area AS heatingArea,
           bd.aircon_form AS airconForm,
           bd.structure_form AS structureForm,
           bd.outer_wallform AS outerWallForm,
           bd.outer_window_form AS outerWindowForm,
           bd.glass_type AS glassType,
           bd.building_type AS buildingType,
           bd.aircon_area AS airconArea,
           bd.heating_form AS heatingForm,
           bd.outer_wallheat AS outerWallHeat,
           bd.frame_material AS frameMaterial
           FROM BUILDING_INFO bd
           WHERE bd.building_name=#{building}
       </select>

Dao层

    /**
     * 根据主键 建筑名 获取该建筑对象
     * @param building_name String-建筑名
     * @return BuildingInfoDataBean:建筑对象<br/>null:没有查询到
     */
    public BuildingInfoDataBean getBuildingByBuildingName(String building);

异常

Error querying database.  Cause: 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 '?' at line 20
### The error may exist in com/xayr/salary/mapper/BuildingInfoMapper.xml
### The error may involve com.xayr.salary.dao.BuildingInfoDao.getBuildingByBuildingName
### The error occurred while executing a query
### SQL: SELECT       bd.building_name AS buildingName,      bd.building_addr AS buildingAddr,      bd.completion_date AS completionDate,      bd.building_storey AS buildingStorey,      bd.building_function AS buildingFunction,      bd.gross_floor_area AS grossFloorArea,      bd.heating_area AS heatingArea,      bd.aircon_form AS airconForm,      bd.structure_form AS structureForm,      bd.outer_wallform AS outerWallForm,      bd.outer_window_form AS outerWindowForm,      bd.glass_type AS glassType,      bd.building_type AS buildingType,      bd.aircon_area AS airconArea,      bd.heating_form AS heatingForm,      bd.outer_wallheat AS outerWallHeat,      bd.frame_material AS frameMaterial      FROM BUILDING_INFO bd      WHERE bd.building_name=?
### Cause: 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 '?' at line 20
]
[2016/08/06 14:08:21,548] [DEBUG] [com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor:84] - Error calling method through OGNL: object: [com.xayr.salary.action.BuildingInfoAction@45d5de28] method: [execute] args: [[]]
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database.  Cause: 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 '?' at line 20
### The error may exist in com/xayr/salary/mapper/BuildingInfoMapper.xml

自私的程序员的主页 自私的程序员 | 初学一级 | 园豆:16
提问于:2016-08-06 14:09
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册