如何对List<PjtSelectMstrInfo> pjtSelectMstrInfoList =....按照PjtSelectMstrInfo中usrId,usrNameJp,usrNameEn的顺序排序
时间: 2024-10-15 14:21:20 浏览: 48
如果你想按照`PjtSelectMstrInfo`中的usrId、usrNameJp(日文名),然后usrNameEn(英文名)的顺序对`List<PjtSelectMstrInfo>`进行排序,你可以使用Java的Collections.sort()方法,配合Comparator接口来自定义排序规则。以下是一个简单的示例:
```java
import java.util.*;
// 假设PjtSelectMstrInfo类有usrId, usrNameJp和usrNameEn属性
class PjtSelectMstrInfo implements Comparable<PjtSelectMstrInfo> {
private int usrId;
private String usrNameJp;
private String usrNameEn;
// getters和setters省略
@Override
public int compareTo(PjtSelectMstrInfo other) {
// 按照usrId,usrNameJp,usrNameEn的顺序比较
return Comparator.comparingInt(this::getUsrId)
.thenComparing(this::getUsrNameJp, String.CASE_INSENSITIVE_ORDER)
.thenComparing(this::getUsrNameEn, String.CASE_INSENSITIVE_ORDER)
.compare(this, other);
}
}
List<PjtSelectMstrInfo> pjtSelectMstrInfoList = ...; // 待排序的列表
Collections.sort(pjtSelectMstrInfoList);
```
这段代码首先实现了Comparable接口,覆盖了compareTo方法,该方法会根据usrId、usrNameJp和usrNameEn依次进行比较。然后使用Collections.sort()函数对列表进行排序。
如果你的环境不支持直接在List上排序,也可以先转换为ArrayList,然后再调用sort()方法:
```java
List<PjtSelectMstrInfo> sortedList = new ArrayList<>(pjtSelectMstrInfoList);
sortedList.sort(Comparator.comparingInt(PjtSelectMstrInfo::getUsrId)
.thenComparing(PjtSelectMstrInfo::getUsrNameJp, String.CASE_INSENSITIVE_ORDER)
.thenComparing(PjtSelectMstrInfo::getUsrNameEn, String.CASE_INSENSITIVE_ORDER));
```
阅读全文
相关推荐






<?php
$footerColor = "#2196F3";
// 启动会话,这步必不可少
session_start();
// 判断是否登陆
if ($_SESSION['usrtag'] === 'admin') {
//echo "您已经成功登陆";
} else {
die("您无权访问");
}
$conn = mysqli_connect("localhost:3306","visitor","helloitsme");
if (!$conn)
{
echo '请检查网络!';
die('Could not connect: ' . mysql_error());
}
mysqli_select_db($conn,'rentcar');
$sql = "select * from bookrecord where result='booking'";
$res = mysqli_query($conn,$sql);
$records=array();
while( $row = mysqli_fetch_array($res)){
$records[]=$row;
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>后台管理</title>
<style type="text/css">
*{margin:0;padding:0;}
body{background-color:white;
width:100%;}
.clear{clear:both;}
#container{
background-color:#BBBBFF;
height:510px;
width:1500px;
margin:auto;}
#picture{height:470px; margin:0px;}
#label{background-color:white; height:30px;}
#container2{
background-color:white;
width:800px;
height:340px;
margin:20px auto;
}
#content{
background-color:white;
width:1000px;
height:100px;
margin:20px auto;
}
a {
color: #F3ADAE;
}
a:link {
color: #0B0B0B;
text-decoration: none;
}
a:visited {
color: #0B0B0B;
text-decoration: none;
}
a:hover {
color: #17E515;
text-decoration: none;
}
a:active {
text-decoration: none;
}
#division{
background-color:white;
width:800px;
height:70px;
margin:20px auto;
}
</style>
</head>
<body>
订单情况
待处理订单
商品数据更新
已注册用户资料
待确认订单信息表
订单编号 账户名 客户邮箱 租借地点 租借时间 归还时间 处理进度 操作
<?php foreach($records as $row) : ?>
<?php echo $row['idbookrecord'];?>
<?php echo $row['usrid'];?>
<?php echo $row['personalid'];?>
<?php echo $row['getcarplace'];?>
<?php echo $row['starttime'];?>
<?php echo $row['endtime'];?>
<?php echo $row['result'];?>
<form action = "confirmrecord.php" method = "post">
<input type="hidden" name="thevalue1" value="<?php echo $row['idbookrecord'];?>">
<input type="submit" name="submit" value="确认" />
</form>
<form action = "rejectrecord.php" method = "post">
<input type="hidden" name="thevalue2" value="<?php echo $row['idbookrecord'];?>">
<input type="submit" name="submit" value="拒绝" />
</form>
<?php endForeach;?>
<form action="logOut.php" method="post" onsubmit="return enter()">
<label><input class="submit" type="submit" name="logout" value="登出账户" /></label>
</form>
充充宝公司版权所有©2024-2025
<script>
// function func1(self){
// //alert(self.innerHTML);
// location.reload();
// }
//a onclick="func1(this)">删除/a
//$('#delete_button').click(function(){
// var comment_id = $(this).attr('id');//you should use the id of the comment as id for the delete button for this to work.
// $.post('delete.php', {'comment_id' : comment_id}, function(){
// $(this).parent('div').remove(); //hide the comment from the user
// });
// });
</script>
</body>
</html>
帮我检查这个代码,底边紫色无法扩充到网页边界




