打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
SpringBoot整合Mybatis实操和打印SQL语句
springBoot2.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 Object findAll(){
           return JsonData.buildSuccess(userMapper.getAll());
        }
        
        @GetMapping("find_by_Id")
        public Object findById(long id){
           return JsonData.buildSuccess(userMapper.findById(id));
        }
        
        @GetMapping("del_by_id")
        public Object delById(long id){
        userMapper.delete(id);
           return JsonData.buildSuccess();
        }
        
        @GetMapping("update")
        public Object update(String name,int id){
            User user = new User();
            user.setName(name);
            user.setId(id);
            userMapper.update(user);
            return JsonData.buildSuccess();
        }

原文地址:http://www.manongjc.com/article/27088.html

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
SpringBoot持久化层操作支持(一)SQL篇
使用MyBatis时,无法绑定抽象方法与配置SQL语句的异常解决方法
Mybatis源码解析之六剑客
Mybatis 开启控制台打印sql语句
Spring Boot (七): Mybatis极简配置
myBatis 使用Select top 动态参数出现“′@P0′ 附近有语法错误”的解决
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服