Python 官方文档:入门教程 => 点击学习
目录需求:1.导入依赖2.配置文件3.创建分页需要的缓存4.创建实体类5.mapper6.测试7.结果需求: 先时间升序排序,相同的时间在按状态排序,状态的顺序为1 在线 4 潜伏
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>Mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
spring:
# 配置数据源信息
datasource:
# 配置数据源类型
type: com.zaxxer.hikari.HikariDataSource
# 配置连接数据库信息
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis_plus?characterEncoding=utf-8&useSSL=false
username: root
passWord: 123456
mybatis-plus:
configuration: # 配置MyBatis日志
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
@Configuration
@MapperScan("scan.your.mapper.package")
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
}
@Data
public class User {
private Integer id;
private String name;
private Integer age;
private String email;
private Integer state;//1 在线 4 潜伏 2 隐身 3 离开
private Date time;
}
public interface UserMapper extends BaseMapper<User> {
}
在启动类上加了@MapperScan(“com.example.mapper”)
@Test
void selectUser(){
QueryWrapper<User> wrapper=new QueryWrapper<>();
//时间升序排序
wrapper.lambda().orderByAsc(User::getTime);
//状态的自定义排序,和姓名排序
wrapper.orderByAsc(" field(state,1,4,2,3)");
wrapper.lambda().orderByAsc(User::getName);
//分页
Page page=new Page<>();
page.setSize(3);//每页的长度
page.setPages(1);//第几页
userMapper.selectPage(page,wrapper);
}
到此这篇关于mybatis-plus自定义排序的实现的文章就介绍到这了,更多相关mybatis-plus 自定义排序内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: mybatis-plus自定义排序的实现
本文链接: https://lsjlt.com/news/177176.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0