zoukankan      html  css  js  c++  java
  • mp实现过程

    步骤:

      1,编写配置文件

    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8
    spring.datasource.username=root
    spring.datasource.password=root

      2,编写entity类

    @Data
    public class User {
        @TableId(type = IdType.ID_WORKER)
        private Long id;
        private String name;
        private Integer age;
        private String email;
        private Date createTime;
        private Date updateTime;
    }

      3,编写mapper类

    @Repository
    public interface UserMapper extends BaseMapper<User> {
      // 需要继承BaseMapper<T> }

      4,再启动类上添加注解:扫描mapper

    @SpringBootApplication
    @MapperScan("com.nbg.mpdemo1010.mapper")
    public class Mpdemo1010Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Mpdemo1010Application.class, args);
        }
    
    }

      5,测试

    @SpringBootTest
    class Mpdemo1010ApplicationTests {
        @Autowired
        private UserMapper userMapper;
    
        @Test
        void contextLoads() {
            for (User user : userMapper.selectList(null)) {
                System.out.println(user);
            }
        }
    
        @Test
        void update(){
            com.nbg.mpdemo1010.entity.User user1 = new com.nbg.mpdemo1010.entity.User();
            User user = new User();
            user.setId(2L);
            user.setAge(111);
            int i = userMapper.updateById(user);
            System.out.println(i);
        }
    }

      

  • 相关阅读:
    设计模式
    雨夹雪背景特效
    lottie-前端实现AE动效
    响应式布局实现原理
    关于小程序(含uniapp)中使用npm模块
    使用脚手架快速搭建React项目
    vue项目接入友盟统计站点数据
    git常用命令
    uniapp请求方法的封装
    小程序获取用户登录及手机号登录
  • 原文地址:https://www.cnblogs.com/NBG-SDL/p/14567411.html
Copyright © 2011-2022 走看看