gpt4 book ai didi

spring - mybatis spring mvc 应用,得到 Invalid bound statement (not found)

转载 作者:IT老高 更新时间:2023-10-28 13:51:45 27 4
gpt4 key购买 nike

这是我第一个使用spring 3.2.4的mybatis spring mvc应用,mybatis-spring-1.2.1

当我尝试调用我的网络服务时,我得到了错误::

org.springframework.web.util.NestedServletException: Request processing failed; 
nested exception is org.apache.ibatis.binding.BindingException: Invalid bound
statement (not found):
org.mydomain.formulary.drugmaster.dao.DrugMasterDao.getDrugsWithAlert

我一定遗漏了一些明显的东西。感谢您的帮助

这是我的关联文件:applicationContext.xml

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="formularyDb" />
<property name="configLocation" value="file:/web/sites/drugformulary-spring/config/mybatis-config.xml" />
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.mydomain.formulary.mappers" />
</bean>
<bean id="DrugMasterDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="org.mydomain.formulary.drugmaster.dao.DrugMasterDao" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

映射器文件 -->/classes/org/mydomain/formulary/mappers/drugmasterDao.xml

<mapper namespace="org.mydomain.formulary.drugmaster.dao.DrugMasterDao">

<select id="getDrugsWithAlert" parameterType="int" resultType="org.mydomain.formulary.drug_master.model.DrugMasters">
Select drug_id,drug_name,drug_alert_date,drug_alert_source, rownum
from (select drug_id,drug_name,to_char(drug_alert_datetime,'MM/DD/YYYY') as drug_alert_date ,drug_alert_source, rownum
from drug_master
where drug_status ='A' and length(drug_alert) > 0
order by drug_alert_datetime DESC )
where
<if test="_parameter != null">
rownum &lt; #{count}
</if>
</select>
</mapper>

映射文件 -->/classes/org/mydomain/formulary/drugmaster/dao/DrugMasterDao.java

public interface DrugMasterDao {
public List<DrugMasters> getDrugsWithAlert(int count);
}

Controller 文件 -->/classes/org/mydomain/formulary/drugmaster/controller/DrugMasterController.java

@Controller
public class DrugMasterController {
@Autowired
DrugMasterService drugMasterService;


@RequestMapping(value = "/drugmaster/withalerts/count/{count}", method = RequestMethod.GET)
public String withAlerts(ModelMap model, @PathVariable int count) {

List<DrugMasters> drugs = drugMasterService.getDrugsWithAlert(count);

return null/*for now*/;

}
}

服务文件 -->/classes/org/mydomain/formulary/drugmaster/service/DrugMasterServiceImpl.java

@Service
public class DrugMasterServiceImpl implements DrugMasterService {

@Autowired
DrugMasterDao drugMasterDao;

public List<DrugMasters> getDrugsWithAlert(int count){
return drugMasterDao.getDrugsWithAlert(count);
}
}

mybatis-configfile -->

<configuration>
<settings>
<setting name="cacheEnabled" value="false" />
<setting name="lazyLoadingEnabled" value="false" />
</settings>
</configuration>

enter image description here

最佳答案

我在寻找我的错误时搜索了这个答案。它实际上与OP的问题无关,但异常(exception)是相同的,这个问题在谷歌中非常明显。

就我而言,我忘记更改映射器命名空间

<mapper namespace="pl.my.package.MyNewMapper">

这导致了同样的问题。

关于spring - mybatis spring mvc 应用,得到 Invalid bound statement (not found),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20427210/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com