发表于: 2016-10-31 20:52:15

4 2073


根据任务二的要求,基于maven用myBatis跟spring写了个最简单的查询的功能,但是全程都在提示Invalid bound statement (not found)

然后检查mapper映射文件,纠结了两天了,都没有弄好,不知道哪里弄错了,好惨啊我真的是个菜鸡

下面是打包的war文件百度盘链接,有好心同门帮忙看看吗

http://pan.baidu.com/s/1dE8ShuL(我试着用mvn package命令打包的,不知道对不对


错误提示

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
SLF4J: This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version
Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): me.dao.StudentDao.findByID
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:184)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:38)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)
    at com.sun.proxy.$Proxy12.findByID(Unknown Source)
    at me.service.impl.StudentServiceImpl.findByID(StudentServiceImpl.java:18)
    at me.service.impl.test.main(test.java:13)


为了解决这个问题,我以为是注解或者哪里错了,又重新看了一遍这方面的知识,做个总结吧,虽然并没看出设么问题

注入:

set注入:

<bean>中加入<property name="" value="">元素

注入时引用其他对象的内容<property name="" value="#{objectID.nameorkey}"></property>,这里要求object有一个public的get方法

注入时引入list的内容<property name="" value="#{somelist[i]}"></property>

注入对象,<bean>中加入<property name="" ref="对象名">元素

构造器注入:

<bean>中加入<constructor-arg index="0" value="">元素


自动注入:

<bean>元素中加入autowire=""

autowire="byType",autowire="byName",autowire="constructor"(根据类型的,但是用于构造器)


list信息注入<list><value></value></list>

list对象注入<list><ref  bean=""/></list>

set信息注入<set><value></value></set>
map信息注入<map><entry key="" value=""></entry></map>

Properties信息注入<props><prop key="">value</prop></props>

spring表达式注入:#{id名.属性}取属性值,#{id名.key}取key对应的value值,


注解:在类定义,方法定义,成员变量定义前面使用,格式为@注解标记名

注解类型:@Controller//控制层组件;@Service//业务层组件xxxService;@Repository//数据访问层组件xxxDao;@Component//其他组件

注解属性:@Scope默认单例,@Scope("prototype")非单例;@PostConstruct指定init-method,@PreDestroy指定destroy-method,用在方法前


开启组件扫描:<context:component-scan base-package=“ ”/>写在<beans>前


注入注解:@Resource @Autowired:可以在变量定义前或setXX方法前应用

如果存在多个匹配类型,建议按名称注入 @Resource(name="指定名称")或@Autowired @Qualifier("指定名称")


返回列表 返回列表
评论

    分享到