新建javaWeb项目maven(springboot+mybatis+mysql)
·
一、新建
新建项目
新建->选择java、Maven、jdk和java选择相同版本、打包选择jar->springboot版本选择2.x(3.x版本需要jdk17以上)->依赖选择developerTools中的lombok、web中的SpringWeb、SQL中选择MyBatisFramework和MySqlDriver,点击完成
新建类
建立五个包,分别为controller、service、mapper、pojo、utils
在service包下面建立impl包
二、运行
Maven自带Tomcat,点击Application主类,点击运行
三、配置
在application.properties进行配置
mysql配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/数据库名
spring.datasource.username=root
spring.datasource.password=123456
mybatis对象名转换
数据库字段名user_id<==>对象的属性名userId,可以相互转换
mybatis.configuration.map-underscore-to-camel-case=true
四、依赖添加
在pom.xml中添加的dependencies标签中添加
pagehelper
更简单的的实现分页查询,获取总页数和每页查询的数量
pom.xml配置
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.2</version>
</dependency>
//代码实现部分
//设置要查询的开始页数和一页的大小
PageHelper.startPage(page,pageSize);
//获取全部数据
List<XXX> List = Mapper.getlist();
//自动选择出当前查询的页数据列表
Page<XXX> p = (Page<XXX>)empList;
// 通过p.getTotal()获取数据总条数,p.getResult()获取结果列表
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)