问题依旧The method obtainedPublicName(String) is undefined for the type UserInfMapper 。 --------------------------切割------------------- 我再详细下: 我用mybatis-generator生成了基本的dao \ mapping \ model 。 mapping中包含了xml dao是mapping对应的接口 model是数据。 我自己再写了一个service实现action数据,此时: 我在mapping中UserIngMapper.xml文件中的sql,然后在dao中UserInfMapper.java中写了对应的method, 然后再在service里面UserInfServiceImpl.java中注入UserInfMapper对象userInfMapper,再用userInfMapper调用其中的方法。具体信息如我提问。 然后就报错了The method obtainedPublicName(String) is undefined for the type UserInfMapper ...
<select id="obtainedPublicName" parameterType="String" resultType="zxw.model.UserInf"> select * from user where userName=#{userName} </select> 你确定 * 和 zxw.model.UserInf 里面的属性对应??你 select * from user where userName=#{userName} 这个先改查 select userName from user where userName=#{userName} 看看
是这样的: 我的maven工程里面,在src/main/java中写,故默认路径为src/main/java。 src/main/java下有一个zxw/model/UserInf.java,所以,我对应的是parameterType="zxw.model.UserInf", 我这个对应是没有问题的。另附1: <select id="obtainedPublicName" resultType="zxw.model.UserInf" parameterType="java.lang.String"> select * from userInf where user_name = #(userName,jdbcType=VARCHAR) </select> 另附2:
mapper中的配置有没有<mapper namespace="zxw.dao.userInfMapper"></mapper>这样把mapper中的方法文件和你userInfMapper接口中的方法对应起来就好了。 或者你协议个继承userInfMapper的java方法继承ibatisDao。public class UserInfMapperImpl extends IbatisBaseDao implements UserInfMapper{ @Override public UserInf obtainedPublicName(String userName);{ return this.getSqlSession().selectList("zxw.dao.userInfMapper.obtainedPublicName", userName); }
1、存在你说的东西 <mapper namespace="zxw.dao.UserInfMapper" > <!-- 自动生成的代码 --> <!-- |以下這些,都是我自己洗的 |@Author:weidu23 --> <!-- public int selectMaxId(); --> <select id="obtainedMaxId" resultType="java.lang.Integer"> select max(user_id) from userInf </select> <!-- public UserInf selectPublicName(String userName); --> <select id="obtainedPublicName" resultType="zxw.model.UserInf" > select * from userInf where user_name = #(userName,jdbcType=VARCHAR) </select> <!-- 以上這些都是@weidu23寫的 --> </mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2 ### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR) ### 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 2 ; bad SQL grammar []; nested exception is 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 2] with root 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 2 但是我自己不知道我的Mapper错在哪里,求赐教
参数设置 为题。 userName
1、存在你说的东西 <mapper namespace="zxw.dao.UserInfMapper" > <!-- 自动生成的代码 --> <!-- |以下這些,都是我自己洗的 |@Author:weidu23 --> <!-- public int selectMaxId(); --> <select id="obtainedMaxId" resultType="java.lang.Integer"> select max(user_id) from userInf </select> <!-- public UserInf selectPublicName(String userName); --> <select id="obtainedPublicName" resultType="zxw.model.UserInf" > select * from userInf where user_name = #(userName,jdbcType=VARCHAR) </select> <!-- 以上這些都是@weidu23寫的 --> </mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2 ### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR) ### 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 2 ; bad SQL grammar []; nested exception is 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 2] with root 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 2 但是我自己不知道我的Mapper错在哪里,求赐教现在报的是sql语句错误了,说明能识别了。你把语句改成这样试一试: select * from userInf where user_name = #{userName}看好,是大括号
1、存在你说的东西 <mapper namespace="zxw.dao.UserInfMapper" > <!-- 自动生成的代码 --> <!-- |以下這些,都是我自己洗的 |@Author:weidu23 --> <!-- public int selectMaxId(); --> <select id="obtainedMaxId" resultType="java.lang.Integer"> select max(user_id) from userInf </select> <!-- public UserInf selectPublicName(String userName); --> <select id="obtainedPublicName" resultType="zxw.model.UserInf" > select * from userInf where user_name = #(userName,jdbcType=VARCHAR) </select> <!-- 以上這些都是@weidu23寫的 --> </mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2 ### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR) ### 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 2 ; bad SQL grammar []; nested exception is 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 2] with root 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 2 但是我自己不知道我的Mapper错在哪里,求赐教现在报的是sql语句错误了,说明能识别了。你把语句改成这样试一试: select * from userInf where user_name = #{userName}看好,是大括号 我真不小心!!! 谢谢你,原来如此,问题解决,谢谢
1、存在你说的东西 <mapper namespace="zxw.dao.UserInfMapper" > <!-- 自动生成的代码 --> <!-- |以下這些,都是我自己洗的 |@Author:weidu23 --> <!-- public int selectMaxId(); --> <select id="obtainedMaxId" resultType="java.lang.Integer"> select max(user_id) from userInf </select> <!-- public UserInf selectPublicName(String userName); --> <select id="obtainedPublicName" resultType="zxw.model.UserInf" > select * from userInf where user_name = #(userName,jdbcType=VARCHAR) </select> <!-- 以上這些都是@weidu23寫的 --> </mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2 ### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR) ### 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 2 ; bad SQL grammar []; nested exception is 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 2] with root 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 2 但是我自己不知道我的Mapper错在哪里,求赐教现在报的是sql语句错误了,说明能识别了。你把语句改成这样试一试: select * from userInf where user_name = #{userName}看好,是大括号 我真不小心!!! 谢谢你,原来如此,问题解决,谢谢 嗯,以后多看看报错信息有帮助的。
where user_name = #(userName,jdbcType=VARCHER)
jdbcType=VARCHER写错了,应该是VARCHAR
我改过来了,可还是有问题2、我自己的判断是【.xml文件的定义,只会在编译时映射才用到,可是我的userInfServiceImpl.java调用UserInfMapper.java出错,说明是java问题】可是我找不到问题的所在,希望指点下
2、我自己的判断是【.xml文件的定义,只会在编译时映射才用到,可是我的userInfServiceImpl.java调用UserInfMapper.java出错,说明是java问题】但我实在无能为力,希望指点下
问题依旧The method obtainedPublicName(String) is undefined for the type UserInfMapper 。
--------------------------切割-------------------
我再详细下:
我用mybatis-generator生成了基本的dao \ mapping \ model 。
mapping中包含了xml
dao是mapping对应的接口
model是数据。
我自己再写了一个service实现action数据,此时:
我在mapping中UserIngMapper.xml文件中的sql,然后在dao中UserInfMapper.java中写了对应的method,
然后再在service里面UserInfServiceImpl.java中注入UserInfMapper对象userInfMapper,再用userInfMapper调用其中的方法。具体信息如我提问。
然后就报错了The method obtainedPublicName(String) is undefined for the type UserInfMapper ...
<select id="obtainedPublicName" parameterType="String" resultType="zxw.model.UserInf">
select * from user where userName=#{userName}
</select> 你确定 * 和 zxw.model.UserInf 里面的属性对应??你 select * from user where userName=#{userName} 这个先改查 select userName from user where userName=#{userName} 看看
我的maven工程里面,在src/main/java中写,故默认路径为src/main/java。
src/main/java下有一个zxw/model/UserInf.java,所以,我对应的是parameterType="zxw.model.UserInf",
我这个对应是没有问题的。另附1:
<select id="obtainedPublicName" resultType="zxw.model.UserInf" parameterType="java.lang.String">
select * from userInf
where user_name = #(userName,jdbcType=VARCHAR)
</select>
另附2:
private UserInfMapper userInfMapper;//spring autowired注入了UserInfMapper 的spring配置是什么?
<context:property-placeholder location="classpath:config.properties" />
<!-- 自动扫描(自动注入) -->
<context:component-scan base-package="zxw.service"></context:component-scan>spring整合mybatis的xml如下:
<!-- spring整合mybatis的xml如下: -->
<!-- myBatis文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations" value="classpath:zxw/mapping/*.xml"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="zxw.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
或者你协议个继承userInfMapper的java方法继承ibatisDao。public class UserInfMapperImpl extends IbatisBaseDao implements UserInfMapper{
@Override
public UserInf obtainedPublicName(String userName);{
return this.getSqlSession().selectList("zxw.dao.userInfMapper.obtainedPublicName", userName);
}
<mapper namespace="zxw.dao.UserInfMapper" >
<!-- 自动生成的代码 -->
<!--
|以下這些,都是我自己洗的
|@Author:weidu23
-->
<!-- public int selectMaxId(); -->
<select id="obtainedMaxId" resultType="java.lang.Integer">
select max(user_id) from userInf
</select>
<!-- public UserInf selectPublicName(String userName); -->
<select id="obtainedPublicName" resultType="zxw.model.UserInf" >
select * from userInf
where user_name = #(userName,jdbcType=VARCHAR)
</select>
<!-- 以上這些都是@weidu23寫的 -->
</mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2
### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR)
### 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 2
; bad SQL grammar []; nested exception is 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 2] with root 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 2
但是我自己不知道我的Mapper错在哪里,求赐教
<mapper namespace="zxw.dao.UserInfMapper" >
<!-- 自动生成的代码 -->
<!--
|以下這些,都是我自己洗的
|@Author:weidu23
-->
<!-- public int selectMaxId(); -->
<select id="obtainedMaxId" resultType="java.lang.Integer">
select max(user_id) from userInf
</select>
<!-- public UserInf selectPublicName(String userName); -->
<select id="obtainedPublicName" resultType="zxw.model.UserInf" >
select * from userInf
where user_name = #(userName,jdbcType=VARCHAR)
</select>
<!-- 以上這些都是@weidu23寫的 -->
</mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2
### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR)
### 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 2
; bad SQL grammar []; nested exception is 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 2] with root 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 2
但是我自己不知道我的Mapper错在哪里,求赐教现在报的是sql语句错误了,说明能识别了。你把语句改成这样试一试: select * from userInf
where user_name = #{userName}看好,是大括号
<mapper namespace="zxw.dao.UserInfMapper" >
<!-- 自动生成的代码 -->
<!--
|以下這些,都是我自己洗的
|@Author:weidu23
-->
<!-- public int selectMaxId(); -->
<select id="obtainedMaxId" resultType="java.lang.Integer">
select max(user_id) from userInf
</select>
<!-- public UserInf selectPublicName(String userName); -->
<select id="obtainedPublicName" resultType="zxw.model.UserInf" >
select * from userInf
where user_name = #(userName,jdbcType=VARCHAR)
</select>
<!-- 以上這些都是@weidu23寫的 -->
</mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2
### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR)
### 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 2
; bad SQL grammar []; nested exception is 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 2] with root 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 2
但是我自己不知道我的Mapper错在哪里,求赐教现在报的是sql语句错误了,说明能识别了。你把语句改成这样试一试: select * from userInf
where user_name = #{userName}看好,是大括号
我真不小心!!!
谢谢你,原来如此,问题解决,谢谢
<mapper namespace="zxw.dao.UserInfMapper" >
<!-- 自动生成的代码 -->
<!--
|以下這些,都是我自己洗的
|@Author:weidu23
-->
<!-- public int selectMaxId(); -->
<select id="obtainedMaxId" resultType="java.lang.Integer">
select max(user_id) from userInf
</select>
<!-- public UserInf selectPublicName(String userName); -->
<select id="obtainedPublicName" resultType="zxw.model.UserInf" >
select * from userInf
where user_name = #(userName,jdbcType=VARCHAR)
</select>
<!-- 以上這些都是@weidu23寫的 -->
</mapper>2、我清理了下缓存问题,发现,原来的问题没了,出了新问题,如下:严重: Servlet.service() for servlet [springMvc] in context with path [/DemoThree] threw exception [Request processing failed; nested exception is 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 2
### The error may exist in file [D:\apache-tomcat-7.0.50\webapps\DemoThree\WEB-INF\classes\zxw\mapping\UserInfMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select * from userInf where user_name = #(userName,jdbcType=VARCHAR)
### 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 2
; bad SQL grammar []; nested exception is 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 2] with root 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 2
但是我自己不知道我的Mapper错在哪里,求赐教现在报的是sql语句错误了,说明能识别了。你把语句改成这样试一试: select * from userInf
where user_name = #{userName}看好,是大括号
我真不小心!!!
谢谢你,原来如此,问题解决,谢谢
嗯,以后多看看报错信息有帮助的。