记录自己搭建的spring+mybatis+springMvc小案例

由于最近一直在带团队,写代码的时间逐渐减少,心里慌的一批 ,于是乎网上找了点资料,踩了一次坑,对这一套理解其实不深,只限于可以搭建后台而已

  1. mybatisgenerator

这个是神器,完全手打不现实,逆向工程生成,网上挺多配置文件的,也有包含controller,service生成的,我这一套不包含
附上pom.xml跟mybatisgenerator.配置
pom.xml


 mybatis.generator
        
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.5
                
                    ${basedir}/src/main/resources/mybatisgenerator/generatorConfig.xml
                    true
                    true
                
            
        

generatorConfig.xml




    
    
    
        
            
            
            
        
        
        
        
        
            
        
        
        
            
            
        
        
        
            
        
        
        
        
            
        

        
        

附上截图
记录自己搭建的spring+mybatis+springMvc小案例_第1张图片
记录自己搭建的spring+mybatis+springMvc小案例_第2张图片

  1. application.yml配置
spring:
  application:
    name: myspringboot
  output:
    ansi:
      enabled: always
  profiles:
    active: dev
  thymeleaf:
    encoding: UTF-8
    prefix: classpath:/templates/

server:
  tomcat:
    uri-encoding: UTF-8
    max-connections: 500
    min-spare-threads: 25
    max-threads: 300
    accept-count: 200
  port: 8080
mybatis:
  type-aliases-package: com.example.demo.testSpringBoot.mapper
  mapper-locations: classpath:com.example.demo.testSpringBoot.mapper/*.xml

pagehelper:
  helper-dialect: mysql
  reasonable: true
  support-methods-arguments: true
  params: count=countSql
logging:
  level:
    com.example.demo.testSpringBoot.mapper: debug

---

#开发配置
spring:
  profiles: dev
  datasource:
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    filters: stat
    maxActive: 20
    initialSize: 1
    maxWait: 60000
    minIdle: 1
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: select 'x'
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    maxOpenPreparedStatements: 20
  1. springboot配置项
@MapperScan(value = "com.example.demo.testSpringBoot.mapper")
@ComponentScan(basePackages = {"com.example.demo.testSpringBoot"})
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

@MapperScan注解可以直接找到mapper项
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})自动找数据库
4. 总结
当然中间遇到很多问题
比如找不到数据库 Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required
等等 不过还是要细心,不要觉得麻烦就不配置了
等有时间在把前端页面给配置出来
附一个链接,我也是按照这个老哥提供的数据做的
https://www.cnblogs.com/zhangbin1989/p/9473292.html

你可能感兴趣的:(记录自己搭建的spring+mybatis+springMvc小案例)