会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133950个问题
人工智能/第六阶段:机器学习-线性分类/逻辑回归 25486楼

老师,通过比较器实现比较规则这个显示下面这一行

Map<Student,String> treeMap = new TreeMap<>(new StudentComparator());

出了问题,能帮我看一下是什么问题吗?

package 双例集合;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/**
 * 元素自身实现比较规则   TreeMap可以对键进行排序
 */
public class TreeMapTest {
    public static void main(String[] args) {
        //实例化TreeMap
        Map<Users,String> map = new TreeMap<>();
        //创建User对象
        Users u1 = new Users("liu",18);
        Users u2 = new Users("admin",20);
        Users u3 = new Users("sxt",20);
        map.put(u1,"liu");
        map.put(u2,"admin");
        map.put(u3,"sxt");
        Set<Users> keys = map.keySet();
        for (Users key:keys){
            System.out.println(key+" "+map.get(key));
        }
        System.out.println("-----通过比较器实现比较规则-------");
        //java.lang.ClassCastException: 双例集合.Student cannot be cast to java.lang.Comparable
        //创建StudentComparator对象,然后交给TreeMap的构造方法中
        Map<Student,String> treeMap = new TreeMap<>(new StudentComparator());
        Student s1 = new Student("liu",18);
        Student s2 = new Student("admin",20);
        Student s3 = new Student("sxt",20);
        treeMap.put(s1,"liu");
        treeMap.put(s2,"admin");
        treeMap.put(s3,"sxt");
        Set<Student> keys2 = treeMap.keySet();
        for (Student key:keys2){
            System.out.println(key+" "+treeMap.get(key));
        }

    }
}

blob.png

JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 25488楼
JAVA 全系列/第十四阶段:分布式文件存储与数据缓存/MongoDB 25490楼

老师,为什么“技术·共享·娱乐”这张图片的高度变高了呢?


图片.png

<!--第一块开始-->
<div class="one box">
    <video src="images/201702241034284066.mp4" autoplay loop muted>
        您的浏览器不支持视频,请升级!
    </video>
    <div class="text">
        <img src="images/video_txt.png" alt="">
        <a href="#">下载迅雷产品</a>
        <i class="iconfont">&#xe60c;</i>
    </div>
</div>
<!--第一块结束-->


/*第一块样式开始*/
.one{
    /*垂直方向溢出部分隐藏 不出现滚动条*/
    overflow: hidden;
    position: relative;
}
.one>video{
    width: 100%;
}
.text{
    width: 716px;
    height: 193px;
    position: absolute;
    /*相对于父元素one往下走50%*/
    top: 50%;
    /*相对于父元素one往右走50%*/
    left: 50%;
    /*往左上走自己宽高的一半*/
    transform: translate(-50%,-50%);
}
.text>img{
    width: 100%;
}
.text>a{
    width: 180px;
    height: 50px;
    margin: 30px auto 20px;
    color: #fff;
    /*z转换为块级元素 样式才会生效*/
    display: block;
    border: 1px solid #fff;
    /*水平居中 行高等于高*/
    line-height: 50px;
}
.text>a:hover{
    background-color: rgba(255,255,255,.5);
}
.text>i{
    font-size: 40px;
    color: #fff;
    animation: updown 1s linear infinite;
    /*转换为块级元素 实现动画*/
    display: block;
}
@keyframes updown{
    0%{
        transform: translateY(0);
    }
    33%{
        transform: translateY(-3px);
    }
    66%{
        transform: translateY(0);
    }
    100%{
        transform: translateY(3px);
    }
}
/*第一块样式结束*/


WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS应用技巧 25493楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>post请求</title>
    <style>
        .sp {width: 80px;height: 35px;line-height: 35px;display: inline-block;}
    </style>
</head>
<body>
    <label for="">
        <span class="sp">用户名:</span><input type="text" class="username">
    </label><br>
    <label for="">
        <span class="sp">密码:</span><input type="password" class="password">
    </label>
    <button>登录</button>

    <script>
        var iun=document.querySelector('.username').value;
        var ipw=document.querySelector('.password').value;
        var btn=document.querySelector('button');

        btn.onclick=function() {
            var xhr=new XMLHttpRequest();
            xhr.onreadystatechange=function() {
                if(xhr.readyState==4) {
                    if(xhr.states==200) {
                        console.log(JSON.parse(xhr.responseText));
                    } 
                }
            }
            xhr.open('post','前台post请求.php',true);
            var datas=new FormData();
            datas.append('usern',iun);
            datas.append('passw',ipw);
            xhr.send(datas);
        }
    </script>
</body>
</html>
<?php

$success=array('msg'=>'ok','info'=>$_POST);
echo json_encode($success);

?>

老师你看

WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 25494楼
Python 全系列/第一阶段:AI驱动的Python编程/Python入门(动画版) 25495楼
JAVA 全系列/第十阶段:权限控制与安全认证/Spring Security(旧) 25496楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 25497楼
Python 全系列/第七阶段:网页编程基础/CSS 样式 25499楼

QQ截图20210130173346.png

这个报错是什么意思呢

WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 25500楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637