class Employee: id_counter = 1000 #初始化传进的name和salary, def __init__(self,name,salary): self.id = Employee.id_counter Employee.id_counter += 1 self.name = name self.__salary = salary def __add__(self, other): return self.__salary+other.salary @property def salary(self): return self.__salary @salary.setter def salary(self,salary): if 1000<salary<50000: self.__salary = salary else: print("薪资太高养不起!!!") person1 = Employee("John",30000) person2 = Employee("keivin",300000) print(person1+person2) person1.salary = 20000 print(person1.salary) person1.salary = 100000000 #错误代码 @salary.setter def salary(self, salary): if 1000<salary<50000: self.salary = salary else: print("薪资太高养不起!!!")
老师我想问在这段代码中出现下面错误代码后,会导致栈溢出,我想问一下原因是什么,为什么会一直触发setter的调用
package com.bjsxt.test4; abstract public class dxh { private int id; abstract public void study(); abstract public void aa(); public int getId() { return id; } public void setId(int id) { this.id = id; } public dxh(int id) { this.id = id; } public dxh() { } } class dx extends dxh{ @Override public void study() { System.out.println("好好学习,天天向上!"); } @Override public void aa() { System.out.println("真棒!"); } } class test{ public static void main(String[] args){ dxh d=new dx(); d.study(); d.aa(); d.setId(1991); d.getId(); } }
老师,1991怎样打印出来?
还有有参构造函数在这有意义吗?
老师您好。海龟图中有句代码t=turtle.Pen()后面Pen为什么要加()呢?
老师,视频里说if __name__ == "__main"代表开启主线程,什么意思,代表的是我运行当前py文件,实际上就是pycharm这个进程开启了一个run当前文件的主线程么,那么当我debug模式的时候是不是又开启了一个主线程,但是一个文件只能有一个主线程,所以run就不会运行,此时只能是debug模式这个主线程在运行
老师我这个是啥问题?
send里面的wait锁不是锁所有拥有”abc“锁的吗,那么receive不是也是有”abc“锁吗,为啥不会被wait
老师,我有点看不懂括号里的单引号,双引号
老师这样写,每次创建的UserServiceImpl不是同一个对象吧
public class ObjectFactory { public static UserServiceImpl getInstance(){ return new UserServiceImpl(); }
我试了下这样写多次创建的才是同一个UserServiceImpl对象
public class ObjectFactory { private static UserServiceImpl userServiceImpl; public static UserServiceImpl getInstance(){ if (userServiceImpl == null) { userServiceImpl = new UserServiceImpl(); } return userServiceImpl; }
为什么使用git init 有错误
这个paint为什么不用在main中调用,而launchFrame需要调用呢
import com.itbaizhan.mapper.UserMapper;import com.itbaizhan.pojo.User;import org.apache.ibatis.io.Resources;import org.apache.ibatis.session.SqlSession;import org.apache.ibatis.session.SqlSessionFactory;import org.apache.ibatis.session.SqlSessionFactoryBuilder;import org.junit.Test;import java.io.InputStream;import java.util.List;public class TestUserMapper { @Test public void testFindAll() throws Exception{ // (1)读取核心配置文件 InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml"); // (2)创建SqlSessionFactoryBuilder对象 SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); // (3)SqlSessionFactoryBuilder对象获取SqlSessionFactory对象 SqlSessionFactory factory = builder.build(is); // (4)SqlSessionFactory对象获取SqlSession对象 SqlSession session = factory.openSession(); // (5)SqlSession对象获取代理对象 UserMapper userMapper = session.getMapper(UserMapper.class); // (6)代理对象执行方法 List<User> all = userMapper.findAll(); all.forEach(System.out::println); // (7)释放资源 session.close(); is.close(); }}
D:\Software\Java\JDK\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\Software\Java\IDEA\IntelliJ IDEA 2023.1\lib\idea_rt.jar=59437:D:\Software\Java\IDEA\IntelliJ IDEA 2023.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\Software\Java\IDEA\IntelliJ IDEA 2023.1\lib\idea_rt.jar;D:\Software\Java\IDEA\IntelliJ IDEA 2023.1\plugins\junit\lib\junit5-rt.jar;D:\Software\Java\IDEA\IntelliJ IDEA 2023.1\plugins\junit\lib\junit-rt.jar;E:\MavenProject\mybatiscase\mybatisDemo1\target\test-classes;E:\MavenProject\mybatiscase\mybatisDemo1\target\classes;E:\repository\org\mybatis\mybatis\3.5.7\mybatis-3.5.7.jar;E:\repository\mysql\mysql-connector-java\8.0.16\mysql-connector-java-8.0.16.jar;E:\repository\com\google\protobuf\protobuf-java\3.6.1\protobuf-java-3.6.1.jar;E:\repository\junit\junit\4.10\junit-4.10.jar;E:\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar;E:\repository\log4j\log4j\1.2.12\log4j-1.2.12.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 TestUserMapper,testFindAll [12/03 21:44:44] 0 [ main] DEBUG ache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.log4j.Log4jImpl' adapter. [12/03 21:44:44] 18 [ main] DEBUG source.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections. [12/03 21:44:44] 18 [ main] DEBUG source.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections. [12/03 21:44:44] 18 [ main] DEBUG source.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections. [12/03 21:44:44] 18 [ main] DEBUG source.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections. [12/03 21:44:44] 71 [ main] DEBUG ansaction.jdbc.JdbcTransaction - Opening JDBC Connection Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. ### The error may exist in com/itbaizhan/mapper/UserMapper.xml ### The error may involve com.itbaizhan.mapper.UserMapper.findAll ### The error occurred while executing a query ### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:153) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86) at com.sun.proxy.$Proxy8.findAll(Unknown Source) at TestUserMapper.testFindAll(TestUserMapper.java:26) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:189) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:224) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:219) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:95) at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:432) at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:139) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:61) at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) ... 32 more Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) at com.mysql.cj.NativeSession.connect(NativeSession.java:152) at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ... 52 more Caused by: java.net.UnknownHostException: 不知道这样的主机。 (mybatis) at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929) at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1515) at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848) at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505) at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364) at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298) at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ... 55 more Process finished with exit code -1
老师一直报错怎么办
老师,以前用XShell时建了一个会话192.168.1.10,后来换了个环境(WIFI换了),以前的连接不上了,所以又新建了个来连接192.168.101.10,但是为啥登录上去了一会就断开连接啊,这个跟网络有关系吗?
按操作安装怎么没有设置密码这一步,后面都进行不下去
视频里最后提供的图片是不是有问题,consumer应该没有向注册中心注册的这个操作吧。。。我记得之前的Dubbo架构图Consumer消费者做了一个 订阅 subscribe 以及一个通知notify的操作,这图不对吧。
图片的问题嘛?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637