pringBoot2.x整合Mybatis3.x增删改查实操, 控制台打印sql语句
1、控制台打印sql语句
#增加打印sql语句,一般用于本地开发测试
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
2、增加mapper代码
@Select(\"SELECT * FROM user\")
@Results({
@Result(column = \"create_time\",property = \"createTime\") //javaType = java.util.Date.class
})
List<User> getAll();
@Select(\"SELECT * FROM user WHERE id = #{id}\")
@Results({
@Result(column = \"create_time\",property = \"createTime\")
})
User findById(Long id);
@Update(\"UPDATE user SET name=#{name} WHERE id =#{id}\")
void update(User user);
@Delete(\"DELETE FROM user WHERE id =#{userId}\")
void delete(Long userId);
3、增加API
@GetMapping(\"find_all\")
public findAll(){
return JsonData.buildSuccess(userMapper.getAll());
}
@GetMapping(\"find_by_Id\")
public findById(long id){
return JsonData.buildSuccess(userMapper.findById(id));
}
@GetMapping(\"del_by_id\")
public delById(long id){
userMapper.delete(id);
return JsonData.buildSuccess();
}
@GetMapping(\"update\")
public update(String name,int id){
User user = new User();
user.setName(name);
user.setId(id);
userMapper.update(user);
return JsonData.buildSuccess();
}
继续阅读与本文标签相同的文章
-
印度5G建设即将开始,是屈服于美国的施压,还是选择跟华为合作?
2026-05-18栏目: 教程
-
系列文章:云原生Kubernetes日志落地方案
2026-05-18栏目: 教程
-
QQ浏览器正孵化“用户增长团队”,解读中国浏览器行业发展趋势
2026-05-18栏目: 教程
-
Java并发系列(4)java关键字-synchronized
2026-05-18栏目: 教程
-
汇编(六)栈段、第一个汇编程序
2026-05-18栏目: 教程
