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();
        }

收藏 打印