spring boot 2.X mybites 实战 自动生成+分页+查询使用

pom



    4.0.0

    com.yousesky
    boot-game
    0.0.1-SNAPSHOT
    jar

    boot-game
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.5.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-aop
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            org.springframework.boot
            spring-boot-starter-validation
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        

        
            mysql
            mysql-connector-java
            runtime
        
        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.2.7
        

    

    
        game-admin
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
            
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.6
                
                    ${basedir}/src/main/resources/generator/generatorConfig.xml
                    true
                    true
                
            

        
    




mybites 生成代码配文件 generatorConfig.xml 路径(插件指定的位置)




    
    
    
        
            
            
            
        
        
        
        
        
            
        
        
        
            
            
        
        
        
            
        
        
        
        
            
        
        
        

运行插件

我是点击idea maven按钮的

添加配置 application.yml

server:
  port: 8080
spring:
  datasource:
    url: jdbc:mysql://192.168.1.12/jpa?characterEncoding=utf-8
    username: root
    password: pass
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    #不加这句则默认为myisam引擎
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect

实战查询

单元测试,好习惯

/**
 * @Description:
 * @Author: rongyu
 * @CreateDate: 2018/10/10$ 14:37$
 * @Remark:
 */
@Slf4j
public class Test01 extends BootGameApplicationTests {
    @Resource
    private UsersGameBetDetailService usersGameBetDetailService;

    @Test
    public void test(){
        UsersGameBetDetailExample usersGameBetDetailExample = new UsersGameBetDetailExample();
        PageParameter pageParameter = new PageParameter();
        pageParameter.setPageNum(0);
        pageParameter.setPageSize(10);
        String date = "2018-09-20 18:51:55";
        Instant instant = Instant.ofEpochMilli(1537468800000L);
        Date from = Date.from(instant);
        // Mybatis查询方法
        usersGameBetDetailExample.createCriteria().andBettimeLessThan(from);
        PageInfo usersGameBetDetailPageInfo = usersGameBetDetailService.pageQuery(usersGameBetDetailExample, pageParameter);
        //UsersGameBetDetail usersGameBetDetail = usersGameBetDetailMapper.selectByPrimaryKey(1925881);
        log.info("");
    }
}

实战使用 见代码
github https://github.com/ronnierry/boot2.0-mybatis-demo

你可能感兴趣的:(spring boot 2.X mybites 实战 自动生成+分页+查询使用)