会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132496个问题
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 23180楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用Solr实现数据搜索 23181楼

<div class="white-nav">
    <div class="white-nav-bar">
        <div class="bar-left">
            <a href="#">
                <img  class="mi-logo"src="images/mi-logo.png" alt="">
                <img  class="mi-home" src="images/mi-home.png" alt="">
            </a>
        </div>
        <div class="bar-center">
            <ul>
                <li><a href="#">小米手机
                <div class="list">
                    <div class="list-center">
        <ul>
            <li>
                <a href="#"><div class="img-box"><img src="images/3b19bf0e7e599c1bbbce510fb0dbc8bc.jpg" alt="">
                </div>
                    <p class="name1">小米10S</p>
                    <p class="price1">3299元起</p></a>
            </li>
            <li><a href="#"><div class="img-box"><img src="images/3b19bf0e7e599c1bbbce510fb0dbc8bc.jpg" alt="">
            </div>
                <p class="name1">小米10S</p>
                <p class="price1">3299元起</p></a></li>
            <li><a href="#"><div class="img-box"><img src="images/3b19bf0e7e599c1bbbce510fb0dbc8bc.jpg" alt="">
            </div>
                <p class="name1">小米10S</p>
                <p class="price1">3299元起</p></a></li>
            <li><a href="#"><div class="img-box"><img src="images/3b19bf0e7e599c1bbbce510fb0dbc8bc.jpg" alt="">
            </div>
                <p class="name1">小米10S</p>
                <p class="price1">3299元起</p></a></li>
            <li><a href="#"><div class="img-box"><img src="images/3b19bf0e7e599c1bbbce510fb0dbc8bc.jpg" alt="">
            </div>
                <p class="name1">小米10S</p>
                <p class="price1">3299元起</p></a></li>
            <li class="last-list"><a href="#"><div class="img-box"><img src="images/3b19bf0e7e599c1bbbce510fb0dbc8bc.jpg" alt="">
            </div>
                <p class="name1">小米10S</p>
                <p class="price1">3299元起</p></a>
            </li>
        </ul>
    </div>
    </div>
                </a></li>
.white-nav{
    width: 1423px;
    height: 100px;
    background-color: #ffffff;
    position: relative;

}
.white-nav-bar{
    width: 1226px;
    height: 100%;
    margin: 0 auto;
}
.bar-left{
    width: 55px;
    height: 55px;
    background-color: #ff6700;
    margin-top: 22.5px;
    float:left;
    position: relative;
    overflow: hidden;

}
.bar-center{
    width: 875px;
    height: 100%;
    float: left;
    line-height: 100px;

}
.bar-right{
    height: 100px;
    width: 296px;
    position: relative;
    float: left;
}
.bar-center>ul{
    margin-left: 179px;

}
.bar-center li{
    padding: 0 10px;
    float: left;


}
.bar-center>ul>li>a{
    color: #333333;
}
.bar-center>ul>li>a:hover{
    color: #ff6700;
}
.mi-home{
    width: 100%;
    position: absolute;
    top: 0;
    left: 100%;
}
.mi-logo{
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}
.bar-left:hover .mi-logo{
    left: -100%;
}
.bar-left:hover .mi-home{
    left: 0;
}
.bar-left img{
    transition: all .2s;
}
.list{
    width: 1423px;
    height: 0;
    background-color: #fff;
    position: absolute;
    left: 40px;
    top: 100px;
    box-shadow: 0 3px 4px rgba(0,0,0,.2);
    transition: all .2s;
    overflow: hidden;
    float: left;



}
.list-center{
    width: 1226px;
    height: 100%;
    position: absolute;
    left: 50%;
    margin-left: -613px;
    float: left;
}
.list-center li{
    width: 204px;
    padding: 0;
}
.img-box{
    width: 100%;
    height: 110px;
    border-right: 1px solid #eee;
    box-sizing: border-box;
    margin-top: 35px;
    margin-bottom: 16px;
}
.img-box img{
    height: 100%;
}
.list-center p{
    font-size: 12px;
    line-height: 20px;
}
.last-list .img-box{
  border-right: none ;
}
.name1{
    color: #333;
}
.price1{
    color: #ff6700;
}
.bar-center li:hover .list{
    height: 229px;
    border-top: 1px solid rgba(224,224,224,.6);

}
.bar-right{
    height: 100px;
    position: relative;
}
.bar-right input{
    width: 244px;
    height: 50px;
    border: 1px solid #e0e0e0;
    padding: 0 10px;
    box-sizing: border-box;
    outline: none;
    float: left;
    border-right: none;
    margin-top: 25px;

}
.bar-right>button{
    width: 52px;
    height: 50px;
    border: 1px solid #e0e0e0;
    background-color: #fff;
    float: left;
    margin-top: 25px;

}
.bar-right input:focus{
    border-color: #ff6700;
}
.bar-right input:focus~.iconfont{
    border-color: #ff6700;
}
.bar-right>button:hover{
    background-color: #ff6700;
    color: #fff;
}

.text-list{
    width: 243px;
    height: 0;
    border-top: none;
    position: absolute;
    top: 75px;
    left: 0;
    z-index: 990;
    background-color: #fff;
}
.bar-right input:focus+.text-list{
    height: 240px;
    border: 1px solid #ff6700;
    border-top: none;
}

老师我想问问为什么我的list显示不了100%的宽度

WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS3新特性 23182楼

package com.cx;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 使用封装工具
 */
public class jdbcTest2 {
    //向Department表中添加一条数据
    public void insertDeparments(String department_name,int location_id){
        Connection conn = null;
        Statement state = null;
        try {
            //使用封装工具
            conn = jdbcUtil1.getConnection();

            String sql="insert into departments values(default,'"+department_name+"',"+location_id+")";
            state = conn.createStatement();   //通过conn对象调用Connection接口下createStatement方法
            int flag = state.executeUpdate(sql);
            System.out.println(flag);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            jdbcUtil1.closeConnection(conn);
            jdbcUtil1.closeStatment(state);
        }
    }
    //更新departments表中的department_id为6的数据,将部门名称修改为教学不,location_id修改为6
    public  void  updateDepartments(String department_name,int location_id,int department_id){
        Connection conn = null;
        Statement state = null;
        try {
            conn= jdbcUtil1.getConnection();
            state = conn.createStatement();
            String sql = "update departments d set d.department_name = '"+department_name+"',d.location_id ="+location_id+" where d.department_id ="+department_id+"";
            int flag = state.executeUpdate(sql);
            System.out.println(flag);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            jdbcUtil1.closeConnection(conn);
            jdbcUtil1.closeStatment(state);
        }
    }
    //查询Departments表中部门ID为6的部门信息
    public void selectDepartmentsById(int departmentId){
        Connection conn = null;
        Statement state = null;
        ResultSet rs = null;
        try {
            conn = jdbcUtil1.getConnection();
            state = conn.createStatement();
            String sql = "select * from departments d where d.department_id = "+departmentId;
            //执行查询返回结果
            rs = state.executeQuery(sql);
            while (rs.next()){
                int a = rs.getInt("department_id");
                String s = rs.getString("department_name");
                int b = rs.getInt(3);
                System.out.println(a+" "+s+" "+b);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            jdbcUtil1.closeConnection(conn);
            jdbcUtil1.closeStatment(state);
            jdbcUtil1.closeResultSet(rs);
        }
    }

    public static void main(String[] args) {
        jdbcTest2 test2 = new jdbcTest2();
        //test.insertDeparments("工程部",6);
       // test.updateDepartments("研发",6,8);
        test2.selectDepartmentsById(6);
    }
   
}
package com.cx;


import java.sql.*;
import java.util.ResourceBundle;

/**
 * 封装jdbc工具类
 */
public class jdbcUtil1 {
    private static String driver;
    private static String jdbcUrl;
    private static String username;
    private static String userpassword;
    static {
        ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
        driver=bundle.getString("driver");
        jdbcUrl= bundle.getString("jdbcUrl");
        username=bundle.getString("username");
        userpassword=bundle.getString("userpassword");
        try {
            Class.forName(driver);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    //获取Connection对象
    public static Connection getConnection() {
        Connection conn = null;
        try {
            //获取连接
            conn = DriverManager.getConnection(jdbcUrl,username,userpassword);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
    //关闭Statement
    public static void closeStatment(Statement state){
        try {
            if (state != null){
                state.close();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    //关闭Connection
    public static void closeConnection(Connection conn){
        try {
            if (conn != null){
                conn.close();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
    //关闭
    public  static void closeResultSet(ResultSet rs){
        try {
            if (rs != null){
                rs.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
driver="com.mysql.jdbc.Driver"
jdbcUrl ="jdbc:mysql://localhost:3306/caixx?useUnicode=true&usecharacterEncoding=utf-8&useSSL=false"
username="root"
userpassword="root"


发现使用properties就会报错

image.png


不使用properties就正常, IDEA到底如何使用这个?

JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 23183楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 23184楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/XML 技术(旧) 23185楼

在UserRealm3中写

while(rs.next()){
    SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(authenticationToken.getPrincipal(),rs.getString("pwd"),ByteSource.Util.bytes(rs.getString("salt")),"userRealm3");

    return simpleAuthenticationInfo;
}

运行TestC就会显示登入失败,并且报异常

把ByteSource.Util.bytes(rs.getString("salt")改为ByteSource.Util.bytes("lin")再运行TestC就登入成功


写ByteSource.Util.bytes(rs.getString("salt")出现的异常

log4j:WARN No appenders could be found for logger (org.apache.shiro.io.ResourceUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.sql.SQLException: Column 'salt' not found.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
	at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1162)
	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5728)
	at com.bjsxt.shiro03.UserRealm3.doGetAuthenticationInfo(UserRealm3.java:40)
	at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:568)
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:180)
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
	at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
	at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
	at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
	at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
	at com.bjsxt.shiro03.TestC.main(TestC.java:25)
登入失败

Process finished with exit code 0


image.png


数据库

image.png



shiro01.rar


JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 23186楼
JAVA 全系列/第八阶段:Linux入门到实战/Linux(旧) 23187楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Dubbo 23188楼
Python 全系列/第一阶段:Python入门/控制语句 23189楼

image.png
为啥 我这反射0,普通方法252- -,不是反射比普通方法运行慢吗

package com.a.cx;

import java.lang.reflect.Method;

/**
 * 测试反射机制的效率
 */
public class TestReflectDemo2 {
    public static void main(String[] args) {
        try {
            //反射耗时
            Class clazz = Class.forName("com.a.cx.Users");
            //newInstance() 返回的是Object类型的结果,这里强制类型转换为Users类型
            Users users = (Users)clazz.newInstance();
            long reflectStart = System.currentTimeMillis();
            Method method = clazz.getMethod("setUsername", String.class);
            for (int i=0;i<100000000;i++){
                method.invoke(users,"李二狗");
            }
            long refectEnd = System.currentTimeMillis();

            //非反射方式耗时
            long start = System.currentTimeMillis();
            Users u = new Users();
            for (int i=0;i<100000000;i++){
                u.setUsername("oldlu");
            }
            long end = System.currentTimeMillis();
            System.out.println("反射执行时时间:"+(refectEnd-refectEnd));
            System.out.println("非反射执行时时间:"+(end-start));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


JAVA 全系列/第二阶段:JAVA 基础深化和提高/反射技术(旧) 23190楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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