springboot整合mybatis,swagger ui

来源:互联网 发布:微博的个性域名怎么改 编辑:程序博客网 时间:2024/06/05 07:05

项目整体结构



pom.xml文件

4.0.0hongyispringboot-mybatis0.0.1-SNAPSHOTwarUTF-81.71.3.0org.springframework.bootspring-boot-starter-parent1.5.8.RELEASEorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-tomcatorg.mybatis.spring.bootmybatis-spring-boot-starter${mybatis-spring-boot.version}com.github.pagehelperpagehelper5.1.1mysqlmysql-connector-javaio.springfoxspringfox-swagger22.6.1io.springfoxspringfox-swagger-ui2.6.1javax.servletjavax.servlet-apiprovidedjavax.servletjstlorg.apache.tomcat.embedtomcat-embed-jasperorg.slf4jslf4j-log4j12providedorg.springframework.bootspring-boot-maven-pluginsrc/main/webappMETA-INF/resources**/**src/main/resources**/**false

创建application.properties,位置是src/java/resources下
##数据库配置信息spring.datasource.url=jdbc:mysql://localhost:3306/easyui?userUnicode=true&characterEncoding=UTF8&useSSL=falsespring.datasource.username=rootspring.datasource.password=donghuspring.datasource.driver-class-name=com.mysql.jdbc.Driver#设置包的别名mybatis.typeAliasesPackage=com.hy31.pojo#设置mapper.xml文件的位置mybatis.mapperLocations=classpath:mapper/*.xml#设置springmvc的前缀spring.mvc.view.prefix=/WEB-INF/jsp/#后缀spring.mvc.view.suffix=.jsp

mybatis分页插件配置
/** * 此类属于配置类,代替xml配置 */@SpringBootConfigurationpublic class MybatisConfig {/** * 分页插件配置 * @return */@Beanpublic PageInterceptor getPageInterceptor() {PageInterceptor pageInterceptor = new PageInterceptor();Properties properties = new Properties();//        //        properties.setProperty("offsetAsPageNum", "true");// 设置为true时,使用RowBounds分页会进行count查询 会去查询出总数 properties.setProperty("rowBoundsWithCount", "true");// 分页合理化properties.setProperty("reasonable", "true");pageInterceptor.setProperties(properties);return pageInterceptor;}// 配置mybatis的分页插件pageHelper 4.X版本 配置/* * @Bean public PageHelper pageHelper(){ PageHelper pageHelper = new * PageHelper(); Properties properties = new Properties(); * properties.setProperty("offsetAsPageNum","true"); * properties.setProperty("rowBoundsWithCount","true"); * properties.setProperty("reasonable","true"); * properties.setProperty("dialect","mysql"); //配置mysql数据库的方言 * pageHelper.setProperties(properties); return pageHelper; } */}


程序主入口
//MyBatis 扫描mapper接口@MapperScan("com.hy31.mapper")@SpringBootApplicationpublic class SBApplication extends SpringBootServletInitializer  {/** * 打成war发布,重写此方法 */@Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {        return application.sources(SBApplication.class);    }public static void main(String[] args) throws Exception {        SpringApplication.run(SBApplication.class, args);    }}
启动:


swagger-ui使用这里暂时不详细写,只截图: