- 点击run-Edit Configurations


注意!!!同一张表一定不要运行多次,因为mapper的映射文件中会生成多次的代码,导致报错,切记

最后生成的文件以及结构:

9. 生成的文件
UserMapper.java
List }
User.java
.userId =
.userName = userName == ?
.password = password == ?
.phone = phone == ? }
对于sql语句这种黄色的背景,真心是看不下去了(解决方案):

**UserMapper.xml **
where user_id = #{userId,jdbcType=
values (#{userId,jdbcType=INTEGER},#{userName,jdbcType=VARCHAR},#{password,jdbcType= #{phone,jdbcType=
< test="userId != null" >
>
< test="userName != null" >
>
< test="password != null" >
>
< test="phone != null" >
>
< test="userId != null" >
#{userId,jdbcType= >
< test="userName != null" >
#{userName, >
< test="password != null" >
#{password, >
< test="phone != null" >
#{phone, >
< test="userName != null" >
user_name = #{userName, >
< test="password != null" >
password = #{password, >
< test="phone != null" >
phone = #{phone, >
where user_id = #{userId,jdbcType=
set user_name = #{userName, password = #{password, phone = #{phone,jdbcType= where user_id = #{userId,jdbcType=
10. 打开类SpringbootMybatisDemoApplication.java,这个是springboot的启动类。我们需要添加点东西:
@MapperScan("com.winter.mapper")
SpringApplication.run(SpringbootMybatisDemoApplication. }
注意:@MapperScan("com.winter.mapper")
这个注解非常的关键,这个对应了项目中mapper(dao)所对应的包路径,很多同学就是这里忘了加导致异常的
11. 到这里所有的搭建工作都完成了,接下来就是测试的工作,没使用junit4进行测试:
首先看一下完成之后的文件的结构:

现在controller,service层的代码都写好:
UserController.java
@RequestMapping(value = "/user"
@RequestMapping(value = "/add",produces = {"application/json;charset=UTF-8"
@RequestMapping(value = "/all/{pageNum}/{pageSize}",produces = {"application/json;charset=UTF-8" Object findAllUser(@PathVariable("pageNum") pageNum,@PathVariable("pageSize")
}
UserService.java
List findAllUser( pageNum, }
UserServiceImpl.java
@Service(value = "userService" UserServiceImpl
UserMapper userMapper;
List findAllUser( pageNum,
}
如果强迫症看不下去那个报错:(解决方法)

测试我使用了idea一个很用心的功能。
可以发http请求的插件:


点击左侧的运行按钮就可以发送请求了;
如果返回值正确 说明你已经搭建成功了!!
ps:如果出现mapper注入不了的情况,请检查版本,当前博客的搭建方法只适合1.5.*版本的。
</div>
</div>
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!