背景
由于本人没有参与过传统的spring 方式搭建,直接上手的springboot。所以有很多spring方面知识没有很懂。直接网上的教程和spring官方手册一点一点的搭建的,开始使用的eclipse搭建。现在开始Intellji。希望这篇文章可以让小伙伴们少走些弯路。
springmvc 常用注解
@Requestmapping 定义url
@RequestResponse 将return 的java对象转成json对象
@Controller
@Service
问题1. mybatis bindingException
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 报这个错误。
解决方式
直接在mapper类里使用注释annotation 比如@Select 注释定义成员方法执行的sql语句。这里就算是找不到xml文件,依然可以执行正确
@Select("select * from myTable")
List<User> findAllUser();
我发现了不少项目都是因为没有在在pom.xml 下面指定xml查找路径导致的,需要在pom.xml build 标签下面配置resource。如果你的文件在resource路径下,需要在build里面配置src/main/resources
<build>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>