├── .gitignore ├── README.md ├── jwt-sample ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── hisen │ │ └── jwt │ │ ├── controller │ │ └── MainController.java │ │ ├── entity │ │ ├── CommonResponse.java │ │ ├── LoginReq.java │ │ └── LoginRes.java │ │ ├── filter │ │ ├── CorsFilter.java │ │ ├── JwtCheckInterceptor.java │ │ └── JwtFilter.java │ │ └── service │ │ ├── LoginService.java │ │ └── impl │ │ └── LoginServiceImpl.java │ ├── resources │ ├── jwt.properties │ ├── logback.xml │ └── spring │ │ ├── spring-cors.xml │ │ └── spring-web.xml │ └── webapp │ ├── WEB-INF │ └── web.xml │ ├── hisenyuan.html │ ├── hisenyuan.js │ ├── index.jsp │ ├── jquery.base64.js │ ├── login.html │ └── login.js ├── pom.xml ├── readinglist ├── .gitignore ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── hisen │ │ │ ├── ReadinglistApplication.java │ │ │ ├── conditions │ │ │ └── JdbcTemplateCondition.java │ │ │ ├── dao │ │ │ └── ReadingListRepository.java │ │ │ ├── entity │ │ │ └── Book.java │ │ │ └── mvc │ │ │ └── ReadingListController.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ └── style.css │ │ └── templates │ │ └── readingList.html │ └── test │ └── java │ └── com │ └── hisen │ └── ReadinglistApplicationTests.java ├── src └── main │ ├── java │ └── com │ │ ├── hisen │ │ ├── Objects │ │ │ ├── bean │ │ │ │ └── Student.java │ │ │ └── test │ │ │ │ └── ObjectsTest.java │ │ ├── Reflect │ │ │ ├── ReflectDemo.java │ │ │ ├── ReflectTest.java │ │ │ └── get │ │ │ │ ├── Person.java │ │ │ │ └── ReflectPersonDemo.java │ │ ├── ShowFileName │ │ │ ├── ShowFileNameFrame.java │ │ │ └── traverseFolder.java │ │ ├── algorithms │ │ │ ├── Bfs.java │ │ │ ├── ClassicalQuestion.java │ │ │ ├── Permutations.java │ │ │ ├── RotateArray.java │ │ │ ├── WeightAlgorithm.java │ │ │ ├── leetcode │ │ │ │ ├── MoveZeroes.java │ │ │ │ └── ValidSudoku.java │ │ │ └── sort │ │ │ │ ├── FindMiddle.java │ │ │ │ ├── QuickSort.java │ │ │ │ ├── Sort_Test.java │ │ │ │ ├── SortingAlgorithms.java │ │ │ │ └── java8Test.java │ │ ├── api │ │ │ ├── douban │ │ │ │ ├── bean │ │ │ │ │ ├── Book.java │ │ │ │ │ ├── Images.java │ │ │ │ │ ├── Rating.java │ │ │ │ │ └── Tag.java │ │ │ │ └── controller │ │ │ │ │ └── GetBookInfomationFromDouban.java │ │ │ └── github │ │ │ │ └── UserInformation.java │ │ ├── clipboard │ │ │ └── JavaClipboard.java │ │ ├── collection │ │ │ ├── list │ │ │ │ ├── ArrayListTest.java │ │ │ │ ├── LinkedListTest.java │ │ │ │ ├── aboutlist │ │ │ │ │ ├── PrintArray.java │ │ │ │ │ ├── hisen.java │ │ │ │ │ └── list1.java │ │ │ │ ├── duplicate │ │ │ │ │ ├── DuplicateMethod.java │ │ │ │ │ ├── ListDuplicateTest.java │ │ │ │ │ └── PersonBean.java │ │ │ │ └── sortlistbycomparator │ │ │ │ │ ├── SortListByComparator.java │ │ │ │ │ └── Student.java │ │ │ ├── map │ │ │ │ ├── CrunchifyConcurrentHashMapVsSynchronizedMap.java │ │ │ │ └── HashMapTest.java │ │ │ └── set │ │ │ │ └── NpResolveBySet.java │ │ ├── copy │ │ │ └── smaller │ │ │ │ ├── bean │ │ │ │ ├── Address.java │ │ │ │ ├── Order.java │ │ │ │ └── ProductInfo.java │ │ │ │ └── utils │ │ │ │ └── CopyLimitedPropertiesUtil.java │ │ ├── databases │ │ │ ├── mongodb │ │ │ │ └── SampleMongoTestNo1.java │ │ │ └── mysql │ │ │ │ └── jdbc │ │ │ │ ├── AddData.java │ │ │ │ └── DBUtils.java │ │ ├── designpattern │ │ │ ├── Singleton.java │ │ │ ├── proxy │ │ │ │ ├── dynamicproxy │ │ │ │ │ ├── DynamicProxy.java │ │ │ │ │ └── DynamicProxyMain.java │ │ │ │ └── staticproxy │ │ │ │ │ ├── BuyCar.java │ │ │ │ │ ├── BuyCarMain.java │ │ │ │ │ ├── BuyCarProxy.java │ │ │ │ │ └── Customser.java │ │ │ └── simplefactory │ │ │ │ ├── CalculatorMain.java │ │ │ │ ├── OperationAdd.java │ │ │ │ ├── OperationDiv.java │ │ │ │ ├── OperationMul.java │ │ │ │ ├── OperationSub.java │ │ │ │ ├── Opreation.java │ │ │ │ └── OpreationSimpleFactory.java │ │ ├── emvco │ │ │ ├── EmvcoSgqrMain.java │ │ │ ├── crccalc │ │ │ │ ├── AlgoParams.java │ │ │ │ ├── Crc16.java │ │ │ │ ├── Crc32.java │ │ │ │ ├── Crc64.java │ │ │ │ ├── Crc8.java │ │ │ │ ├── CrcCalculator.java │ │ │ │ ├── CrcHelper.java │ │ │ │ └── CrcUtils.java │ │ │ └── parser │ │ │ │ ├── EMVCoParser.java │ │ │ │ └── EmvcoTlvBean.java │ │ ├── file │ │ │ ├── Html2Image.java │ │ │ ├── oracle │ │ │ │ ├── function │ │ │ │ │ ├── GET_DATE_FROM_MILLISECOND.fnc │ │ │ │ │ └── GET_MILLISECOND_FROM_DATE.fnc │ │ │ │ └── produres │ │ │ │ │ ├── GET_ONE_DAY_24_DATA.prc │ │ │ │ │ └── oracle存储过程.txt │ │ │ └── test.txt │ │ ├── github │ │ │ ├── api │ │ │ │ └── UserInformation.java │ │ │ └── gitlab │ │ │ │ ├── Commit.java │ │ │ │ ├── CountMain.java │ │ │ │ ├── GetCommitsCallable.java │ │ │ │ ├── GitLabConstants.java │ │ │ │ ├── GitLabUtil.java │ │ │ │ └── README.md │ │ ├── image │ │ │ ├── ShowImageByBase64.java │ │ │ ├── controller │ │ │ │ └── addFont.java │ │ │ ├── imageAddFont.java │ │ │ └── testImage.java │ │ ├── interview │ │ │ ├── AboutExtends.java │ │ │ ├── AboutNewObject.java │ │ │ ├── BloomFilter.java │ │ │ ├── CreateNumberByRMB.java │ │ │ ├── FinalString.java │ │ │ ├── FindFirstNotDupStr.java │ │ │ ├── FindLucklyOne.java │ │ │ ├── FindNotDupInArray.java │ │ │ ├── GB2312__to__ISO_8859_1.java │ │ │ ├── MoveElement.java │ │ │ ├── MultithreadingSingleton.java │ │ │ ├── QuickSort.java │ │ │ ├── ReverseLink.java │ │ │ ├── ReverseString.java │ │ │ ├── TestStringTokenizer.java │ │ │ ├── effective │ │ │ │ ├── no2buildpatter │ │ │ │ │ ├── NutritionFacts.java │ │ │ │ │ └── TestBuilderPatter.java │ │ │ │ └── no3enumsingleton │ │ │ │ │ ├── EnumSingleton.java │ │ │ │ │ └── TestEnumSingleton.java │ │ │ ├── java8 │ │ │ │ ├── FunctionalInterfaceTest.java │ │ │ │ └── LambdaExpression.java │ │ │ ├── math │ │ │ │ ├── Ascii2String_String2Ascii.java │ │ │ │ ├── Get_GCD_LCM.java │ │ │ │ ├── JiDan.java │ │ │ │ ├── LingXing.java │ │ │ │ ├── MaopaoSort.java │ │ │ │ ├── RandomCode.java │ │ │ │ ├── ReadText.java │ │ │ │ ├── digui.java │ │ │ │ ├── sumJC.java │ │ │ │ └── xyz.java │ │ │ └── tiger20171110 │ │ │ │ ├── btree │ │ │ │ ├── BTree.java │ │ │ │ ├── BTreeMain.java │ │ │ │ ├── LinkBTree.java │ │ │ │ ├── OrderBTree.java │ │ │ │ └── Visit.java │ │ │ │ ├── multithreadingwrite │ │ │ │ ├── MultithreadingWrite.java │ │ │ │ ├── Write2File.java │ │ │ │ └── Write2FileMain.java │ │ │ │ └── reverselinkedlist │ │ │ │ ├── Node.java │ │ │ │ ├── ReverseNode.java │ │ │ │ └── ReverseNodeMain.java │ │ ├── jars │ │ │ ├── JUnit │ │ │ │ ├── Calculator.java │ │ │ │ └── CalculatorTest.java │ │ │ ├── Jedis │ │ │ │ ├── FirstTest.java │ │ │ │ ├── PipeliningTest.java │ │ │ │ ├── RedisLock │ │ │ │ │ └── RedisLock.java │ │ │ │ └── TestCase.java │ │ │ ├── apache │ │ │ │ └── commons │ │ │ │ │ └── lang │ │ │ │ │ └── LangDemo.java │ │ │ ├── dom4j │ │ │ │ ├── Dom4jTest.java │ │ │ │ └── test.xml │ │ │ ├── guava │ │ │ │ ├── CollectionsTest.java │ │ │ │ ├── CommonUsage.java │ │ │ │ ├── OptionalTest.java │ │ │ │ ├── PreconditionsTest.java │ │ │ │ └── test.txt │ │ │ ├── guice │ │ │ │ ├── HelloApp.java │ │ │ │ └── service │ │ │ │ │ ├── BaseServer.java │ │ │ │ │ ├── HelloService.java │ │ │ │ │ └── impl │ │ │ │ │ └── HelloServiceImpl.java │ │ │ ├── httpclient │ │ │ │ └── HttpClientGet.java │ │ │ ├── jmx │ │ │ │ ├── Hello.java │ │ │ │ ├── HelloAgent.java │ │ │ │ └── HelloMBean.java │ │ │ ├── jodaTime │ │ │ │ └── jodaCommonUsage.java │ │ │ ├── json │ │ │ │ ├── Map2Json.java │ │ │ │ ├── fastjson │ │ │ │ │ ├── bean │ │ │ │ │ │ ├── Group.java │ │ │ │ │ │ └── User.java │ │ │ │ │ └── test │ │ │ │ │ │ └── Test.java │ │ │ │ ├── gson │ │ │ │ │ ├── Bean1.java │ │ │ │ │ ├── Bean2.java │ │ │ │ │ └── TestGson.java │ │ │ │ └── test.java │ │ │ ├── jsonwebtokenjjwt │ │ │ │ └── JsonWebTokenJJWT.java │ │ │ ├── jwt │ │ │ │ ├── Jwt.java │ │ │ │ └── TestJWT.java │ │ │ ├── log4j │ │ │ │ ├── Test.java │ │ │ │ └── log4j2MySQL │ │ │ │ │ ├── Log4jDemo.java │ │ │ │ │ └── sql │ │ │ │ │ └── log4j.sql │ │ │ ├── netty │ │ │ │ └── day1 │ │ │ │ │ ├── EchoClient.java │ │ │ │ │ ├── EchoClientHandler.java │ │ │ │ │ ├── EchoServer.java │ │ │ │ │ └── EchoServerHandler.java │ │ │ ├── poi │ │ │ │ ├── POIExcelUtil.java │ │ │ │ └── TestPoiExcelUtil.java │ │ │ ├── rabbitmq │ │ │ │ ├── Receive.java │ │ │ │ └── Send.java │ │ │ ├── redisson │ │ │ │ ├── MyThread.java │ │ │ │ ├── RedissonUtil.java │ │ │ │ └── ResissonDistributedLockTest.java │ │ │ ├── rocketmq │ │ │ │ ├── Consumer.java │ │ │ │ └── Producer.java │ │ │ ├── sentinel │ │ │ │ └── SentinelSampleTest.java │ │ │ ├── spring │ │ │ │ └── aop │ │ │ │ │ ├── HelloWorld.java │ │ │ │ │ ├── HelloWorldImpl1.java │ │ │ │ │ ├── HelloWorldImpl2.java │ │ │ │ │ ├── LogHandler.java │ │ │ │ │ ├── MainTest.java │ │ │ │ │ └── TimeHandler.java │ │ │ └── zookeeper │ │ │ │ ├── ListAllNode.java │ │ │ │ └── ZooKeeperTest.java │ │ ├── java8inaction │ │ │ ├── Calculator.java │ │ │ ├── ContextTest.java │ │ │ ├── LambdaScopeTest.java │ │ │ ├── LambdaSort.java │ │ │ ├── Map2StringTest.java │ │ │ └── test_5_5 │ │ │ │ ├── TestCrcUtils.java │ │ │ │ ├── Trader.java │ │ │ │ └── Transaction.java │ │ ├── javaGaiShu │ │ │ ├── page73test5 │ │ │ │ └── Person.java │ │ │ ├── page91test20 │ │ │ │ └── JingTaiDaiMaKuai.java │ │ │ ├── test17 │ │ │ │ └── IsRen.java │ │ │ ├── test2 │ │ │ │ ├── AddButton.html │ │ │ │ └── AddButton.java │ │ │ └── test9 │ │ │ │ └── Scanner.java │ │ ├── javanet │ │ │ ├── GetHtml.java │ │ │ ├── JavaNetTest.java │ │ │ ├── RegxTest.java │ │ │ └── SubStrTest.java │ │ ├── jdk │ │ │ └── agent │ │ │ │ ├── AgentTest.java │ │ │ │ ├── CGlibAgent.java │ │ │ │ ├── DynamicAgent.java │ │ │ │ └── service │ │ │ │ ├── Fruit.java │ │ │ │ └── impl │ │ │ │ ├── Apple.java │ │ │ │ └── Orange.java │ │ ├── mybatis │ │ │ ├── SimplePojo │ │ │ │ ├── SimplePojo.java │ │ │ │ ├── SimplePojo.sql │ │ │ │ ├── SimplePojoDao.java │ │ │ │ ├── SimplePojoDao.xml │ │ │ │ └── SimplePojoService.java │ │ │ ├── mapper │ │ │ │ ├── AppointmentMapper.java │ │ │ │ └── BookMapper.java │ │ │ └── model │ │ │ │ ├── Appointment.java │ │ │ │ ├── AppointmentExample.java │ │ │ │ ├── AppointmentKey.java │ │ │ │ ├── Book.java │ │ │ │ └── BookExample.java │ │ ├── mybatisStudy │ │ │ ├── jdbc │ │ │ │ └── JdbcTest.java │ │ │ ├── no3 │ │ │ │ └── Mybatis3.java │ │ │ ├── no4 │ │ │ │ ├── dao │ │ │ │ │ ├── UserDao.java │ │ │ │ │ ├── UserDaoImpl.java │ │ │ │ │ └── UserDaoImplTest.java │ │ │ │ └── mapper │ │ │ │ │ ├── UserMapper.java │ │ │ │ │ └── UserMapperTest.java │ │ │ └── po │ │ │ │ ├── User.java │ │ │ │ ├── UserCustom.java │ │ │ │ └── UserQueryVo.java │ │ ├── nio │ │ │ ├── copyFile │ │ │ │ └── NIOCopy.java │ │ │ └── cs │ │ │ │ ├── NioClient.java │ │ │ │ └── NioServer.java │ │ ├── programLogicOfThinking │ │ │ ├── Part3StrEncode.java │ │ │ ├── Part4.java │ │ │ ├── Part5.java │ │ │ ├── Part6.java │ │ │ ├── README.md │ │ │ ├── basics │ │ │ │ └── Operation.java │ │ │ └── binaryAndBitwisePart2 │ │ │ │ └── BinaryAndBitwise.java │ │ ├── regex │ │ │ ├── IPTest.java │ │ │ ├── IsEmail.java │ │ │ └── PWD.java │ │ ├── string │ │ │ ├── File2Base64.java │ │ │ ├── FullHalf.java │ │ │ ├── String2Base64.java │ │ │ ├── StringSpecharsHandle.java │ │ │ ├── split │ │ │ │ ├── ReplacePhoneNumber.java │ │ │ │ ├── SplitLength.java │ │ │ │ ├── SplitString.java │ │ │ │ └── Str2List.java │ │ │ ├── stock │ │ │ │ └── GetStockInformation.java │ │ │ ├── stringbuilder │ │ │ │ └── TestSBDelete.java │ │ │ └── text │ │ │ │ ├── build.png │ │ │ │ ├── str2File.txt │ │ │ │ └── tomcat.png │ │ ├── test │ │ │ ├── Add.java │ │ │ ├── CodeCount.java │ │ │ ├── Dp.java │ │ │ ├── FileHeaderTest.java │ │ │ ├── GeometricProgression.java │ │ │ ├── GetPomVersion.java │ │ │ ├── NIO.java │ │ │ ├── NumberNotExit.java │ │ │ ├── RealProgrammer.java │ │ │ ├── RetryTime.java │ │ │ ├── SortStr.java │ │ │ ├── Sql.java │ │ │ ├── StreamForCompareTest.java │ │ │ ├── TestMap.java │ │ │ ├── TestMultithreadingSingleton.java │ │ │ ├── TestTrackSingleton.java │ │ │ ├── enum_test │ │ │ │ ├── Color.java │ │ │ │ └── UseEnum.java │ │ │ ├── scriptengine │ │ │ │ ├── ScriptTest.java │ │ │ │ └── model.js │ │ │ ├── snamu.java │ │ │ └── testShort.java │ │ ├── thinkingInJava │ │ │ └── chapter18 │ │ │ │ ├── DirList.java │ │ │ │ ├── DirList2.java │ │ │ │ └── DirList3.java │ │ ├── thread │ │ │ ├── AboutThreadPoolExecutor.java │ │ │ ├── CompletableFutureTest.java │ │ │ ├── ThreadPoolExample.java │ │ │ ├── count_click_by_redis │ │ │ │ ├── ClickRedis.java │ │ │ │ ├── CountClickByRedisThread.java │ │ │ │ └── Main.java │ │ │ ├── progressbar │ │ │ │ ├── 1.jpg │ │ │ │ └── ProgressBar.java │ │ │ ├── threadTest.java │ │ │ └── threadpool │ │ │ │ ├── TestThreadPool.java │ │ │ │ └── ThreadPool.java │ │ └── utils │ │ │ ├── Base64Util.java │ │ │ ├── BuildFileUtil.java │ │ │ ├── CallerAnalyze.java │ │ │ ├── CommonUtils.java │ │ │ ├── DateUtils.java │ │ │ ├── File2ByteArraysUtil.java │ │ │ ├── FileUtils.java │ │ │ ├── GetAllFileUtil.java │ │ │ ├── HttpClientUtil.java │ │ │ ├── JavaShellUtil.java │ │ │ ├── JedisUtil.java │ │ │ ├── ParseXMLUtil.java │ │ │ ├── SecureUtil.java │ │ │ └── ZipOrUnZipFileUtil.java │ │ └── translate │ │ ├── baidu │ │ ├── HttpGet.java │ │ ├── MD5.java │ │ ├── Main.java │ │ └── TransApi.java │ │ └── google │ │ └── QuickstartSample.java │ ├── resources │ ├── No3 │ │ ├── SqlMapConfig.xml │ │ └── mapper.xml │ ├── com │ │ └── hisen │ │ │ └── mybatis │ │ │ └── mapper │ │ │ ├── AppointmentMapper.xml │ │ │ └── BookMapper.xml │ ├── db.properties │ ├── files │ │ └── 1-150316141F4.gif │ ├── generator.properties │ ├── generatorConfig.xml │ ├── log4j.properties │ ├── spring │ │ └── aop │ │ │ └── spring-aop.xml │ └── sqlmap │ │ └── User.xml │ └── webapp │ ├── WEB-INF │ └── web.xml │ ├── firstJsp │ └── index.jsp │ └── index.jsp ├── ssm_study ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── hisen │ │ │ ├── dao │ │ │ ├── AppointmentDao.java │ │ │ └── BookDao.java │ │ │ ├── dto │ │ │ ├── AppointExecution.java │ │ │ └── Result.java │ │ │ ├── entity │ │ │ ├── Appointment.java │ │ │ └── Book.java │ │ │ ├── enums │ │ │ └── AppointStateEnum.java │ │ │ ├── exception │ │ │ ├── AppointException.java │ │ │ ├── NoNumberException.java │ │ │ └── RepeatAppointException.java │ │ │ ├── service │ │ │ ├── BookService.java │ │ │ └── impl │ │ │ │ └── BookServiceImpl.java │ │ │ └── web │ │ │ └── BookController.java │ ├── resources │ │ ├── jdbc.properties │ │ ├── logback.xml │ │ ├── mapper │ │ │ ├── AppointmentDao.xml │ │ │ ├── BookDao.xml │ │ │ └── sql │ │ │ │ └── ssm_study.sql │ │ ├── mybatis-config.xml │ │ └── spring │ │ │ ├── spring-dao.xml │ │ │ ├── spring-service.xml │ │ │ └── spring-web.xml │ └── webapp │ │ ├── WEB-INF │ │ ├── jsp │ │ │ ├── detail.jsp │ │ │ └── list.jsp │ │ └── web.xml │ │ ├── add.jsp │ │ ├── appoint.jsp │ │ ├── images │ │ └── avator.jpg │ │ └── index.jsp │ └── test │ └── java │ └── com │ └── hisen │ └── test │ ├── AppointmentDaoTest.java │ ├── BaseTest.java │ ├── BookDaoTest.java │ └── BookServiceImplTest.java └── websocket-demo ├── README.md ├── pom.xml └── src └── main ├── java └── com │ └── hisen │ ├── netty │ ├── ClientApp4Java.java │ ├── NettyWebSocketServer.java │ ├── SocketHandler.java │ ├── UserInfo.java │ ├── UserInfoManager.java │ └── chat.html │ └── ws │ ├── client │ └── ClientApp4Java.java │ ├── server │ └── WebSocketServer.java │ └── util │ └── Constants.java └── webapp ├── WEB-INF └── web.xml ├── hisen.jsp └── index.jsp /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | log 3 | *.iml 4 | target -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IDEAPractice 2 | idea上的一些练习 3 | 4 | # src/main 5 | 这个是一些平时的小练习 6 | 7 | 各种简单的例子集合 8 | 9 | # ssm_study 10 | 开发工具:IntelliJ IDEA 11 | 12 | maven:3.3.9 13 | 14 | jdk:1.8 15 | 16 | Spring:4.1.7 17 | 18 | Mybatis:3.3.0 19 | 20 | 这个项目只是一个简单的搭建SSM框架 21 | 22 | 建表语句在resources/mapper/下 23 | 24 | 实现了CRUD,jsp页面是用了下bootstrap 25 | 26 | # 个人渣渣博客 27 | http://hisen.me 28 | -------------------------------------------------------------------------------- /jwt-sample/src/main/java/com/hisen/jwt/controller/MainController.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jwt.controller; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.hisen.jwt.entity.LoginReq; 5 | import com.hisen.jwt.entity.LoginRes; 6 | import com.hisen.jwt.service.LoginService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | 13 | /** 14 | * @author : hisenyuan 15 | * @date : 2018/3/16 23:02 16 | * @descriptor : 17 | */ 18 | @Controller 19 | @RequestMapping("/hisen") 20 | public class MainController { 21 | @Autowired 22 | LoginService loginService; 23 | 24 | 25 | @RequestMapping(value = "/login", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8") 26 | @ResponseBody 27 | public String login(LoginReq req){ 28 | LoginRes login = loginService.login(req); 29 | return JSON.toJSONString(login); 30 | } 31 | @RequestMapping(value = "/test", method = RequestMethod.GET, produces = "text/plain;charset=UTF-8") 32 | @ResponseBody 33 | public String test(LoginReq req){ 34 | 35 | return "hisenyuan"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /jwt-sample/src/main/java/com/hisen/jwt/entity/CommonResponse.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jwt.entity; 2 | 3 | /** 4 | * Created by hisen on 17-8-26. 5 | * E-mail: hisenyuan@gmail.com 6 | */ 7 | public class CommonResponse { 8 | 9 | private int resCode; 10 | private String resMsg; 11 | 12 | public int getResCode() { 13 | return resCode; 14 | } 15 | 16 | public void setResCode(int resCode) { 17 | this.resCode = resCode; 18 | } 19 | 20 | public String getResMsg() { 21 | return resMsg; 22 | } 23 | 24 | public void setResMsg(String resMsg) { 25 | this.resMsg = resMsg; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jwt-sample/src/main/java/com/hisen/jwt/entity/LoginReq.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jwt.entity; 2 | 3 | /** 4 | * @author : hisenyuan 5 | * @date : 2018/3/16 23:04 6 | * @descriptor : 7 | */ 8 | public class LoginReq { 9 | private String userName; 10 | private String pwd; 11 | 12 | public String getUserName() { 13 | return userName; 14 | } 15 | 16 | public void setUserName(String userName) { 17 | this.userName = userName; 18 | } 19 | 20 | public String getPwd() { 21 | return pwd; 22 | } 23 | 24 | public void setPwd(String pwd) { 25 | this.pwd = pwd; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jwt-sample/src/main/java/com/hisen/jwt/entity/LoginRes.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jwt.entity; 2 | 3 | /** 4 | * @author : hisenyuan 5 | * @date : 2018/3/16 23:27 6 | * @descriptor : 7 | */ 8 | public class LoginRes { 9 | private String code = "0000"; 10 | private String msg; 11 | private String jwt; 12 | private String userName; 13 | 14 | public String getCode() { 15 | return code; 16 | } 17 | 18 | public void setCode(String code) { 19 | this.code = code; 20 | } 21 | 22 | public String getMsg() { 23 | return msg; 24 | } 25 | 26 | public void setMsg(String msg) { 27 | this.msg = msg; 28 | } 29 | 30 | public String getJwt() { 31 | return jwt; 32 | } 33 | 34 | public void setJwt(String jwt) { 35 | this.jwt = jwt; 36 | } 37 | 38 | public String getUserName() { 39 | return userName; 40 | } 41 | 42 | public void setUserName(String userName) { 43 | this.userName = userName; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /jwt-sample/src/main/java/com/hisen/jwt/service/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jwt.service; 2 | 3 | import com.hisen.jwt.entity.LoginReq; 4 | import com.hisen.jwt.entity.LoginRes; 5 | 6 | /** 7 | * @author : hisenyuan 8 | * @date : 2018/3/16 23:17 9 | * @descriptor : 10 | */ 11 | public interface LoginService { 12 | LoginRes login(LoginReq req); 13 | } 14 | -------------------------------------------------------------------------------- /jwt-sample/src/main/resources/jwt.properties: -------------------------------------------------------------------------------- 1 | secret=hisenyuan-yhx-test-secret 2 | userName=hisen 3 | pwd=hisen 4 | isLogin=1 -------------------------------------------------------------------------------- /jwt-sample/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jwt-sample/src/main/resources/spring/spring-cors.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /jwt-sample/src/main/webapp/hisenyuan.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | hisenyuan 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 18 |
19 |
20 |
21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /jwt-sample/src/main/webapp/hisenyuan.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by hisen on 17-8-26. 3 | */ 4 | $.ajax({ 5 | type: "GET", 6 | url: "http://localhost:8080/hisen/test", 7 | async: false, 8 | headers: { 9 | "Authorization":localStorage.getItem("jwt") 10 | }, 11 | success: function(result) { 12 | $("#hisenyuan").text(result); 13 | alert(1 ) 14 | } 15 | }); -------------------------------------------------------------------------------- /jwt-sample/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /jwt-sample/src/main/webapp/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 |
18 | 19 |
20 |
21 | 22 |
23 | 24 |
25 |
26 |
27 |
28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /jwt-sample/src/main/webapp/login.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by hisen on 17-8-26. 3 | */ 4 | 5 | var frm = $('#form'); 6 | frm.submit(function (ev) { 7 | $.ajax({ 8 | type: "post", 9 | url: "http://localhost:8080/hisen/login", 10 | data: frm.serialize(), 11 | success:function(data) { 12 | console.log(data) 13 | var json = jQuery.parseJSON(data); 14 | var jwt = json.jwt; 15 | var kv = $.base64.decode(jwt.split('.')[1]); 16 | var info = jQuery.parseJSON(kv); 17 | // 登录成功,存储令牌到本地 18 | localStorage.setItem("jwt",jwt) 19 | alert(localStorage.getItem("jwt")); 20 | 21 | window.location.href="./hisenyuan.html"; 22 | }, 23 | error:function(data){ 24 | console.log(data) 25 | } 26 | }); 27 | ev.preventDefault(); 28 | }); 29 | 30 | -------------------------------------------------------------------------------- /readinglist/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /readinglist/src/main/java/com/hisen/ReadinglistApplication.java: -------------------------------------------------------------------------------- 1 | package com.hisen; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 应用程序启动引导类,也是主要的Spring配置类 8 | */ 9 | /** 10 | * 开启组件扫描和自动配置 其实包含了三个注解 11 | * @Configuration 12 | * @ComponentScan 13 | * @EnableAutoConfiguration 14 | */ 15 | @SpringBootApplication 16 | public class ReadinglistApplication { 17 | 18 | public static void main(String[] args) { 19 | //负责启动引导应用程序 20 | SpringApplication.run(ReadinglistApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /readinglist/src/main/java/com/hisen/conditions/JdbcTemplateCondition.java: -------------------------------------------------------------------------------- 1 | package com.hisen.conditions; 2 | 3 | import org.springframework.context.annotation.Condition; 4 | import org.springframework.context.annotation.ConditionContext; 5 | import org.springframework.core.type.AnnotatedTypeMetadata; 6 | 7 | /** 8 | * Created by hisenyuan on 2017/7/13 at 23:00. 9 | * 10 | * 当classpath里有dbcTemplate,加了这个注解的类才会被创建为bean 11 | * 如下所示 12 | */ 13 | //@Conditional(JdbcTemplateCondition.class) 14 | public class JdbcTemplateCondition implements Condition { 15 | 16 | @Override 17 | public boolean matches(ConditionContext context, 18 | AnnotatedTypeMetadata metadata) { 19 | try { 20 | context.getClassLoader().loadClass("org.springframework.jdbc.core.JdbcTemplate"); 21 | return true; 22 | } catch (ClassNotFoundException e) { 23 | e.printStackTrace(); 24 | } 25 | return false; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /readinglist/src/main/java/com/hisen/dao/ReadingListRepository.java: -------------------------------------------------------------------------------- 1 | package com.hisen.dao; 2 | 3 | import com.hisen.entity.Book; 4 | import java.util.List; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | /** 8 | * Created by hisenyuan on 2017/7/13 at 20:17. 9 | */ 10 | 11 | /** 12 | * ReadingListRepository 直接继承了18个执行常用持久化操作的方法 13 | * JpaRepository 是一个泛型接口 14 | * 两个参数: 仓库操作的领域对象模型,及其ID熟悉的类型 15 | */ 16 | public interface ReadingListRepository extends JpaRepository { 17 | 18 | List findByReader(String reader); 19 | } 20 | -------------------------------------------------------------------------------- /readinglist/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #配置文件,默认为空 2 | server.port=8000 -------------------------------------------------------------------------------- /readinglist/src/main/resources/static/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-color: #cccccc; 3 | font-family: Arial,sans-serif; 4 | } 5 | 6 | .bookHeadline{ 7 | font-size: 12pt; 8 | font-weight: bold; 9 | } 10 | 11 | .bookDecsription{ 12 | font-size: 10pt; 13 | } 14 | 15 | label{ 16 | font-weight: bold; 17 | } -------------------------------------------------------------------------------- /readinglist/src/main/resources/templates/readingList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Reading List 5 | 6 | 7 | 8 |

Your Reading List

9 |
10 |
11 |
12 | Title by 13 | Author 14 | (ISBN:ISBN) 15 |
16 |
17 | Description 18 | No Description Available 19 |
20 |
21 |
22 |
23 |

you have no book in you book list

24 |
25 | 26 |
27 |

Add a book

28 |
29 | 30 |
31 | 32 |
33 | 34 |
35 |
36 |
37 | 38 |
39 | 40 | -------------------------------------------------------------------------------- /readinglist/src/test/java/com/hisen/ReadinglistApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.hisen; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | /** 9 | * 集成测试类 10 | */ 11 | @RunWith(SpringRunner.class) 12 | @SpringBootTest 13 | public class ReadinglistApplicationTests { 14 | 15 | @Test 16 | public void contextLoads() { 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/Objects/bean/Student.java: -------------------------------------------------------------------------------- 1 | package com.hisen.Objects.bean; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/3/21 at 15:07. 5 | */ 6 | public class Student { 7 | 8 | private String name; 9 | private Integer age; 10 | 11 | public Student(String name, Integer age) { 12 | this.name = name; 13 | this.age = age; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | public Integer getAge() { 25 | return age; 26 | } 27 | 28 | public void setAge(Integer age) { 29 | this.age = age; 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | return this.getAge(); 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) { 40 | return true; 41 | } 42 | if (obj == null) { 43 | return false; 44 | } 45 | if (getClass() != obj.getClass()) { 46 | return false; 47 | } 48 | 49 | Student other = (Student) obj; 50 | if (name == null) { 51 | if (other.name != null) { 52 | return false; 53 | } 54 | } else if (!name.equals(other.name)) { 55 | return false; 56 | } 57 | return true; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/Reflect/ReflectDemo.java: -------------------------------------------------------------------------------- 1 | package com.hisen.Reflect; 2 | 3 | /** 4 | * 三种获取反射累的方法 5 | * Created by hisenyuan on 2017/4/14 at 10:37. 6 | */ 7 | public class ReflectDemo { 8 | 9 | public static void main(String[] args) throws ClassNotFoundException { 10 | //第一种:Class c1 = Code.class; 11 | Class class1 = ReflectDemo.class; 12 | System.out.println(class1.getName()); 13 | 14 | //第二种:Class c2 = code1.getClass(); 15 | ReflectDemo demo2 = new ReflectDemo(); 16 | Class c2 = demo2.getClass(); 17 | System.out.println(c2.getName()); 18 | 19 | //第三种:Class c3 = Class.forName("com.trigl.reflect.Code"); 20 | Class class3 = Class.forName("com.hisen.Reflect.ReflectDemo"); 21 | System.out.println(class3.getName()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/Reflect/get/Person.java: -------------------------------------------------------------------------------- 1 | package com.hisen.Reflect.get; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/14 at 10:42. 5 | */ 6 | public class Person { 7 | 8 | private String name; 9 | private int age; 10 | private String msg = "hello wrold"; 11 | 12 | public Person(String name) { 13 | this.name = name; 14 | System.out.println(name); 15 | } 16 | 17 | public Person() { 18 | } 19 | 20 | public String getName() { 21 | 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public int getAge() { 30 | return age; 31 | } 32 | 33 | public void setAge(int age) { 34 | this.age = age; 35 | } 36 | 37 | public void fun() { 38 | System.out.println("这是一个没有参数的fun方法"); 39 | } 40 | 41 | public void fun(String name, int age) { 42 | System.out.println("我叫" + name + ",今年" + age + "岁"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/algorithms/Permutations.java: -------------------------------------------------------------------------------- 1 | package com.hisen.algorithms; 2 | 3 | /** 4 | * @Author hisenyuan 5 | * @Description 全排列 6 | * @Date 2019/4/7 22:02 7 | */ 8 | public class Permutations { 9 | public static void main(String[] args) { 10 | int[] arr = {1, 2, 3, 4}; 11 | fullPermutation(arr, 0, arr.length - 1); 12 | } 13 | 14 | private static void fullPermutation(int[] data, int start, int end) { 15 | if (start == end) { 16 | final StringBuilder sb = new StringBuilder(); 17 | for (int i : data) { 18 | sb.append(i); 19 | } 20 | System.out.println(sb.toString()); 21 | return; 22 | } 23 | for (int i = start; i <= end; i++) { 24 | swap(data, i, start); 25 | fullPermutation(data, start + 1, end); 26 | swap(data, i, start); 27 | } 28 | } 29 | 30 | private static void swap(int[] arr, int i, int j) { 31 | if (i == j) { 32 | return; 33 | } 34 | int tmp = arr[i]; 35 | arr[i] = arr[j]; 36 | arr[j] = tmp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/algorithms/RotateArray.java: -------------------------------------------------------------------------------- 1 | package com.hisen.algorithms; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * @Author hisenyuan 9 | * @Description Rotate Array https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/646/ 10 | * @Date 2019/4/26 16:02 11 | */ 12 | public class RotateArray { 13 | @Test 14 | public void testRotate() { 15 | int[] nums = {1, 2, 3, 4, 5, 6, 7}; 16 | int k = 9; 17 | rotate(nums, k); 18 | System.out.println(Arrays.toString(nums)); 19 | } 20 | 21 | private void rotate(int[] nums, int k) { 22 | final int length = nums.length; 23 | if (k > length) { 24 | k = k % length; 25 | } 26 | 27 | int[] tmp = new int[k]; 28 | 29 | System.arraycopy(nums, length - k, tmp, 0, k); 30 | 31 | for (int i = length - 1; i >= 0; i--) { 32 | if (i >= k) { 33 | nums[i] = nums[i - k]; 34 | } else { 35 | nums[i] = tmp[i]; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/algorithms/leetcode/MoveZeroes.java: -------------------------------------------------------------------------------- 1 | package com.hisen.algorithms.leetcode; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * @author hisenyuan 9 | * @date 2019-10-23 17:40 10 | * url:https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/567/ 11 | */ 12 | public class MoveZeroes { 13 | @Test 14 | public void testMoveZeros() { 15 | int[] oriArray = {0, 0, 0, 0, 12, 0}; 16 | moveZeroes(oriArray); 17 | System.out.println(Arrays.toString(oriArray)); 18 | } 19 | 20 | private void moveZeroes(int[] nums) { 21 | int zeroCount = 0; 22 | for (int value : nums) { 23 | if (value == 0) { 24 | zeroCount = zeroCount + 1; 25 | } 26 | } 27 | while (zeroCount-- >= 0) { 28 | for (int i = 0; i < nums.length; i++) { 29 | if (nums[i] == 0 && i + 1 < nums.length) { 30 | int tmp = nums[i + 1]; 31 | nums[i + 1] = nums[i]; 32 | nums[i] = tmp; 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/algorithms/sort/SortingAlgorithms.java: -------------------------------------------------------------------------------- 1 | package com.hisen.algorithms.sort; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.junit.Test; 6 | 7 | /** 8 | * @author : yhx 9 | * @date : 2017/11/7 16:24 10 | * @descriptor : 排序算法 11 | */ 12 | public class SortingAlgorithms { 13 | 14 | /** 15 | * 最简单的冒泡排序 16 | */ 17 | @Test 18 | public void bubbleSort() { 19 | int[] numbers = {3, 6, 2, 4, 5, 1, 7, 9, 8}; 20 | int temp = 0; 21 | int len = numbers.length; 22 | for (int i = 0; i < len - 1; i++) { 23 | for (int j = 0; j < len - 1 - i; j++) { 24 | if (numbers[j] > numbers[j + 1]) { 25 | temp = numbers[j]; 26 | numbers[j] = numbers[j + 1]; 27 | numbers[j + 1] = temp; 28 | } 29 | } 30 | } 31 | System.out.println(Arrays.toString(numbers)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/algorithms/sort/java8Test.java: -------------------------------------------------------------------------------- 1 | package com.hisen.algorithms.sort; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | /** 8 | * @author : yhx 9 | * @date : 2017/11/26 22:29 10 | * @descriptor : lambda表达式排序算法 11 | */ 12 | public class java8Test { 13 | 14 | public static void main(String args[]) { 15 | 16 | List names1 = new ArrayList(); 17 | names1.add("Google"); 18 | names1.add("W3CSchool"); 19 | names1.add("Taobao"); 20 | names1.add("Baidu"); 21 | names1.add("Sina"); 22 | 23 | List names2 = new ArrayList(); 24 | names2.add("Google"); 25 | names2.add("W3CSchool"); 26 | names2.add("Taobao"); 27 | names2.add("Baidu"); 28 | names2.add("Sina"); 29 | 30 | java8Test tester = new java8Test(); 31 | System.out.println("使用 Java 7 语法: "); 32 | tester.sortUsingJava7(names1); 33 | System.out.println(names1); 34 | 35 | System.out.println("使用 Java 8 语法: "); 36 | tester.sortUsingJava8(names2); 37 | System.out.println(names2); 38 | } 39 | 40 | // 使用 java 7 排序 41 | private void sortUsingJava7(List names) { 42 | Collections.sort(names, new Comparator() { 43 | @Override 44 | public int compare(String s1, String s2) { 45 | return s1.compareTo(s2); 46 | } 47 | }); 48 | } 49 | 50 | // 使用 java 8 排序 51 | private void sortUsingJava8(List names) { 52 | names.sort(String::compareTo); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/api/douban/bean/Images.java: -------------------------------------------------------------------------------- 1 | package com.hisen.api.douban.bean; 2 | 3 | /** 4 | * 图书封面URL 5 | * Created by hisen on 17-9-8. 6 | * E-mail: hisenyuan@gmail.com 7 | */ 8 | public class Images { 9 | 10 | /** 11 | * 小 12 | */ 13 | private String small; 14 | /** 15 | * 大 16 | */ 17 | private String large; 18 | /** 19 | * 中 20 | */ 21 | private String medium; 22 | 23 | public String getSmall() { 24 | return small; 25 | } 26 | 27 | public void setSmall(String small) { 28 | this.small = small; 29 | } 30 | 31 | public String getLarge() { 32 | return large; 33 | } 34 | 35 | public void setLarge(String large) { 36 | this.large = large; 37 | } 38 | 39 | public String getMedium() { 40 | return medium; 41 | } 42 | 43 | public void setMedium(String medium) { 44 | this.medium = medium; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/api/douban/bean/Rating.java: -------------------------------------------------------------------------------- 1 | package com.hisen.api.douban.bean; 2 | 3 | /** 4 | * Created by hisen on 17-9-8. 5 | * E-mail: hisenyuan@gmail.com 6 | */ 7 | public class Rating { 8 | 9 | /** 10 | * 最高分 11 | */ 12 | private int max; 13 | /** 14 | * 打分人数 15 | */ 16 | private int numRaters; 17 | /** 18 | * 平均分 19 | */ 20 | private String average; 21 | /** 22 | * 最低分 23 | */ 24 | private int min; 25 | 26 | public int getMax() { 27 | return max; 28 | } 29 | 30 | public void setMax(int max) { 31 | this.max = max; 32 | } 33 | 34 | public int getNumRaters() { 35 | return numRaters; 36 | } 37 | 38 | public void setNumRaters(int numRaters) { 39 | this.numRaters = numRaters; 40 | } 41 | 42 | public String getAverage() { 43 | return average; 44 | } 45 | 46 | public void setAverage(String average) { 47 | this.average = average; 48 | } 49 | 50 | public int getMin() { 51 | return min; 52 | } 53 | 54 | public void setMin(int min) { 55 | this.min = min; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/api/douban/bean/Tag.java: -------------------------------------------------------------------------------- 1 | package com.hisen.api.douban.bean; 2 | 3 | /** 4 | * 标签 5 | * Created by hisen on 17-9-8. 6 | * E-mail: hisenyuan@gmail.com 7 | */ 8 | public class Tag { 9 | 10 | /** 11 | * 标签次数 12 | */ 13 | private int count; 14 | /** 15 | * 标签名字 16 | */ 17 | private String name; 18 | /** 19 | * 标签标题 20 | */ 21 | private String title; 22 | 23 | public int getCount() { 24 | return count; 25 | } 26 | 27 | public void setCount(int count) { 28 | this.count = count; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getTitle() { 40 | return title; 41 | } 42 | 43 | public void setTitle(String title) { 44 | this.title = title; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/collection/list/ArrayListTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.collection.list; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.ListIterator; 6 | 7 | public class ArrayListTest { 8 | 9 | public static void main(String[] args) { 10 | List al = new ArrayList(); 11 | al.add(1); 12 | al.add(5); 13 | al.add(10); 14 | al.add(100); 15 | //移除下标为0的元素 16 | al.remove(0); 17 | //设置下标为1的元素值为99 18 | al.set(1, 99); 19 | 20 | int size = al.size(); 21 | Boolean flag = al.isEmpty(); 22 | int a = al.get(0); 23 | 24 | ListIterator li = al.listIterator(); 25 | while (li.hasNext()) { 26 | System.out.println(li.next()); 27 | } 28 | System.out.println("al的大小:" + size + ";al为空:" + flag + ";al的第一个元素:" + a); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/collection/list/aboutlist/PrintArray.java: -------------------------------------------------------------------------------- 1 | package com.hisen.collection.list.aboutlist; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * 数组简单的打印方法 7 | * 一维数组:Arrays.toString 8 | * 二维数组:Arrays.deepToString 9 | * 10 | * @author hisenyuan 2016年4月22日 下午6:29:31 11 | */ 12 | public class PrintArray { 13 | 14 | public static void main(String[] args) { 15 | String[] arrayStr = new String[]{"Java", "Node", "Python", "Ruby"}; 16 | System.out.println(Arrays.toString(arrayStr)); 17 | // Output :[Java, Node, Python, Ruby] 18 | 19 | int[] arrayInt = {1, 3, 5, 7, 9}; 20 | System.out.println(Arrays.toString(arrayInt)); 21 | // Output : [1, 3, 5, 7, 9] 22 | 23 | String[][] deepArrayStr = new String[][]{{"yiibai1", "yiibai2"}, {"yiibai3", "yiibai4"}}; 24 | System.out.println(Arrays.deepToString(deepArrayStr)); 25 | // Output : [[yiibai1, yiibai2], [yiibai3, yiibai4] 26 | 27 | int[][] deepArrayInt = new int[][]{{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}}; 28 | System.out.println(Arrays.deepToString(deepArrayInt)); 29 | // Output : [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]] 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/collection/list/aboutlist/hisen.java: -------------------------------------------------------------------------------- 1 | package com.hisen.collection.list.aboutlist; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class hisen { 7 | 8 | public static void main(String[] args) { 9 | List list = new ArrayList(); 10 | list.add("1.txt"); 11 | list.add("2.txt"); 12 | list.add("3.txt"); 13 | String s = listToString(list, "|"); 14 | String h = ""; 15 | for (String yhx : list) { 16 | h += "|" + yhx; 17 | } 18 | System.out.println(s);// 1.txt|2.txt|3.txt 19 | System.out.println(h);// |1.txt|2.txt|3.txt 20 | } 21 | 22 | /** 23 | * List转字符串并且加入分隔符的方法 24 | * 25 | * @param separator 分隔符 26 | */ 27 | public static String listToString(List list, String separator) { 28 | String sb = ""; 29 | for (int i = 0; i < list.size(); i++) { 30 | sb += list.get(i) + separator; 31 | } 32 | /** 33 | * 去掉多余的分隔符,截取想要的 34 | * 去掉最后那个 | :substring(1, sb.toString().length()); 35 | * 如果多余的分隔符在最后一位:substring(0, sb.toString().length()-1); 36 | */ 37 | return sb.substring(0, sb.toString().length() - 1); 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/collection/list/aboutlist/list1.java: -------------------------------------------------------------------------------- 1 | package com.hisen.collection.list.aboutlist; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class list1 { 6 | 7 | public static void main(String[] args) { 8 | ArrayList list = new ArrayList(); 9 | String[] a = new String[2]; 10 | a[0] = "a"; 11 | a[1] = "b"; 12 | list.add(a); 13 | System.out.println(((String[]) list.get(0))[0]); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/collection/list/duplicate/PersonBean.java: -------------------------------------------------------------------------------- 1 | package com.hisen.collection.list.duplicate; 2 | 3 | /** 4 | * @author hisenyuan 5 | * @time 2018/2/7 12:39 6 | * @description 7 | */ 8 | public class PersonBean { 9 | private int age; 10 | private String name; 11 | private int weight; 12 | 13 | public int getAge() { 14 | return age; 15 | } 16 | 17 | public void setAge(int age) { 18 | this.age = age; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public int getWeight() { 30 | return weight; 31 | } 32 | 33 | public PersonBean() { 34 | } 35 | 36 | public PersonBean(int age, String name, int weight) { 37 | this.age = age; 38 | this.name = name; 39 | this.weight = weight; 40 | } 41 | 42 | public void setWeight(int weight) { 43 | this.weight = weight; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/copy/smaller/bean/Address.java: -------------------------------------------------------------------------------- 1 | package com.hisen.copy.smaller.bean; 2 | 3 | /** 4 | * @author hisenyuan 5 | * @date 2020-09-26 14:42 6 | */ 7 | public class Address { 8 | private String province; 9 | private String city; 10 | private String county; 11 | 12 | public String getProvince() { 13 | return province; 14 | } 15 | 16 | public void setProvince(String province) { 17 | this.province = province; 18 | } 19 | 20 | public String getCity() { 21 | return city; 22 | } 23 | 24 | public void setCity(String city) { 25 | this.city = city; 26 | } 27 | 28 | public String getCounty() { 29 | return county; 30 | } 31 | 32 | public void setCounty(String county) { 33 | this.county = county; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/copy/smaller/bean/Order.java: -------------------------------------------------------------------------------- 1 | package com.hisen.copy.smaller.bean; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author hisenyuan 7 | * @date 2020-09-26 14:44 8 | */ 9 | public class Order { 10 | private String orderId; 11 | private Address address; 12 | private List productInfos; 13 | 14 | public String getOrderId() { 15 | return orderId; 16 | } 17 | 18 | public void setOrderId(String orderId) { 19 | this.orderId = orderId; 20 | } 21 | 22 | public Address getAddress() { 23 | return address; 24 | } 25 | 26 | public void setAddress(Address address) { 27 | this.address = address; 28 | } 29 | 30 | public List getProductInfos() { 31 | return productInfos; 32 | } 33 | 34 | public void setProductInfos(List productInfos) { 35 | this.productInfos = productInfos; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/copy/smaller/bean/ProductInfo.java: -------------------------------------------------------------------------------- 1 | package com.hisen.copy.smaller.bean; 2 | 3 | import java.math.BigDecimal; 4 | 5 | /** 6 | * @author hisenyuan 7 | * @date 2020-09-26 14:45 8 | */ 9 | public class ProductInfo { 10 | private long productId; 11 | private String name; 12 | private BigDecimal price; 13 | private BigDecimal discount; 14 | private int num; 15 | private String imgUrl; 16 | 17 | public long getProductId() { 18 | return productId; 19 | } 20 | 21 | public void setProductId(long productId) { 22 | this.productId = productId; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public BigDecimal getPrice() { 34 | return price; 35 | } 36 | 37 | public void setPrice(BigDecimal price) { 38 | this.price = price; 39 | } 40 | 41 | public BigDecimal getDiscount() { 42 | return discount; 43 | } 44 | 45 | public void setDiscount(BigDecimal discount) { 46 | this.discount = discount; 47 | } 48 | 49 | public int getNum() { 50 | return num; 51 | } 52 | 53 | public void setNum(int num) { 54 | this.num = num; 55 | } 56 | 57 | public String getImgUrl() { 58 | return imgUrl; 59 | } 60 | 61 | public void setImgUrl(String imgUrl) { 62 | this.imgUrl = imgUrl; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/databases/mysql/jdbc/AddData.java: -------------------------------------------------------------------------------- 1 | package com.hisen.databases.mysql.jdbc; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | import java.sql.Statement; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Created by hisenyuan on 2017/5/16 at 16:27. 10 | */ 11 | public class AddData { 12 | 13 | private static String url = "jdbc:mysql://127.0.0.1:3306/hisen?user=root&password=hisen&useUnicode=true&characterEncoding=UTF8"; 14 | 15 | /** 16 | * 添加20万数据 17 | */ 18 | @Test 19 | public void addData() { 20 | Connection connect = DBUtils.getConnect(url); 21 | String[] arr = {"标题", "内容"}; 22 | for (int i = 0; i < 10000; i++) { 23 | for (int j = 0; j < 20; j++) { 24 | StringBuilder sb = new StringBuilder(); 25 | sb.append("insert into post(title,content) values('"); 26 | sb.append(arr[0] + j).append("','").append(arr[1] + j).append("');"); 27 | System.out.println(sb.toString()); 28 | try { 29 | Statement statement = connect.createStatement(); 30 | int i1 = statement.executeUpdate(sb.toString()); 31 | } catch (SQLException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/databases/mysql/jdbc/DBUtils.java: -------------------------------------------------------------------------------- 1 | package com.hisen.databases.mysql.jdbc; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | 7 | /** 8 | * Created by hisenyuan on 2017/5/16 at 15:55. 9 | */ 10 | public class DBUtils { 11 | 12 | /** 13 | * 获得连接 14 | * @param URL 15 | */ 16 | public static Connection getConnect(String URL) { 17 | Connection connection = null; 18 | try { 19 | Class.forName("com.mysql.jdbc.Driver"); 20 | System.out.println("mysql has connected!"); 21 | connection = DriverManager.getConnection(URL); 22 | return connection; 23 | } catch (ClassNotFoundException e) { 24 | e.printStackTrace(); 25 | System.out.println(e); 26 | } catch (SQLException e) { 27 | System.out.println(e); 28 | e.printStackTrace(); 29 | } 30 | return connection; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/Singleton.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/9 21:18 6 | * @descriptor : 单例模式 7 | */ 8 | public class Singleton { 9 | 10 | private static Singleton instance; 11 | 12 | /** 13 | * 懒汉模式 14 | */ 15 | public static Singleton getInstance() { 16 | if (instance == null) { 17 | instance = new Singleton(); 18 | } 19 | return instance; 20 | } 21 | 22 | //将构造器使用private修饰,隐藏该构造器 23 | private Singleton() { 24 | System.out.println("Singleton被构造!"); 25 | } 26 | 27 | public static void main(String[] args) { 28 | // 获取两个实例,最终输入的结果为 true 29 | Singleton singleton1 = Singleton.getInstance(); 30 | Singleton singleton2 = Singleton.getInstance(); 31 | // 比较两个对象是否相等 32 | System.out.println(singleton1==singleton2); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/proxy/dynamicproxy/DynamicProxy.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.proxy.dynamicproxy; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | 6 | /** 7 | * @author : yhx 8 | * @date : 2017/11/9 21:58 9 | * @descriptor : 动态代理 - 利用反射原理 10 | */ 11 | public class DynamicProxy implements InvocationHandler { 12 | // 被代理的对象 13 | Object object; 14 | 15 | // 将被代理的类传给动态代理类构造函数中 16 | public DynamicProxy(Object object) { 17 | this.object = object; 18 | } 19 | 20 | /** 21 | * 覆盖InvocationHandler接口中的invoke()方法 22 | * 在不改变原有代码的情况下进行扩展 23 | * 下面的before、after就是我们可以进行特殊代码切入的扩展点了。 24 | */ 25 | @Override 26 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 27 | // before 28 | Object result = method.invoke(this.object, args); 29 | // after 30 | return result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/proxy/dynamicproxy/DynamicProxyMain.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.proxy.dynamicproxy; 2 | 3 | import com.hisen.designpattern.proxy.staticproxy.BuyCar; 4 | import com.hisen.designpattern.proxy.staticproxy.Customser; 5 | import java.lang.reflect.InvocationHandler; 6 | import java.lang.reflect.Proxy; 7 | 8 | /** 9 | * @author : yhx 10 | * @date : 2017/11/9 22:03 11 | * @descriptor : 动态代理测试类 12 | */ 13 | public class DynamicProxyMain { 14 | 15 | /** 16 | * 动态代理好处 17 | * 使用Java动态代理机制的好处: 18 | * 1、减少编程的工作量:假如需要实现多种代理处理逻辑, 19 | * 只要写多个代理处理器就可以了,无需每种方式都写一个代理类。 20 | * 2、系统扩展性和维护性增强,程序修改起来也方便多了(一般只要改代理处理器类就行了)。 21 | * @param args 22 | */ 23 | public static void main(String[] args) { 24 | // 要代理的真实对象 25 | Customser customser = new Customser(); 26 | customser.setCash(100000); 27 | // 我们要代理那个对象,就把这个对象传进去,最后是通过该对象来调用其他方法 28 | InvocationHandler handler = new DynamicProxy(customser); 29 | // 简单的模拟,于是这里顾客是直接买车的,没有通过4S店 30 | BuyCar buyCarHandler = (BuyCar) Proxy.newProxyInstance(handler.getClass().getClassLoader(),customser.getClass().getInterfaces(),handler); 31 | buyCarHandler.buyCar(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/proxy/staticproxy/BuyCar.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.proxy.staticproxy; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/9 21:41 6 | * @descriptor : 静态代理模式买车接口 7 | */ 8 | public interface BuyCar { 9 | 10 | /** 11 | * 买车 12 | */ 13 | public void buyCar(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/proxy/staticproxy/BuyCarMain.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.proxy.staticproxy; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/9 21:48 6 | * @descriptor : 静态代理模式测试类 - 顾客通过4S店买车 7 | */ 8 | public class BuyCarMain { 9 | 10 | /** 11 | * 通过代理模式可以方便的对一些现有方法进行扩展 12 | * @param args 13 | */ 14 | public static void main(String[] args) { 15 | Customser customser = new Customser(); 16 | customser.setCash(10000); 17 | BuyCarProxy buyCarProxy = new BuyCarProxy(customser); 18 | buyCarProxy.buyCar(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/proxy/staticproxy/BuyCarProxy.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.proxy.staticproxy; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/9 21:45 6 | * @descriptor : 汽车代理商 - 4S店 7 | */ 8 | public class BuyCarProxy implements BuyCar{ 9 | // 买车的客户 10 | private Customser customser; 11 | public BuyCarProxy(Customser customser){ 12 | // 接收买车客户 13 | this.customser = customser; 14 | } 15 | 16 | /** 17 | * 实现为客户买车 18 | */ 19 | @Override 20 | public void buyCar() { 21 | // 实现权限控制 22 | if (customser.getCash()<100000){ 23 | System.out.println("您的购车款不足!"); 24 | } 25 | customser.buyCar(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/proxy/staticproxy/Customser.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.proxy.staticproxy; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/9 21:42 6 | * @descriptor : 顾客买车 7 | */ 8 | public class Customser implements BuyCar { 9 | // 购车款 10 | private int cash; 11 | 12 | public int getCash() { 13 | return cash; 14 | } 15 | 16 | public void setCash(int cash) { 17 | this.cash = cash; 18 | } 19 | 20 | @Override 21 | public void buyCar() { 22 | System.out.println("顾客花--> " + cash + " 元购买了一辆车"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/simplefactory/CalculatorMain.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.simplefactory; 2 | 3 | /** 4 | * 计算器 - 利用简单工厂模式实现 5 | * Created by hisen on 17-4-16. 6 | */ 7 | public class CalculatorMain { 8 | 9 | public static void main(String[] args) { 10 | Opreation opreation; 11 | opreation = OpreationSimpleFactory.createOperate("+"); 12 | opreation.setNumberA(10); 13 | opreation.setNumberB(1); 14 | double result = opreation.getResult(); 15 | System.out.println(result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/simplefactory/OperationAdd.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.simplefactory; 2 | 3 | /** 4 | * 业务类:加法 5 | * Created by hisen on 17-4-16. 6 | */ 7 | public class OperationAdd extends Opreation { 8 | 9 | @Override 10 | public double getResult() { 11 | double result = 0; 12 | result = getNumberA() + getNumberB(); 13 | return result; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/simplefactory/OperationDiv.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.simplefactory; 2 | 3 | /** 4 | * 业务类:除法 5 | * Created by hisen on 17-4-16. 6 | */ 7 | public class OperationDiv extends Opreation { 8 | 9 | @Override 10 | public double getResult() { 11 | double result = 0; 12 | if (getNumberB() == 0) { 13 | try { 14 | throw new Exception("除数不能为0"); 15 | } catch (Exception e) { 16 | e.printStackTrace(); 17 | } 18 | } 19 | result = getNumberA() / getNumberB(); 20 | return result; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/simplefactory/OperationMul.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.simplefactory; 2 | 3 | /** 4 | * 业务类:乘法 5 | * Created by hisen on 17-4-16. 6 | */ 7 | public class OperationMul extends Opreation { 8 | 9 | @Override 10 | public double getResult() { 11 | double result = 0; 12 | result = getNumberA() * getNumberB(); 13 | return result; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/simplefactory/OperationSub.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.simplefactory; 2 | 3 | /** 4 | * 业务类:减法 5 | * Created by hisen on 17-4-16. 6 | */ 7 | public class OperationSub extends Opreation { 8 | 9 | @Override 10 | public double getResult() { 11 | double result = 0; 12 | result = getNumberA() - getNumberB(); 13 | return result; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/simplefactory/Opreation.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.simplefactory; 2 | 3 | /** 4 | * 业务类:计算操作父类 5 | * 继承的子类要重写父类方法有几个条件: 6 | * 1.父类中的方法在子类中必须可见 7 | * 2.子类和父类的方法必须是实例方法,如果父类是static方法而子类是实例方法,或者相反都会报错 8 | * 3.子类和父类的方法必须要具有相同的函数名称、参数列表,并且子类的返回值与父类相同或者是父类返回类型的子类型 9 | * 4.子类方法的访问权限不能小于父类方法的访问权限 10 | * 5.子类方法不能比父类方法抛出更多的编译时异常 11 | * Created by hisen on 17-4-16. 12 | */ 13 | public class Opreation { 14 | 15 | private double numberA = 0; 16 | private double numberB = 0; 17 | 18 | public double getNumberA() { 19 | return numberA; 20 | } 21 | 22 | public void setNumberA(double numberA) { 23 | this.numberA = numberA; 24 | } 25 | 26 | public double getNumberB() { 27 | return numberB; 28 | } 29 | 30 | public void setNumberB(double numberB) { 31 | this.numberB = numberB; 32 | } 33 | 34 | public double getResult() { 35 | double result = 0; 36 | return result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/designpattern/simplefactory/OpreationSimpleFactory.java: -------------------------------------------------------------------------------- 1 | package com.hisen.designpattern.simplefactory; 2 | 3 | /** 4 | * 简单工厂模式:传入参数构造相应的对象返回 5 | * Created by hisen on 17-4-16. 6 | */ 7 | public class OpreationSimpleFactory { 8 | 9 | public static Opreation createOperate(String operate) { 10 | //下面用到了多态 11 | Opreation opreation = null; 12 | switch (operate) { 13 | case "+": 14 | opreation = new OperationAdd(); 15 | break; 16 | case "-": 17 | opreation = new OperationSub(); 18 | break; 19 | case "*": 20 | opreation = new OperationMul(); 21 | break; 22 | case "/": 23 | opreation = new OperationDiv(); 24 | break; 25 | } 26 | return opreation; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/emvco/crccalc/Crc64.java: -------------------------------------------------------------------------------- 1 | package com.hisen.emvco.crccalc; 2 | 3 | public class Crc64 { 4 | public static AlgoParams Crc64 = new AlgoParams("CRC-64",64, 0x42F0E1EBA9EA3693L, 0x00000000L, false, false, 0x00000000L, 0x6C40DF5F0B497347L); 5 | public static AlgoParams Crc64We = new AlgoParams("CRC-64/WE", 64, 0x42F0E1EBA9EA3693L, 0xFFFFFFFFFFFFFFFFL, false, false, 0xFFFFFFFFFFFFFFFFL,0x62EC59E3F1A4F00AL); 6 | public static AlgoParams Crc64Xz = new AlgoParams("CRC-64/XZ", 64, 0x42F0E1EBA9EA3693L, 0xFFFFFFFFFFFFFFFFL, true, true, 0xFFFFFFFFFFFFFFFFL,0x995DC9BBDF1939FAL); 7 | 8 | 9 | public static final AlgoParams[] Params = new AlgoParams[]{ 10 | Crc64, Crc64We, Crc64Xz 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/emvco/crccalc/Crc8.java: -------------------------------------------------------------------------------- 1 | package com.hisen.emvco.crccalc; 2 | 3 | /** 4 | * Created by anthony on 15.05.2017. 5 | */ 6 | public class Crc8 { 7 | public static AlgoParams Crc8 = new AlgoParams("CRC-8", 8, 0x7, 0x0, false, false, 0x0, 0xF4); 8 | public static AlgoParams Crc8Cdma2000 = new AlgoParams("CRC-8/CDMA2000", 8, 0x9B, 0xFF, false, false, 0x0, 0xDA); 9 | public static AlgoParams Crc8Darc = new AlgoParams("CRC-8/DARC", 8, 0x39, 0x0, true, true, 0x0, 0x15); 10 | public static AlgoParams Crc8DvbS2 = new AlgoParams("CRC-8/DVB-S2", 8, 0xD5, 0x0, false, false, 0x0, 0xBC); 11 | public static AlgoParams Crc8Ebu = new AlgoParams("CRC-8/EBU", 8, 0x1D, 0xFF, true, true, 0x0, 0x97); 12 | public static AlgoParams Crc8ICode = new AlgoParams("CRC-8/I-CODE", 8, 0x1D, 0xFD, false, false, 0x0, 0x7E); 13 | public static AlgoParams Crc8Itu = new AlgoParams("CRC-8/ITU", 8, 0x7, 0x0, false, false, 0x55, 0xA1); 14 | public static AlgoParams Crc8Maxim = new AlgoParams("CRC-8/MAXIM", 8, 0x31, 0x0, true, true, 0x0, 0xA1); 15 | public static AlgoParams Crc8Rohc = new AlgoParams("CRC-8/ROHC", 8, 0x7, 0xFF, true, true, 0x0, 0xD0); 16 | public static AlgoParams Crc8Wcdma = new AlgoParams("CRC-8/WCDMA", 8, 0x9B, 0x0, true, true, 0x0, 0x25); 17 | 18 | public static final AlgoParams[] Params = new AlgoParams[]{ 19 | Crc8, Crc8Cdma2000, Crc8Darc, Crc8DvbS2, Crc8Ebu, Crc8ICode, Crc8Itu, Crc8Maxim, Crc8Rohc, Crc8Wcdma 20 | }; 21 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/emvco/crccalc/CrcHelper.java: -------------------------------------------------------------------------------- 1 | package com.hisen.emvco.crccalc; 2 | 3 | /** 4 | * Created by anthony on 13.05.2017. 5 | */ 6 | public class CrcHelper { 7 | 8 | static long ReverseBits(long ul, int valueLength) 9 | { 10 | long newValue = 0; 11 | 12 | for (int i = valueLength - 1; i >= 0; i--) 13 | { 14 | newValue |= (ul & 1) << i; 15 | ul >>= 1; 16 | } 17 | 18 | return newValue; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/emvco/parser/EmvcoTlvBean.java: -------------------------------------------------------------------------------- 1 | package com.hisen.emvco.parser; 2 | 3 | import java.util.StringJoiner; 4 | 5 | /** 6 | * @Author hisenyuan 7 | * @Description $end$ 8 | * @Date 2019/3/6 21:12 9 | */ 10 | public class EmvcoTlvBean { 11 | private String tag; 12 | private int length; 13 | private String value; 14 | 15 | public String getTag() { 16 | return tag; 17 | } 18 | 19 | public void setTag(String tag) { 20 | this.tag = tag; 21 | } 22 | 23 | public int getLength() { 24 | return length; 25 | } 26 | 27 | public void setLength(int length) { 28 | this.length = length; 29 | } 30 | 31 | public String getValue() { 32 | return value; 33 | } 34 | 35 | public void setValue(String value) { 36 | this.value = value; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return new StringJoiner(", ", EmvcoTlvBean.class.getSimpleName() + "[", "]") 42 | .add("tag='" + tag + "'") 43 | .add("length=" + length) 44 | .add("value='" + value + "'") 45 | .toString(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/file/Html2Image.java: -------------------------------------------------------------------------------- 1 | package com.hisen.file; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.awt.image.RenderedImage; 5 | import java.io.File; 6 | import java.net.URL; 7 | import javax.imageio.ImageIO; 8 | import javax.swing.JEditorPane; 9 | import javax.swing.JPanel; 10 | import javax.swing.SwingUtilities; 11 | 12 | /** 13 | * Created by hisenyuan on 2017/5/9 at 18:25. 14 | */ 15 | public class Html2Image { 16 | public static void main(String[] args) throws Exception { 17 | //load the webpage into the editor 18 | JEditorPane ed = new JEditorPane(new URL("http://hisen.me")); 19 | Thread.sleep(10000); 20 | ed.setSize(1000,1000); 21 | //create a new image 22 | BufferedImage image = new BufferedImage(ed.getWidth(), ed.getHeight(), 23 | BufferedImage.TYPE_INT_ARGB); 24 | 25 | //paint the editor onto the image 26 | SwingUtilities.paintComponent(image.createGraphics(), 27 | ed, 28 | new JPanel(), 29 | 0, 0, image.getWidth(), image.getHeight()); 30 | //save the image to file 31 | ImageIO.write((RenderedImage)image, "png", new File("html.png")); 32 | System.out.println("ok"); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/file/oracle/function/GET_DATE_FROM_MILLISECOND.fnc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE NONEDITIONABLE FUNCTION GET_DATE_FROM_MILLISECOND(MILLISECOND NUMBER) 2 | RETURN DATE IS 3 | Result DATE; 4 | BEGIN 5 | --in 1149124496734 6 | --out date 7 | 8 | SELECT (TRUNC(SYSDATE,'HH')+(MILLISECOND-(GET_MILLISECOND(TRUNC(SYSDATE,'HH'))))/86400000) 9 | INTO Result 10 | FROM DUAL; 11 | 12 | RETURN Result; 13 | 14 | END GET_DATE_FROM_MILLISECOND; 15 | / 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/file/oracle/function/GET_MILLISECOND_FROM_DATE.fnc: -------------------------------------------------------------------------------- 1 | CREATE OR REPLACE NONEDITIONABLE FUNCTION GET_MILLISECOND(THISTIME DATE) 2 | RETURN NUMBER IS 3 | Result NUMBER(13); 4 | BEGIN 5 | --in date 6 | --out 1149124496734 7 | 8 | SELECT (THISTIME-to_date('1970-01-01 08:00:00','YYYY-MM-DD HH24:mi:ss'))*86400000 9 | INTO Result 10 | FROM DUAL; 11 | 12 | RETURN Result; 13 | 14 | END GET_MILLISECOND; 15 | / 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/file/oracle/produres/GET_ONE_DAY_24_DATA.prc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hisenyuan/IDEAPractice/d44f90a385688fdaf071035519854d5357286f8a/src/main/java/com/hisen/file/oracle/produres/GET_ONE_DAY_24_DATA.prc -------------------------------------------------------------------------------- /src/main/java/com/hisen/file/test.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hisenyuan/IDEAPractice/d44f90a385688fdaf071035519854d5357286f8a/src/main/java/com/hisen/file/test.txt -------------------------------------------------------------------------------- /src/main/java/com/hisen/image/ShowImageByBase64.java: -------------------------------------------------------------------------------- 1 | package com.hisen.image; 2 | 3 | import com.hisen.utils.Base64Util; 4 | import com.hisen.utils.File2ByteArraysUtil; 5 | 6 | /** 7 | * data:image/png;base64base64image 8 | * Created by hisenyuan on 2017/5/11 at 18:44. 9 | */ 10 | public class ShowImageByBase64 { 11 | public static String showimage(){ 12 | //写相对路径会报错,暂时不知道如何解决 13 | String imagePath = "C:\\1\\830.jpg"; 14 | byte[] bytes = File2ByteArraysUtil.file2Bytes(imagePath); 15 | String s = Base64Util.encodeBase64(bytes); 16 | return s; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/AboutExtends.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | /** 4 | * 变量不能被重写 5 | * 6 | * @author hisenyuan 2017年1月18日 下午10:33:33 7 | */ 8 | public class AboutExtends { 9 | 10 | public static void main(String[] args) { 11 | // 里面的static块方法,new了就会执行 12 | // new B()两个都执行,new A()执行A的 13 | // static代码块在{}代码块后面执行 14 | A classA = new B(); 15 | System.out.println(classA.a); 16 | classA.fun(); 17 | // 输出信息 18 | // Astatic 19 | // Bstatic 20 | // I'm A class 21 | // I'm B class 22 | // 0 23 | // B 24 | 25 | // 多态记忆口诀 26 | // 变量多态看左边 27 | // 方法多态看右边 28 | // 静态多态看左边 29 | } 30 | 31 | public static class A { 32 | 33 | static { 34 | System.out.println("Astatic"); 35 | } 36 | 37 | public int a = 0; 38 | 39 | { 40 | System.out.println("I'm A class"); 41 | } 42 | 43 | public void fun() { 44 | System.out.println("A"); 45 | } 46 | } 47 | 48 | public static class B extends A { 49 | 50 | static { 51 | System.out.println("Bstatic"); 52 | } 53 | 54 | public int a = 1; 55 | 56 | { 57 | System.out.println("I'm B class"); 58 | } 59 | 60 | public void fun() { 61 | System.out.println("B"); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/AboutNewObject.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | /** 4 | * 有时候可能会遇到关于String 的一些问题 5 | * Created by hisenyuan on 2017/7/5 at 1:09. 6 | */ 7 | public class AboutNewObject { 8 | 9 | 10 | public static void main(String[] args) { 11 | User m = new User(); 12 | User w = new User(); 13 | m.setAdd("北京"); 14 | System.out.println(w.getAdd()); 15 | 16 | String a = "xxx"; 17 | //b指向a所指向的同一个对象 18 | String b = "xxx"; 19 | //c是一个新对象 20 | String c = new String("xxx"); 21 | System.out.println(a == b); 22 | System.out.println(a == c); 23 | //c.intern(),取c的值 24 | System.out.println(a == c.intern()); 25 | } 26 | 27 | static class User { 28 | 29 | private String name; 30 | private String add; 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getAdd() { 41 | return add; 42 | } 43 | 44 | public void setAdd(String add) { 45 | this.add = add; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/CreateNumberByRMB.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * 动态规划问题 7 | * 根据人民币的币值 1、5、20、50、100 8 | * 判断一个特定的金额有多少中组合 9 | * Created by hisenyuan on 2017/7/15 at 22:34. 10 | */ 11 | public class CreateNumberByRMB { 12 | @Test 13 | public void test3() { 14 | int[] rmb = {1, 5, 10, 20, 50, 100}; 15 | int i = countWays(rmb, 5, 1000000); 16 | System.out.println(i); 17 | } 18 | /** 19 | * 第三组 - 动态规划 20 | * @param penny 21 | * @param n 22 | * @param aim 23 | * @return 24 | */ 25 | public int countWays(int[] penny, int n, int aim) { 26 | // write code here 27 | if(n==0||penny==null||aim<0){ 28 | return 0; 29 | } 30 | int[][] pd = new int[n][aim+1]; 31 | for(int i=0;i=penny[i]){ 40 | pd[i][j] = pd[i-1][j]+pd[i][j-penny[i]]; 41 | }else{ 42 | pd[i][j] = pd[i-1][j]; 43 | } 44 | } 45 | } 46 | return pd[n-1][aim]; 47 | } 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/FinalString.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | /** 4 | * String为final类型,不可变 5 | * Created by hisen on 17-8-15. 6 | * E-mail: hisenyuan@gmail.com 7 | */ 8 | public class FinalString { 9 | 10 | private String host = ""; 11 | private String api = "login"; 12 | private String service = host + api; 13 | 14 | public FinalString setHost(String host) { 15 | this.host = host; 16 | // System.out.println("A setHost:"+this.services); 17 | // System.out.println("A setHost:"+this.host); 18 | return this; 19 | } 20 | 21 | public String getService() { 22 | return this.service; 23 | } 24 | public String getHost(){ 25 | return this.host; 26 | } 27 | 28 | public static void main(String[] args) { 29 | String host_ = "127.0.0.1/"; 30 | System.out.println(new FinalString().setHost(host_).getService()); 31 | // login # 因为service所指向的内存地址始终没变 32 | System.out.println(new FinalString().setHost(host_).getHost()); 33 | // 127.0.0.1/ 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/FindFirstNotDupStr.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * @Author hisenyuan 7 | * @Description 在一段字符串中找出第一个只出现一次的字符,没有返回空串 8 | * @Date 2019/4/2 14:50 9 | */ 10 | public class FindFirstNotDupStr { 11 | public static void main(String[] args) { 12 | String str = "ADBABCAABB"; 13 | 14 | final int[] indexs = getDupCountArr(str); 15 | 16 | final String c = firstFirstNotDup(str, indexs); 17 | 18 | System.out.println(c); 19 | 20 | System.out.println(Arrays.toString(indexs)); 21 | } 22 | 23 | // 找出第一个只出现一次的字符 24 | private static String firstFirstNotDup(String str, int[] indexs) { 25 | for (int i = 0; i < str.length(); i++) { 26 | int at = str.charAt(i); 27 | final int id = (at - 'A'); 28 | if (indexs[id] == 1) { 29 | return String.valueOf((char) at); 30 | } 31 | } 32 | return ""; 33 | } 34 | 35 | // 利用字符ascii码作为数组下标,记录字符出现次数 36 | private static int[] getDupCountArr(String str) { 37 | final int[] indexs = new int[26]; 38 | for (int i = 0; i < str.length(); i++) { 39 | int at = str.charAt(i); 40 | final int id = (at - 'A'); 41 | indexs[id] = indexs[id] + 1; 42 | } 43 | return indexs; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/FindNotDupInArray.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | /** 4 | * @Author hisenyuan 5 | * @Description $end$ 6 | * @Date 2019/4/4 18:50 7 | */ 8 | public class FindNotDupInArray { 9 | public static void main(String[] args) { 10 | int[] mayDup = {1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1}; 11 | int res = mayDup[0]; 12 | for (int i = 1; i < mayDup.length; i++) { 13 | System.out.print("res^mayDup[i]: " + res + "^" + mayDup[i]); 14 | res ^= mayDup[i]; 15 | System.out.println("=" + res); 16 | } 17 | System.out.println(res); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/GB2312__to__ISO_8859_1.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | 5 | public class GB2312__to__ISO_8859_1 { 6 | 7 | public static void main(String[] args) throws UnsupportedEncodingException { 8 | String s1 = "你好"; 9 | String s2 = new String(s1.getBytes("GB2312"), "ISO-8859-1"); 10 | System.out.println(s2); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/MoveElement.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * 把数组中的非零元素往前移动 7 | */ 8 | public class MoveElement { 9 | 10 | public static void main(String[] args) { 11 | int[] array = {0, 0, 1, 0, 3, 5, 0, 6, 7}; 12 | System.out.println("移动前:" + Arrays.toString(array)); 13 | // 移动前:[0, 0, 1, 0, 3, 5, 0, 6, 7] 14 | mv(array); 15 | System.out.println("移动后:" + Arrays.toString(array)); 16 | // 移动后:[1, 3, 5, 6, 7, 0, 0, 0, 0] 17 | } 18 | 19 | /** 20 | * 传入一个数组,把非零数尽量左移 21 | * 22 | * @param arr 传入的数组 23 | */ 24 | static void mv(int[] arr) { 25 | int i = -1, j, temp; 26 | 27 | for (j = 0; j < arr.length; j++) { 28 | System.out.println("------->\ti=" + i + "\t j=" + j); 29 | if (arr[j] != 0) { 30 | ++i; 31 | if (i != j) { 32 | temp = arr[i]; 33 | arr[i] = arr[j]; 34 | arr[j] = temp; 35 | } 36 | } 37 | } 38 | } 39 | /* 40 | * 移动过程中,i j的变化 41 | 移动前:[0, 0, 1, 0, 3, 5, 0, 6, 7] 42 | -------> i=-1 j=0 43 | -------> i=-1 j=1 44 | -------> i=-1 j=2 45 | -------> i=0 j=3 46 | -------> i=0 j=4 47 | -------> i=1 j=5 48 | -------> i=2 j=6 49 | -------> i=2 j=7 50 | -------> i=3 j=8 51 | 移动后:[1, 3, 5, 6, 7, 0, 0, 0, 0] 52 | */ 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/MultithreadingSingleton.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/10 17:56 6 | * @descriptor : 多线程下的单例模式 7 | */ 8 | public class MultithreadingSingleton { 9 | 10 | // 保证可见性 11 | private static volatile MultithreadingSingleton singleton = null; 12 | 13 | private static volatile boolean flag = false; 14 | 15 | // 必须指定为私有方法,否则可以直接new对象 16 | private MultithreadingSingleton() { 17 | // 防止被反射;并且保证过程是线程安全的 18 | synchronized (MultithreadingSingleton.class) { 19 | if (!flag) { 20 | flag = true; 21 | } else { 22 | throw new RuntimeException("禁止反射!"); 23 | } 24 | } 25 | } 26 | 27 | // 获取实例 28 | public static MultithreadingSingleton getInstance() { 29 | if (singleton == null) { 30 | syncInit(); 31 | } 32 | return singleton; 33 | } 34 | 35 | /** 36 | * 加入同步方法 37 | */ 38 | private static void syncInit() { 39 | // 减小锁的粒度 40 | synchronized (MultithreadingSingleton.class) { 41 | // 二次判断,防止多次创建 42 | if (singleton == null) { 43 | singleton = new MultithreadingSingleton(); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/QuickSort.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | import java.util.Arrays; 4 | import org.junit.Test; 5 | 6 | /** 7 | * 最简单的方式实现快排 8 | * Created by hisenyuan on 2017/6/1 at 16:55. 9 | */ 10 | public class QuickSort { 11 | 12 | @Test 13 | public void test() { 14 | int[] a = {1, 3, 43, 5, 33, 53, 3, 7, -9, 23, 90}; 15 | int low = 0; 16 | int high = a.length - 1; 17 | qiuckSort(a, low, high); 18 | //快速打印数组 19 | System.out.println(Arrays.toString(a)); 20 | } 21 | 22 | public static void qiuckSort(int a[], int low, int high) { 23 | int l = low; 24 | int r = high; 25 | int temp = a[l]; 26 | 27 | if (l < r) { 28 | while (l < r) { 29 | while (l < r && a[r] > temp) { 30 | r--; 31 | } 32 | if (l < r) { 33 | a[l] = a[r]; 34 | } 35 | while (l < r && a[l] <= temp) { 36 | l++; 37 | } 38 | if (l < r) { 39 | a[r] = a[l]; 40 | } 41 | } 42 | a[l] = temp; 43 | qiuckSort(a, low, l - 1); 44 | qiuckSort(a, l + 1, high); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/ReverseString.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview; 2 | 3 | /* 4 | * 递归实现字符的翻转 5 | */ 6 | public class ReverseString { 7 | 8 | public static String reverse(String str) { 9 | if (str == null || str.length() <= 1) { 10 | return str; 11 | } 12 | //str.charAt(0) 截取第一个字符 13 | //str.substring(1)) 截取第一个字符后的所有字符 14 | return reverse(str.substring(1)) + str.charAt(0); 15 | } 16 | 17 | public static void main(String[] args) { 18 | String str = "hisen"; 19 | System.out.println(reverse(str)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/effective/no2buildpatter/TestBuilderPatter.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.effective.no2buildpatter; 2 | 3 | import com.hisen.interview.effective.no2buildpatter.NutritionFacts.Builder; 4 | 5 | /** 6 | * @author : yhx 7 | * @date : 2018/1/27 23:01 8 | * @descriptor : 9 | */ 10 | public class TestBuilderPatter { 11 | 12 | public static void main(String[] args) { 13 | NutritionFacts cocaCola = new Builder(240, 8) 14 | .calories(100) 15 | .sodium(35) 16 | .calories(27) 17 | .carbohydrate(18) 18 | .build(); 19 | System.out.println(cocaCola); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/effective/no3enumsingleton/EnumSingleton.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.effective.no3enumsingleton; 2 | 3 | 4 | /** 5 | * @author : yhx 6 | * @date : 2018/1/27 23:16 7 | * @descriptor : 利用枚举实现单例模式,单例的最佳方法。枚举单例有序列化和线程安全的保证。 8 | */ 9 | public class EnumSingleton { 10 | 11 | private EnumSingleton() { 12 | } 13 | 14 | public static EnumSingleton getInstance() { 15 | return Singleton.INSTANCE.getInstance(); 16 | } 17 | 18 | private enum Singleton { 19 | INSTANCE; 20 | private EnumSingleton singleton; 21 | 22 | Singleton() { 23 | singleton = new EnumSingleton(); 24 | } 25 | 26 | public EnumSingleton getInstance() { 27 | return singleton; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/effective/no3enumsingleton/TestEnumSingleton.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.effective.no3enumsingleton; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2018/1/27 23:11 6 | * @descriptor : 7 | */ 8 | public class TestEnumSingleton { 9 | 10 | public static void main(String[] args) { 11 | EnumSingleton singleton = EnumSingleton.getInstance(); 12 | EnumSingleton instance = EnumSingleton.getInstance(); 13 | System.out.println(singleton==instance); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/java8/FunctionalInterfaceTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.java8; 2 | 3 | /** 4 | * 函数式接口 5 | * Created by hisen on 17-8-6. 6 | */ 7 | public class FunctionalInterfaceTest { 8 | 9 | // 声明一个函数式接口 10 | @FunctionalInterface 11 | interface Converter { 12 | 13 | T convert(F from); 14 | } 15 | 16 | public static void main(String[] args) { 17 | // 实现接口 18 | Converter converter = (from -> Integer.valueOf(from)); 19 | // 调用函数 20 | Integer converted = converter.convert("123"); 21 | // 输出 22 | System.out.println(converted); 23 | 24 | //静态方法引用 25 | Converter converter1 = Integer::valueOf; 26 | Integer con = converter1.convert("234"); 27 | System.out.println(con); 28 | 29 | class Something { 30 | 31 | String startsWith(String s) { 32 | return String.valueOf(s.charAt(0)); 33 | } 34 | } 35 | 36 | Something something = new Something(); 37 | Converter converter2 = something::startsWith; 38 | String con2 = converter2.convert("Java"); 39 | System.out.println(con2); // "J" 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/java8/LambdaExpression.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.java8; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by hisen on 17-8-6. 10 | */ 11 | public class LambdaExpression { 12 | 13 | public static void main(String[] args) { 14 | List names = Arrays.asList("peter", "anna", "mike", "xenia"); 15 | //java8之前的写法 16 | Collections.sort(names, new Comparator() { 17 | @Override 18 | public int compare(String a, String b) { 19 | return a.compareTo(b); 20 | } 21 | }); 22 | System.out.println("传统排序:"+names);//[anna, mike, peter, xenia] 23 | //常规的Lambda表达式 24 | Collections.sort(names,(String a,String b) ->{ 25 | return a.compareTo(b); 26 | }); 27 | System.out.println("常规Lambda:"+names);//[anna, mike, peter, xenia] 28 | //缩短 29 | Collections.sort(names,(String a,String b) -> b.compareTo(a)); 30 | 31 | //再缩短,编译器自动根据上下文来决定参数的类型 32 | Collections.sort(names,(a,b) -> b.compareTo(a)); 33 | System.out.println("缩短的lambda:"+names);//[xenia, peter, mike, anna] 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/Ascii2String_String2Ascii.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | 5 | /** 6 | * ASCII/字符串 互相转换 7 | * 8 | * @author hisenyuan 2016年3月28日 下午6:05:28 9 | */ 10 | public class Ascii2String_String2Ascii { 11 | 12 | public static void main(String[] args) throws UnsupportedEncodingException { 13 | Ascii2String();// ASCII转换为字符串 14 | String2Ascii();// 字符串转换为ASCII码 15 | } 16 | 17 | public static void Ascii2String() {// ASCII转换为字符串 18 | String s = "22307,35806,24555,20048";// ASCII码 19 | String[] chars = s.split(","); 20 | System.out.println("ASCII -> 汉字 \n----------------------"); 21 | for (int i = 0; i < chars.length; i++) { 22 | System.out.println(chars[i] + " -> " + (char) Integer.parseInt(chars[i])); 23 | } 24 | } 25 | 26 | public static void String2Ascii() {// 字符串转换为ASCII码 27 | String s = "新年快乐!";// 字符串 28 | char[] chars = s.toCharArray(); // 把字符中转换为字符数组 29 | System.out.println("\n\n汉字 -> ASCII\n----------------------"); 30 | for (int i = 0; i < chars.length; i++) {// 输出结果 31 | System.out.println(" " + chars[i] + " -> " + (int) chars[i]); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/JiDan.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | /** 4 | * 朋友圈遇到的计算一筐鸡蛋不同拿法算最少有多少个的题 5 | * 6 | * @author hisenyuan 2017年2月8日 下午3:34:19 7 | */ 8 | public class JiDan { 9 | 10 | public static void main(String[] args) { 11 | // 1个1个拿,正好拿完。 12 | // 2个2个拿,还剩1个。 13 | // 3个3个拿,正好拿完。 14 | // 4个4个拿,还剩1个。 15 | // 5个5个拿,还差1个。 16 | // 6个6个拿,还剩3个。 17 | // 7个7个拿,正好拿完。 18 | // 8个8个拿,还剩1个。 19 | // 9个9个拿,正好拿完。 20 | //问筐里最少有多少鸡蛋? 21 | boolean flag = true; 22 | int x = 0; 23 | while (flag) { 24 | if (x % 3 == 0 && x % 7 == 0 && x % 9 == 0) { 25 | if ((x - 1) % 2 == 0 && (x - 1) % 4 == 0 && (x - 1) % 8 == 0) { 26 | if ((x + 1) % 5 == 0 && (x - 3) % 6 == 0) { 27 | System.out.println(x); 28 | // 1449 为最小的数目 29 | flag = false; 30 | } 31 | } 32 | } 33 | ++x; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/LingXing.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | /** 4 | * 观察规律,打印菱形的话是由空格跟*组成 5 | * 每一行里面 空格个数+星号的个数都是相等的 6 | * 所以在for循环里面加入两个并行的循环可以实现打印 7 | */ 8 | public class LingXing { 9 | 10 | public static void main(String[] args) { 11 | printLX(5); 12 | } 13 | 14 | /** 15 | * 打印菱形的方法 16 | * 17 | * @param n 菱形最宽处*的个数 18 | */ 19 | public static void printLX(int n) { 20 | // 菱形的上半部分 21 | for (int i = 1; i <= n; i++) { 22 | for (int k = 0; k < n - i; k++) { 23 | System.out.print("\t"); 24 | } 25 | for (int j = 1; j <= i; j++) { 26 | System.out.print("\t*\t"); 27 | } 28 | System.out.println(""); 29 | } 30 | // 菱形下半部分,x从1开始,否则会多一行 31 | for (int x = 1; x <= n; x++) { 32 | for (int y = 0; y < x; y++) { 33 | System.out.print("\t"); 34 | } 35 | for (int z = 1; z <= n - x; z++) { 36 | System.out.print("\t*\t"); 37 | } 38 | System.out.println(""); 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/MaopaoSort.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | import java.util.Arrays; 4 | 5 | public class MaopaoSort { 6 | 7 | public static void main(String[] args) { 8 | //int hisen[] = new int[10]; 9 | int hisen[] = {1, 23, 4, 9, 7, 22, 54, 89, 47}; 10 | for (int i = 1; i < hisen.length; i++) { 11 | //从数组最后一个开始,往前逐个比较,符合条件就调换顺序 12 | for (int j = hisen.length - 1; j > 0; j--) { 13 | //大于号是降序,小于号是升序 14 | if (hisen[j] > hisen[j - 1]) { 15 | int temp = hisen[j]; 16 | hisen[j] = hisen[j - 1]; 17 | hisen[j - 1] = temp; 18 | } 19 | } 20 | } 21 | //输出排序之后的数组 22 | System.out.println(Arrays.toString(hisen)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/RandomCode.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | /** 4 | * 利用ASCII生成置顶长度的密码 5 | * 密码包含大小写字母、数字、常用符号的密码 6 | * 7 | * ASCII 33-126含有大小写字母、数字、常用符号 8 | * 9 | * @author hisenyuan 2016年3月28日 下午6:13:14 10 | */ 11 | public class RandomCode { 12 | 13 | public static void main(String[] args) { 14 | System.out.print("为您生成的密码:" + code(2)); 15 | //hisen();//判断随机数的范围 16 | } 17 | 18 | /** 19 | * 生成随机密码 20 | * 21 | * @param length 密码长度 22 | * @return 生成的密码字符串 23 | */ 24 | public static String code(int length) { 25 | StringBuilder builder = new StringBuilder(); 26 | for (int i = 0; i < length; i++) { 27 | //利用22~126的随机数,把ascii码转成字符拼接 28 | int random = 65 + (int) (Math.random() * 26); 29 | builder.append((char) Integer.parseInt(String.valueOf(random))); 30 | } 31 | return builder.toString(); 32 | } 33 | 34 | /** 35 | * 判断随机数的范围 36 | */ 37 | public static void hisen() { 38 | Boolean flag = true; 39 | int i = 0; 40 | while (flag) { 41 | i = 33 + (int) (Math.random() * 94); 42 | // 希望得到 33~126的数字 43 | if (i == 33) { 44 | flag = false; 45 | } 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/digui.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | public class digui { 4 | 5 | public static void main(String[] args) { 6 | System.out.println(jc(4)); 7 | } 8 | 9 | public static long jc(long n) { 10 | if (n == 0) { 11 | return 1; 12 | } else { 13 | return n * jc(n - 1); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/sumJC.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | /** 4 | * 求 1!+2!+3! ....+n! 5 | * 6 | * @author Administrator 7 | */ 8 | public class sumJC { 9 | 10 | public static void main(String[] args) { 11 | int result = 0; 12 | for (int i = 1; i <= 4; i++) { 13 | int a = 1; 14 | for (int j = 1; j <= i; j++) { 15 | a = a * j; 16 | System.out.println(a + "*" + j + "=" + a * j); 17 | } 18 | System.out.println("-----------------");// 19 | result += a;//把a都加起来,而不是把a*j的结果加起来 20 | } 21 | System.out.println(result); 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/math/xyz.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.math; 2 | 3 | /** 4 | * xyz = x3 + y3 + z3 5 | * 水仙花数 6 | */ 7 | public class xyz { 8 | 9 | public static void main(String[] args) { 10 | int x, y, z, n; 11 | char c = 0xB3; //立方根符号 12 | for (n = 100; n < 1000; n++) { 13 | x = n / 100;//取出百位 14 | y = n / 10 % 10;//取出十位 15 | z = n % 10;//取出个位 16 | int f = x * x * x + y * y * y + z * z * z; 17 | if (n == f) { 18 | System.out.println( 19 | n + "=" + x + c + "+" + y + c + "+" + z + c + "=" + x * x * x + "+" + y * y * y + "+" 20 | + z * z * z); 21 | } 22 | } 23 | // 全部输出 24 | // 153=1³+5³+3³=1+125+27 25 | // 370=3³+7³+0³=27+343+0 26 | // 371=3³+7³+1³=27+343+1 27 | // 407=4³+0³+7³=64+0+343 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/tiger20171110/btree/Visit.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.tiger20171110.btree; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/13 12:14 6 | * @descriptor : 对节点进行操作的接口 - 二叉树的构造与遍历 7 | */ 8 | public interface Visit { 9 | 10 | /** 11 | * 对节点进行某种操作 12 | * @param bTree 树的节点 13 | */ 14 | public void visit(BTree bTree); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/tiger20171110/multithreadingwrite/MultithreadingWrite.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.tiger20171110.multithreadingwrite; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/13 16:53 6 | * @descriptor : 写文件的线程类 7 | */ 8 | public class MultithreadingWrite extends Thread{ 9 | Write2File write2File = new Write2File(); 10 | @Override 11 | public void run(){ 12 | Write2File.write2file(); 13 | write2File.write2file1(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/tiger20171110/multithreadingwrite/Write2File.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.tiger20171110.multithreadingwrite; 2 | 3 | import com.google.common.base.Charsets; 4 | import com.google.common.io.Files; 5 | import java.io.File; 6 | import java.io.IOException; 7 | import org.joda.time.DateTime; 8 | 9 | /** 10 | * @author : yhx 11 | * @date : 2017/11/13 16:40 12 | * @descriptor : 利用Guava向文件写入数据 - 加入同步方法 13 | */ 14 | public class Write2File { 15 | // 获取系统换行符 16 | private static String lineSeparator = System.getProperty("line.separator", "\n"); 17 | // 静态方法同步 - 同步在拥有该方法的对象上 18 | public static synchronized void write2file(){ 19 | File file = new File("C:\\1\\hisenyuan\\write.txt"); 20 | // 三个系统都没有统一的换行符 21 | String str = "Hello world - " + DateTime.now().toString("yyyy-MM-dd hh:mm:ss SSS") + lineSeparator; 22 | try { 23 | Files.append(str, file, Charsets.UTF_8); 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | 29 | // 实例方法同步 - 同步在拥有该方法的对象上 30 | public synchronized void write2file1(){ 31 | File file = new File("C:\\1\\hisenyuan\\write1.txt"); 32 | String str = "Hello world 1 - " + DateTime.now().toString("yyyy-MM-dd hh:mm:ss SSS") + lineSeparator; 33 | try { 34 | Files.append(str, file, Charsets.UTF_8); 35 | } catch (IOException e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/tiger20171110/multithreadingwrite/Write2FileMain.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.tiger20171110.multithreadingwrite; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/13 16:47 6 | * @descriptor : 多线程同时写入文件 7 | */ 8 | public class Write2FileMain { 9 | 10 | public static void main(String[] args) { 11 | for (int i = 0; i < 100; i++) { 12 | System.out.println("第" + i + "个线程正在写"); 13 | new MultithreadingWrite().start(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/tiger20171110/reverselinkedlist/Node.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.tiger20171110.reverselinkedlist; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/13 15:02 6 | * @descriptor : 定义一个单链表 7 | */ 8 | public class Node { 9 | private int data; 10 | private Node next; 11 | 12 | public Node(int data) { 13 | this.data = data; 14 | } 15 | 16 | public int getData() { 17 | return data; 18 | } 19 | 20 | public void setData(int data) { 21 | this.data = data; 22 | } 23 | 24 | public Node getNext() { 25 | return next; 26 | } 27 | 28 | public void setNext(Node next) { 29 | this.next = next; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/interview/tiger20171110/reverselinkedlist/ReverseNodeMain.java: -------------------------------------------------------------------------------- 1 | package com.hisen.interview.tiger20171110.reverselinkedlist; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/13 15:19 6 | * @descriptor : 7 | */ 8 | public class ReverseNodeMain { 9 | 10 | public static void main(String[] args) { 11 | /********************* 测试递归翻转 *********************/ 12 | // 前一个节点 13 | Node head = new Node(0); 14 | // 第一个节点 15 | Node node1 = new Node(1); 16 | Node node2 = new Node(2); 17 | Node node3 = new Node(3); 18 | 19 | head.setNext(node1); 20 | node1.setNext(node2); 21 | node2.setNext(node3); 22 | 23 | ReverseNode.printNode(head); 24 | System.out.println("递归翻转"); 25 | ReverseNode.printNode(ReverseNode.reverseByRecursion(head)); 26 | 27 | /********************* 测试遍历翻转 *********************/ 28 | // 前一个节点 29 | Node head1 = new Node(0); 30 | // 第一个节点 31 | Node node11 = new Node(1); 32 | Node node21 = new Node(2); 33 | Node node31 = new Node(3); 34 | 35 | head1.setNext(node11); 36 | node11.setNext(node21); 37 | node21.setNext(node31); 38 | ReverseNode.printNode(head); 39 | System.out.println("遍历翻转"); 40 | ReverseNode.printNode(ReverseNode.reverseByErgodic(head1)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/JUnit/Calculator.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.JUnit; 2 | 3 | /** 4 | * 计算类 5 | * 6 | * @author hisenyuan 2017年1月18日 下午10:23:13 7 | */ 8 | public class Calculator { 9 | 10 | private static int result; //静态变量,用于存储运行结果 11 | 12 | public void add(int n) { 13 | result = result + n; 14 | } 15 | 16 | public void substract(int n) { 17 | result = result - 1; //Bug:正确的应该是result=result-n; 18 | } 19 | 20 | public void multiply(int n) { 21 | //此方法尚未写好 22 | } 23 | 24 | public void divide(int n) { 25 | result = result / n; 26 | } 27 | 28 | public void square(int n) { 29 | result = n * n; 30 | } 31 | 32 | public void squareRoot(int n) { 33 | for (; ; ) { 34 | ; //Bug:死循环 35 | } 36 | } 37 | 38 | public void clear() { 39 | result = 0; //将结果清零 40 | } 41 | 42 | public int getResult() { 43 | return result; 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/JUnit/CalculatorTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.JUnit; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.fail; 5 | 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | public class CalculatorTest { 11 | 12 | private static Calculator calculator = new Calculator(); 13 | 14 | @Before 15 | public void setUp() throws Exception { 16 | } 17 | 18 | @After 19 | public void tearDown() throws Exception { 20 | } 21 | 22 | @Test 23 | public void testAdd() { 24 | calculator.add(2); 25 | calculator.add(3); 26 | //预判,类似于断言 27 | assertEquals(5, calculator.getResult()); 28 | fail("Not yet implemented"); 29 | } 30 | 31 | @Test 32 | public void testSubstract() { 33 | fail("Not yet implemented"); 34 | } 35 | 36 | @Test 37 | public void testMultiply() { 38 | fail("Not yet implemented"); 39 | } 40 | 41 | @Test 42 | public void testDivide() { 43 | fail("Not yet implemented"); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/Jedis/FirstTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.Jedis; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import org.junit.Test; 6 | import redis.clients.jedis.Jedis; 7 | 8 | /** 9 | * Created by hisen on 17-4-11. 10 | * 有待参考:http://www.cnblogs.com/vinozly/p/5459498.html 11 | */ 12 | public class FirstTest { 13 | 14 | @Test 15 | public void testClient() { 16 | Jedis jedis = new Jedis("127.0.0.1", 6379); 17 | jedis.select(2); //切换Redis数据库 18 | jedis.set("firstJedis", "hello,Jedis"); //与Redis命令行操作基本一致 19 | System.out.println(jedis.get("firstJedis")); 20 | } 21 | 22 | @Test 23 | public void testMap() { 24 | Jedis jedis = new Jedis("127.0.0.1", 6379); 25 | jedis.select(2); 26 | //同Redis命令行中的hset操作,如名为family的set不存在,则创建set并放入名为lbq的元素,值为65 27 | jedis.hset("family", "lbq", "65"); 28 | //Redis不支持int类型,如不传String则会报错。 29 | jedis.hset("family", "zjz", "62"); 30 | System.out.println(jedis.hmget("family", "lbq", "zjz")); 31 | 32 | Map testMap1 = new HashMap(); 33 | //此处同上面,不能传非String型 34 | testMap1.put("num1", "1"); 35 | testMap1.put("num2", "15"); 36 | testMap1.put("num3", "606"); 37 | testMap1.put("num4", "1024"); 38 | jedis.hmset("testMap1", testMap1); //传入整个map对象入redis 39 | System.out.println(jedis.hmget("testMap1", "num1", "num2", "num3", "num4")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/dom4j/test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <高级java>@hisenyuan 5 | <工号>20110714 6 | <地址>北京 7 | <座右铭>唯有跑步和读书不能放弃 8 | 9 | 10 | <初级java>@hisenyuan 11 | <学号>20080808 12 | <地址>北京朝阳区 13 | <座右铭>三样东西别人抢不走:一是吃进胃里的食物,二是藏在心中的梦想,三是读进大脑里的书丨 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/guava/CollectionsTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.guava; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import java.awt.Color; 5 | 6 | /** 7 | * Created by hisenyuan on 2017/7/27 at 14:10. 8 | */ 9 | public class CollectionsTest { 10 | 11 | public static void main(String[] args) { 12 | 13 | } 14 | 15 | public static final ImmutableSet GOOGLE_COLORS = ImmutableSet.builder() 16 | .add(new Color(0,191,255)).build(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/guava/OptionalTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.guava; 2 | 3 | import com.google.common.base.Optional; 4 | 5 | /** 6 | * Guava 7 | * Guava是一种基于开源的Java库,其中包含谷歌正在由他们很多项目使用的很多核心库。 8 | * 这个库是为了方便编码,并减少编码错误。 9 | * 这个库提供用于集合,缓存,支持原语,并发性,常见注解,字符串处理,I/O和验证的实用方法。 10 | * 11 | * Optional 避免null Created by hisenyuan on 2017/7/27 at 13:43. 12 | */ 13 | public class OptionalTest { 14 | 15 | public static void main(String[] args) { 16 | //创建指定引用的Optional实例,若引用为null则快速失败 17 | Optional optional = Optional.of(5); 18 | //isPresent() 如果Optional包含非null的引用(引用存在),返回true 19 | boolean present = optional.isPresent();//true 20 | //get() 返回Optional所包含的引用,若引用缺失,则抛出java.lang.IllegalStateException 21 | Integer integer = optional.get();//5 22 | System.out.println(present + "\n" + integer); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/guava/PreconditionsTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.guava; 2 | 3 | import static com.google.common.base.Preconditions.*; 4 | 5 | /** 6 | * [Google Guava] 1.2-前置条件 7 | * Created by hisenyuan on 2017/7/27 at 13:58. 8 | */ 9 | public class PreconditionsTest { 10 | 11 | public static void main(String[] args) { 12 | try { 13 | checkArgument(true); // false:IllegalArgumentException 14 | checkNotNull(1);//null:java.lang.NullPointerException 15 | checkElementIndex(5, 6);//index:5,size:4 java.lang.IndexOutOfBoundsException: index (5) must be less than size (4) 16 | } catch (Exception e) { 17 | System.out.println(e.toString()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/guice/HelloApp.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.guice; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Inject; 5 | import com.google.inject.Injector; 6 | import com.hisen.jars.guice.service.BaseServer; 7 | import com.hisen.jars.guice.service.HelloService; 8 | import com.hisen.jars.guice.service.impl.HelloServiceImpl; 9 | import org.junit.Test; 10 | 11 | /** 12 | * @Author hisenyuan 13 | * @Description $end$ 14 | * @Date 2019/4/24 16:13 15 | */ 16 | public class HelloApp extends BaseServer { 17 | @Inject 18 | private HelloServiceImpl hello; 19 | 20 | @Test 21 | public void testSayHello() { 22 | // 方式一 23 | Injector injector = Guice.createInjector(); 24 | HelloService helloService = injector.getInstance(HelloService.class); 25 | helloService.sayHello("hisen"); 26 | 27 | // 方式二 其实是在BaseServer中做了方式1的事情 【类似Spring的方式】 28 | hello.sayHello("1"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/guice/service/BaseServer.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.guice.service; 2 | 3 | import com.google.inject.Guice; 4 | 5 | public abstract class BaseServer { 6 | public BaseServer() { 7 | Guice.createInjector().injectMembers(this); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/guice/service/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.guice.service; 2 | 3 | import com.google.inject.ImplementedBy; 4 | import com.hisen.jars.guice.service.impl.HelloServiceImpl; 5 | 6 | /** 7 | * @Author hisenyuan 8 | * @Description $end$ 9 | * @Date 2019/4/24 16:12 10 | */ 11 | @ImplementedBy(HelloServiceImpl.class) 12 | public interface HelloService { 13 | void sayHello(String name); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/guice/service/impl/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.guice.service.impl; 2 | 3 | 4 | import com.google.inject.Singleton; 5 | import com.hisen.jars.guice.service.HelloService; 6 | 7 | /** 8 | * @Author hisenyuan 9 | * @Description $end$ 10 | * @Date 2019/4/24 16:13 11 | */ 12 | @Singleton 13 | public class HelloServiceImpl implements HelloService { 14 | @Override 15 | public void sayHello(String name) { 16 | System.out.println("Hello " + name); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/jmx/Hello.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.jmx; 2 | 3 | /** 4 | * 实现接口 5 | * Created by hisenyuan on 2017/5/15 at 20:04. 6 | */ 7 | public class Hello implements HelloMBean { 8 | 9 | private String name; 10 | private String age; 11 | 12 | @Override 13 | public String getName() { 14 | System.out.println("get name 123"); 15 | return name; 16 | } 17 | 18 | @Override 19 | public void setName(String name) { 20 | System.out.println("set name 123"); 21 | this.name = name; 22 | } 23 | 24 | @Override 25 | public String getAge() { 26 | System.out.println("get age 123"); 27 | return age; 28 | } 29 | 30 | @Override 31 | public void setAge(String age) { 32 | System.out.println("set age 123"); 33 | this.age = age; 34 | } 35 | 36 | @Override 37 | public void helloWorld() { 38 | System.out.println("hello world"); 39 | } 40 | 41 | @Override 42 | public void helloWorld(String str) { 43 | System.out.println("helloWorld:" + str); 44 | } 45 | 46 | @Override 47 | public void getTelephone() { 48 | System.out.println("get Telephone"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/jmx/HelloAgent.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.jmx; 2 | 3 | import java.lang.management.ManagementFactory; 4 | import javax.management.JMException; 5 | import javax.management.MBeanServer; 6 | import javax.management.ObjectName; 7 | 8 | /** 9 | * 主方法,运行后在Jconsole里面可实现操作 10 | * 参考:http://www.cnblogs.com/dongguacai/p/5900507.html 11 | * Created by hisenyuan on 2017/5/15 at 20:05. 12 | */ 13 | public class HelloAgent { 14 | 15 | public static void main(String[] args) throws JMException, Exception { 16 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); 17 | ObjectName helloName = new ObjectName("jmxBean:name=hello"); 18 | //create mbean and register mbean 19 | server.registerMBean(new Hello(), helloName); 20 | Thread.sleep(60 * 60 * 1000); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/jmx/HelloMBean.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.jmx; 2 | 3 | /** 4 | * 接口应该严格按照类名+MBean 5 | * Created by hisenyuan on 2017/5/15 at 20:03. 6 | */ 7 | public interface HelloMBean { 8 | 9 | public String getName(); 10 | 11 | public void setName(String name); 12 | 13 | public String getAge(); 14 | 15 | public void setAge(String age); 16 | 17 | public void helloWorld(); 18 | 19 | public void helloWorld(String str); 20 | 21 | public void getTelephone(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/json/Map2Json.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.json; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * 将map转化为json 9 | * Created by hisenyuan on 2017/3/22 at 14:59. 10 | */ 11 | public class Map2Json { 12 | 13 | public static void main(String[] args) { 14 | fastjson(); 15 | } 16 | 17 | /** 18 | * 阿里巴巴的fastjson把map转换成json 19 | */ 20 | public static void fastjson() { 21 | Map map = new HashMap(); 22 | map.put("name", "hisen"); 23 | map.put("age", "20"); 24 | map.put("gender", "female"); 25 | map.put("add", "北京"); 26 | map.put("email", "hisenyuan@gmail.com"); 27 | map.put("phone", "15555555555"); 28 | 29 | String jsonString = JSON.toJSONString(map); 30 | System.out.println("-------------fastjson-----------------"); 31 | System.out.println(jsonString); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/json/fastjson/bean/Group.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.json.fastjson.bean; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by hisenyuan on 2017/3/22 at 17:48. 8 | */ 9 | public class Group { 10 | 11 | private Long id; 12 | private String name; 13 | private List users = new ArrayList(); 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) { 20 | this.id = id; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public List getUsers() { 32 | return users; 33 | } 34 | 35 | public void setUsers(List users) { 36 | this.users = users; 37 | } 38 | 39 | public void addUser(User user) { 40 | users.add(user); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/json/fastjson/bean/User.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.json.fastjson.bean; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/3/22 at 17:48. 5 | */ 6 | public class User { 7 | 8 | private Long id; 9 | private String name; 10 | 11 | public Long getId() { 12 | return id; 13 | } 14 | 15 | public void setId(Long id) { 16 | this.id = id; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/json/gson/Bean1.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.json.gson; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * @author hisenyuan 7 | * @time 2018/4/16 15:53 8 | * @description 9 | */ 10 | public class Bean1 { 11 | private Date now; 12 | private String name; 13 | private Long height; 14 | 15 | public Date getNow() { 16 | return now; 17 | } 18 | 19 | public void setNow(Date now) { 20 | this.now = now; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public Long getHeight() { 32 | return height; 33 | } 34 | 35 | public void setHeight(Long height) { 36 | this.height = height; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/json/gson/Bean2.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.json.gson; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * @author hisenyuan 7 | * @time 2018/4/16 15:53 8 | * @description 9 | */ 10 | public class Bean2 { 11 | private Date now; 12 | private String name; 13 | private Long height; 14 | 15 | public Date getNow() { 16 | return now; 17 | } 18 | 19 | public void setNow(Date now) { 20 | this.now = now; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public Long getHeight() { 32 | return height; 33 | } 34 | 35 | public void setHeight(Long height) { 36 | this.height = height; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/json/gson/TestGson.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.json.gson; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.google.gson.Gson; 5 | import com.google.gson.reflect.TypeToken; 6 | import java.util.ArrayList; 7 | import java.util.Date; 8 | import java.util.List; 9 | import org.junit.Test; 10 | 11 | /** 12 | * @author hisenyuan 13 | * @time 2018/4/16 15:54 14 | * @description 利用Gson转带有范型的对象 15 | */ 16 | public class TestGson { 17 | @Test 18 | public void parseA2B(){ 19 | List bean1s = new ArrayList<>(); 20 | for (int i = 0; i < 9; i++) { 21 | Bean1 bean1 = new Bean1(); 22 | bean1.setName("hisen_"+i); 23 | bean1.setNow(new Date()); 24 | bean1.setHeight(100L+i); 25 | bean1s.add(bean1); 26 | } 27 | Gson gson = new Gson(); 28 | String toJson = gson.toJson(bean1s); 29 | System.out.println(toJson); 30 | List bean2s=gson.fromJson(toJson, new TypeToken>(){}.getType()); 31 | for (int i = 0; i < bean2s.size(); i++) { 32 | Date now = bean2s.get(i).getNow(); 33 | System.out.println(now); 34 | } 35 | System.out.println(JSON.toJSONString(bean2s)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/json/test.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.json; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | 6 | /** 7 | * 测试fastjson 8 | * Created by hisenyuan on 2017/3/23 at 18:02. 9 | */ 10 | public class test { 11 | 12 | public static void main(String[] args) { 13 | String s = "{'A':'a'}"; 14 | JSONObject obj = JSON.parseObject(s); 15 | System.out.println(obj.get("A")); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/jwt/TestJWT.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.jwt; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import java.io.UnsupportedEncodingException; 5 | 6 | /** 7 | * Created by hisenyuan on 2017/8/17 at 16:13. 8 | */ 9 | public class TestJWT { 10 | 11 | public static void main(String[] args) 12 | throws UnsupportedEncodingException, JsonProcessingException { 13 | String hisen = Jwt.sign("hisen", 60L * 1000L * 30L); 14 | System.out.println(hisen); 15 | String unsign = Jwt.unsign(hisen, String.class); 16 | System.out.println(unsign); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/log4j/Test.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.log4j; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | public class Test { 6 | 7 | private static Logger logger = Logger.getLogger(Test.class); 8 | 9 | public static void main(String[] args) { 10 | logger.debug("This is debug message"); 11 | logger.info("This is info message"); 12 | logger.error("This is error message"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/log4j/log4j2MySQL/sql/log4j.sql: -------------------------------------------------------------------------------- 1 | #创建数据库 2 | CREATE DATABASE log4j; 3 | #使用 4 | USE log4j; 5 | #建表 6 | CREATE TABLE log ( 7 | Class VARCHAR(255) NULL, 8 | Mothod VARCHAR(255) NULL, 9 | CreateTime VARCHAR(255) NULL, 10 | LogLevel VARCHAR(20) NULL, 11 | MSG VARCHAR(555) NULL 12 | ) -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/netty/day1/EchoClientHandler.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.netty.day1; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.buffer.Unpooled; 5 | import io.netty.channel.ChannelHandlerContext; 6 | import io.netty.channel.SimpleChannelInboundHandler; 7 | import io.netty.util.CharsetUtil; 8 | 9 | /** 10 | * @author hisenyuan 11 | * @time 2017/12/27 15:38 12 | * @description 13 | */ 14 | public class EchoClientHandler extends SimpleChannelInboundHandler{ 15 | 16 | @Override 17 | protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf in) 18 | throws Exception { 19 | // 记录已接收信息的转储 20 | System.out.println("Client recevied : " + in.toString(CharsetUtil.UTF_8)); 21 | } 22 | 23 | @Override 24 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 25 | // 当被通知channel是活跃的时候,发送一条消息 26 | ctx.writeAndFlush(Unpooled.copiedBuffer("Netty Rocks!",CharsetUtil.UTF_8)); 27 | } 28 | 29 | @Override 30 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { 31 | // 发生异常,记录并且关闭 32 | cause.printStackTrace(); 33 | ctx.close(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/poi/TestPoiExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.poi; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | /** 9 | * @author hisenyuan 10 | * @time 2018/1/12 17:43 11 | * @description 测试读取 12 | */ 13 | public class TestPoiExcelUtil { 14 | 15 | public static void main(String[] args) { 16 | File file = new File("C:\\work\\document\\银行信息.xlsx"); 17 | try { 18 | // 每一个excelData为一行数据(存放在数组) 19 | List excelData = POIExcelUtil.readExcel(file); 20 | for (String[] data:excelData) { 21 | System.out.println(Arrays.toString(data)); 22 | } 23 | } catch (IOException e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/redisson/MyThread.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.redisson; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | import java.util.concurrent.TimeUnit; 5 | import org.redisson.api.RLock; 6 | import org.redisson.api.RedissonClient; 7 | import redis.clients.jedis.Jedis; 8 | 9 | /** 10 | * @author : hisenyuan 11 | * @date : 2018/3/5 0:40 12 | * @descriptor : 13 | */ 14 | public class MyThread extends Thread{ 15 | 16 | private int num; 17 | private String print; 18 | private RedissonClient client; 19 | private Jedis jedis; 20 | private CountDownLatch latch; 21 | 22 | public MyThread(int num,String print,RedissonClient client,Jedis jedis,CountDownLatch latch) { 23 | this.num = num; 24 | this.print = print; 25 | this.client = client; 26 | this.jedis =jedis; 27 | this.latch = latch; 28 | } 29 | 30 | @Override 31 | public void run() { 32 | RLock lock = client.getLock("hisenyuan1"); 33 | try { 34 | if (lock.tryLock(10,2, TimeUnit.SECONDS)) { 35 | jedis.incrBy("yhx", num); 36 | System.out.println(print+this.getName()); 37 | } 38 | } catch (InterruptedException e) { 39 | e.printStackTrace(); 40 | }finally { 41 | lock.unlock(); 42 | } 43 | latch.countDown(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/redisson/RedissonUtil.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.redisson; 2 | 3 | import com.hisen.utils.JedisUtil; 4 | import org.redisson.Redisson; 5 | import org.redisson.api.RList; 6 | import org.redisson.api.RedissonClient; 7 | import org.redisson.config.Config; 8 | import redis.clients.jedis.Jedis; 9 | 10 | /** 11 | * @author : hisenyuan 12 | * @date : 2018/3/4 22:13 13 | * @descriptor : 14 | */ 15 | public class RedissonUtil { 16 | private static Jedis jedis = JedisUtil.getJedis(); 17 | private static RedissonClient client = null; 18 | 19 | private static final String url ="127.0.0.1:6379"; 20 | 21 | public static RedissonClient getClient() { 22 | if (client == null){ 23 | final RList hisen = client.getList("hisen"); 24 | hisen.add("1"); 25 | Config config = new Config(); 26 | config.useSingleServer().setAddress(url); 27 | client = Redisson.create(config); 28 | } 29 | return client; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/spring/aop/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.spring.aop; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/7/26 at 13:43. 5 | */ 6 | public interface HelloWorld { 7 | 8 | void printHelloWorld(); 9 | 10 | void doPrint(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/spring/aop/HelloWorldImpl1.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.spring.aop; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/7/26 at 13:44. 5 | */ 6 | public class HelloWorldImpl1 implements HelloWorld { 7 | 8 | @Override 9 | public void printHelloWorld() { 10 | System.out.println("Enter HelloWorldImpl1.printHelloWorld()"); 11 | } 12 | 13 | @Override 14 | public void doPrint() { 15 | System.out.println("Enter HelloWorldImpl1.doPrint()"); 16 | return; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/spring/aop/HelloWorldImpl2.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.spring.aop; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/7/26 at 13:45. 5 | */ 6 | public class HelloWorldImpl2 implements HelloWorld { 7 | 8 | @Override 9 | public void printHelloWorld() { 10 | System.out.println("Enter HelloWorldImpl2.printHelloWorld()"); 11 | } 12 | 13 | @Override 14 | public void doPrint() { 15 | System.out.println("Enter HelloWorldImpl2.doPrint()"); 16 | return; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/spring/aop/LogHandler.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.spring.aop; 2 | 3 | /** 4 | * 横切关注点 - 打印日志 5 | * Created by hisenyuan on 2017/7/26 at 14:12. 6 | */ 7 | public class LogHandler { 8 | 9 | public void LogBefore() { 10 | System.out.println("Spring AOP >>>>> Log before method"); 11 | } 12 | 13 | public void LogAfter() { 14 | System.out.println("Spring AOP >>>>> Log after method"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jars/spring/aop/TimeHandler.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jars.spring.aop; 2 | 3 | import java.util.Arrays; 4 | import org.aspectj.lang.JoinPoint; 5 | 6 | /** 7 | * 横切关注点 - 打印时间 8 | * Created by hisenyuan on 2017/7/26 at 13:46. 9 | */ 10 | public class TimeHandler { 11 | 12 | /** 13 | * 打印时间 14 | */ 15 | public void printTime(JoinPoint joinPoint) { 16 | System.out.println("Spring AOP >>>>> CurrentTime = " + System.currentTimeMillis()); 17 | //Object[] getArgs:返回目标方法的参数 18 | //Signature getSignature:返回目标方法的签名 19 | //Object getTarget:返回被织入增强处理的目标对象 20 | //Object getThis:返回AOP框架为目标对象生成的代理对象 21 | System.out.println("执行过的函数相关信息 >>>>> 方法" + joinPoint.getSignature()); 22 | System.out.println("执行过的函数相关信息 >>>>> 参数" + Arrays.asList(joinPoint.getArgs())); 23 | System.out.println("执行过的函数相关信息 >>>>> 目标" + joinPoint.getTarget()); 24 | System.out.println("执行过的函数相关信息 >>>>> 代理" + joinPoint.getThis()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/java8inaction/Calculator.java: -------------------------------------------------------------------------------- 1 | package com.hisen.java8inaction; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/8/3 at 10:29. 5 | */ 6 | public class Calculator { 7 | 8 | interface integerMath { 9 | 10 | int operation(int a, int b); 11 | } 12 | 13 | public int operateBinary(int a, int b, integerMath op) { 14 | return op.operation(a, b); 15 | } 16 | 17 | public static void main(String[] args) { 18 | Calculator calculator = new Calculator(); 19 | /** 20 | * addition和subtraction就可以看做是IntegerMath省略了operation名称的方法。 21 | */ 22 | integerMath addition = ((a, b) -> a + b); 23 | integerMath subtraction = (a, b) -> a - b; 24 | System.out.println("40 + 20 = " + calculator.operateBinary(40, 20, addition)); 25 | System.out.println("40 - 20 = " + calculator.operateBinary(40, 20, subtraction)); 26 | // 40 + 20 = 60 27 | // 40 - 20 = 20 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/java8inaction/ContextTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.java8inaction; 2 | 3 | /** 4 | * 参考:http://www.jianshu.com/p/e7db8fddb8b4 5 | * 编译器通过以下上下文识别Lambda表达式类型: 6 | * 变量声明 7 | * 赋值 8 | * return语句 9 | * 数组初始化 10 | * 方法或构造方法参数 11 | * Lambda表达式体 12 | * 条件语句?: 13 | * 类型转换 14 | * Created by hisenyuan on 2017/8/3 at 11:23. 15 | */ 16 | public class ContextTest { 17 | 18 | static void invoke(Runnable r) { 19 | r.run(); 20 | } 21 | 22 | static T invoke(Callable c) throws Exception { 23 | return c.call(); 24 | } 25 | 26 | public interface Runnable { 27 | 28 | void run(); 29 | } 30 | 31 | public interface Callable { 32 | 33 | V call(); 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | String s = invoke(() -> "done"); 38 | // 最终会调用invoke(Callable),因为Runnable.run没有返回值。所以表达式() -> "done"的类型为Callable。 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/java8inaction/LambdaScopeTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.java8inaction; 2 | 3 | import java.util.function.Consumer; 4 | 5 | /** 6 | * Lambda可以访问 7 | * LambdaScopeTest的成员变量、 8 | * FirstLevel的成员变量、 9 | * methodInFirstLevel的参数变量。 10 | * 11 | * Created by hisenyuan on 2017/8/3 at 10:52. 12 | */ 13 | public class LambdaScopeTest { 14 | public int x = 0; 15 | 16 | class FisrtLevel{ 17 | public int x = 1; 18 | void methodInFirstLevel(int x){ 19 | Consumer myConsumer = (y)->{ 20 | System.out.println("x = " + x); 21 | System.out.println("y = " + y); 22 | // 在lambda中,this不是指向lambda表达式产生的那个SAM对象,而是声明它的外部对象。 23 | System.out.println("this.x = " + this.x); 24 | System.out.println("LambdaScopeTest.this.x = " + LambdaScopeTest.this.x); 25 | }; 26 | myConsumer.accept(9); 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | LambdaScopeTest scopeTest = new LambdaScopeTest(); 32 | LambdaScopeTest.FisrtLevel f = scopeTest.new FisrtLevel(); 33 | f.methodInFirstLevel(23); 34 | // 执行结果 35 | // x = 23 36 | // y = 9 37 | // this.x = 1 38 | // LambdaScopeTest.this.x = 0 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/java8inaction/LambdaSort.java: -------------------------------------------------------------------------------- 1 | package com.hisen.java8inaction; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.Comparator; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * Created by hisenyuan on 2017/8/3 at 11:40. 11 | */ 12 | public class LambdaSort { 13 | 14 | public static void main(String[] args) { 15 | List list = Arrays.asList("hisen", "Get_GCD_LCM", "work", "name", "apple"); 16 | //利用lambda语法 17 | Collections.sort(list, (o1, o2) -> o1.compareTo(o2)); 18 | for (String s : list) { 19 | System.out.println(s); 20 | } 21 | System.out.println("--------"); 22 | //利用匿名内部类 23 | Collections.sort(list, new Comparator() { 24 | @Override 25 | public int compare(String o1, String o2) { 26 | return o2.compareTo(o1);//反过来之后首字母倒序 27 | } 28 | }); 29 | for (String s : list) { 30 | System.out.println(s); 31 | } 32 | 33 | System.out.println("--------"); 34 | //转换大小写 35 | List collect = list.stream().map((String name) -> { 36 | return name.toUpperCase(); 37 | }).collect(Collectors.toList()); 38 | for (String s : collect){ 39 | System.out.println("转换为大写 >>>>> "+s); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/java8inaction/Map2StringTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.java8inaction; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.stream.Collectors; 6 | import org.junit.Test; 7 | 8 | /** 9 | * @author hisenyuan 10 | * @time 2018/5/2 15:14 11 | * @description 12 | */ 13 | public class Map2StringTest { 14 | 15 | @Test 16 | public void test() { 17 | HashMap unSignMapData = new HashMap<>(8); 18 | unSignMapData.put("name","hisen"); 19 | unSignMapData.put("age","25"); 20 | unSignMapData.put("height","233"); 21 | unSignMapData.put("addr","beijing"); 22 | String signData = unSignMapData 23 | .entrySet() 24 | .stream() 25 | .sorted(Map.Entry.comparingByKey()) 26 | .map(entry -> entry.getKey() + "=" + entry.getValue()) 27 | .collect(Collectors.joining("&")); 28 | System.out.println(signData); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/java8inaction/test_5_5/Trader.java: -------------------------------------------------------------------------------- 1 | package com.hisen.java8inaction.test_5_5; 2 | 3 | /** 4 | * @author hisenyuan 5 | * @time 2018/4/21 16:33 6 | * @description 7 | */ 8 | public class Trader { 9 | private final String name; 10 | private final String city; 11 | public Trader(String n, String c){ 12 | this.name = n; 13 | this.city = c; 14 | } 15 | public String getName(){ 16 | return this.name; 17 | } 18 | public String getCity(){ 19 | return this.city; 20 | } 21 | @Override 22 | public String toString(){ 23 | return "Trader:"+this.name + " in " + this.city; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/java8inaction/test_5_5/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.hisen.java8inaction.test_5_5; 2 | 3 | /** 4 | * @author hisenyuan 5 | * @time 2018/4/21 16:34 6 | * @description 7 | */ 8 | public class Transaction { 9 | private final Trader trader; 10 | private final int year; 11 | private final int value; 12 | public Transaction(Trader trader, int year, int value){ 13 | this.trader = trader; 14 | this.year = year; 15 | this.value = value; 16 | } 17 | public Trader getTrader(){ 18 | return this.trader; 19 | } 20 | public int getYear(){ 21 | return this.year; 22 | } 23 | public int getValue(){ 24 | return this.value; 25 | } 26 | @Override 27 | public String toString(){ 28 | return "{" + this.trader + ", " + 29 | "year: "+this.year+", " + 30 | "value:" + this.value +"}"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/javaGaiShu/page91test20/JingTaiDaiMaKuai.java: -------------------------------------------------------------------------------- 1 | package com.hisen.javaGaiShu.page91test20; 2 | 3 | /** 4 | * 静态代码块相关 5 | * 6 | * @author hisenyuan 2017年2月27日 下午9:33:04 7 | */ 8 | public class JingTaiDaiMaKuai { 9 | 10 | private static String a; 11 | 12 | static { 13 | JingTaiDaiMaKuai.a = "我学习了很多语言"; 14 | System.out.println(a); 15 | JingTaiDaiMaKuai t = new JingTaiDaiMaKuai(); 16 | t.fina(); 17 | t.b = "Java语言"; 18 | System.out.println(t.b); 19 | } 20 | 21 | static { 22 | JingTaiDaiMaKuai.a = "I Love Java"; 23 | System.out.println(a); 24 | } 25 | 26 | static { 27 | JingTaiDaiMaKuai.a = "我还将继续学习下去"; 28 | System.out.println(a); 29 | } 30 | 31 | private String b; 32 | 33 | public static void main(String[] args) { 34 | 35 | } 36 | 37 | private void fina() { 38 | System.out.println("但是我最喜欢的是:"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/javaGaiShu/test17/IsRen.java: -------------------------------------------------------------------------------- 1 | package com.hisen.javaGaiShu.test17; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * 计算某年的某个月有多少天 7 | * 影响因子有是否为闰年 8 | * 9 | * @author hisenyuan 2017年2月10日 下午10:00:33 10 | */ 11 | public class IsRen { 12 | 13 | @SuppressWarnings("resource") 14 | public static void main(String[] args) { 15 | Scanner sc = new Scanner(System.in); 16 | System.out.println("请输入年份(注:必须大于1990):"); 17 | int year = sc.nextInt(); 18 | System.out.println("请输入月份"); 19 | int month = sc.nextInt(); 20 | 21 | boolean isRen; 22 | if (year % 4 == 0 && year % 100 != 0 && year % 400 == 0) { 23 | System.out.println(year + "闰年"); 24 | isRen = true; 25 | } else { 26 | isRen = false; 27 | } 28 | 29 | int day = 0; 30 | switch (month) { 31 | case 1: 32 | case 3: 33 | case 5: 34 | case 7: 35 | case 8: 36 | case 10: 37 | case 12: 38 | day = 31; 39 | break; 40 | case 4: 41 | case 6: 42 | case 9: 43 | case 11: 44 | day = 30; 45 | break; 46 | default: 47 | if (isRen) { 48 | day = 29; 49 | } else { 50 | day = 28; 51 | } 52 | break; 53 | 54 | } 55 | System.out.println(year + "年" + month + "月共有" + day + "天"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/javaGaiShu/test2/AddButton.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Java Applet 5 | 6 | 7 | 8 | 9 | > -------------------------------------------------------------------------------- /src/main/java/com/hisen/javaGaiShu/test2/AddButton.java: -------------------------------------------------------------------------------- 1 | package com.hisen.javaGaiShu.test2; 2 | 3 | import java.applet.Applet; 4 | import java.awt.Button; 5 | import java.awt.Color; 6 | 7 | @SuppressWarnings("serial") 8 | public class AddButton extends Applet { 9 | 10 | Button button; 11 | 12 | public void init() { 13 | setBackground(Color.lightGray); 14 | button = new Button("我是按钮"); 15 | add(button); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/javaGaiShu/test9/Scanner.java: -------------------------------------------------------------------------------- 1 | package com.hisen.javaGaiShu.test9; 2 | 3 | /** 4 | * 文档注释 5 | * 乘法表 6 | * 7 | * @author hisenyuan 2017年2月10日 下午9:44:18 8 | */ 9 | public class Scanner { 10 | 11 | public static void main(String[] args) { 12 | System.out.print("乘法口诀表:"); 13 | for (int i = 0; i <= 9; i++) { 14 | for (int j = 1; j <= i; j++) { 15 | System.out.print(j + "*" + i + "=" + j * i + "\t"); 16 | } 17 | System.out.println(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/javanet/JavaNetTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.javanet; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | 6 | /** 7 | * 参考:http://www.cnblogs.com/oubo/archive/2012/01/16/2394641.html 8 | * 9 | * @author hisenyuan 2016年4月7日 下午3:40:58 10 | */ 11 | public class JavaNetTest { 12 | 13 | public static void main(String[] args) { 14 | 15 | } 16 | 17 | /** 18 | * Java中的InetAddress是一个代表IP地址的封装。 19 | * IP地址可以由字节数组和字符串来分别表示, 20 | * InetAddress将IP地址以对象的形式进行封装, 21 | * 可以更方便的操作和获取其属性。 22 | * InetAddress没有构造方法, 23 | * 可以通过两个静态方法获得它的对象。 24 | */ 25 | public static void InetAddressTest() throws IOException { 26 | // 根据主机名来获取对应的InetAddress实例 27 | InetAddress ip = InetAddress.getByName("www.baidu.com"); 28 | // 判断是否可以访问 29 | System.out.println("百度是否可以访问:" + ip.isReachable(2000)); 30 | // 获取InetAddress实例的ip字符串 31 | System.out.println(ip.getHostAddress()); 32 | // 根据原始ip地址(字节数组)来获取对应的InetAddress实例 33 | InetAddress local = InetAddress.getByAddress(new byte[]{127, 0, 0, 1}); 34 | System.out.println("本机是否可以访问:" + local.isReachable(2000)); 35 | //获取InetAddress实例对应的全限定域名 36 | System.out.println(local.getCanonicalHostName()); 37 | } 38 | 39 | /** 40 | * 创建URL对象,并通过调用openConnection方法获得URLConnection对象; 41 | * 设置URLConnection参数和普通请求属性; 42 | * 向远程资源发送请求; 43 | * 远程资源变为可用,程序可以访问远程资源的头字段和通过输入流来读取远程资源返回的信息。 44 | */ 45 | public static void URLTest() { 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/javanet/RegxTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.javanet; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class RegxTest { 7 | 8 | public static void main(String[] args) { 9 | 10 | // 按指定模式在字符串查找 11 | String line = "magnet:?xt=urn:btih:bd51204cfd4c815727cefff3f2633f12ec7ad9cd&tr=http://bt.mp4ba.com:2710/announce"; 12 | String pattern = "(magnet:\\?xt=).*"; 13 | // 创建 Pattern 对象 14 | Pattern r = Pattern.compile(pattern); 15 | // 现在创建 matcher 对象 16 | Matcher m = r.matcher(line); 17 | while (m.find()) { 18 | System.out.println("Found value: " + m.group(0)); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/javanet/SubStrTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.javanet; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class SubStrTest { 7 | 8 | public static void main(String[] args) { 9 | String a = "HiSEN - hisenyuan's blog"; 10 | int x = a.indexOf(""); 11 | int y = a.indexOf(""); 12 | String b = a.substring(x, y); 13 | String f = b.replace("", ""); 14 | System.out.println(f); 15 | 16 | String title = null; 17 | String pattern1 = "<title>(.*)"; 18 | // 创建 Pattern 对象 19 | Pattern r = Pattern.compile(pattern1); 20 | // 现在创建 matcher 对象 21 | Matcher m = r.matcher(a); 22 | //循环获取目标链接 23 | while (m.find()) { 24 | //把获取到的链接装进去 25 | title = (m.group(0)); 26 | System.out.println(m.group(0)); 27 | } 28 | System.out.println(title); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jdk/agent/CGlibAgent.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jdk.agent; 2 | 3 | import net.sf.cglib.proxy.Enhancer; 4 | import net.sf.cglib.proxy.MethodInterceptor; 5 | import net.sf.cglib.proxy.MethodProxy; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | /** 10 | * @Author hisenyuan 11 | * @Description $end$ 12 | * @Date 2019/3/29 23:37 13 | */ 14 | public class CGlibAgent implements MethodInterceptor { 15 | 16 | public Object getInstance(Class clazz) { 17 | Enhancer enhancer = new Enhancer(); 18 | enhancer.setSuperclass(clazz); 19 | // 回调方法 20 | enhancer.setCallback(this); 21 | // 创建代理对象 22 | return enhancer.create(); 23 | } 24 | 25 | @Override 26 | public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { 27 | System.out.println("-> before invoking"); 28 | //真正调用 29 | Object ret = methodProxy.invokeSuper(o, objects); 30 | System.out.println("-> after invoking"); 31 | return ret; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jdk/agent/DynamicAgent.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jdk.agent; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Proxy; 6 | 7 | /** 8 | * @Author hisenyuan 9 | * @Description $end$ 10 | * @Date 2019/3/29 23:17 11 | */ 12 | public class DynamicAgent { 13 | // implement InvocationHandler interface,init oriObject 14 | static class MyHandler implements InvocationHandler { 15 | private Object proxy; 16 | 17 | MyHandler(Object proxy) { 18 | this.proxy = proxy; 19 | } 20 | 21 | // customer invoke 22 | @Override 23 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 24 | System.out.println("-> before invoking"); 25 | // really invoke 26 | Object ret = method.invoke(this.proxy, args); 27 | System.out.println("-> after invoking"); 28 | return ret; 29 | } 30 | } 31 | 32 | // return a modify object 33 | static Object agent(Class interfaceClazz, Object proxy) { 34 | final Class[] classes = {interfaceClazz}; 35 | final MyHandler myHandler = new MyHandler(proxy); 36 | return Proxy.newProxyInstance(interfaceClazz.getClassLoader(), classes, myHandler); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jdk/agent/service/Fruit.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jdk.agent.service; 2 | 3 | /** 4 | * @Author hisenyuan 5 | * @Description $end$ 6 | * @Date 2019/3/29 23:18 7 | */ 8 | public interface Fruit { 9 | public void show(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jdk/agent/service/impl/Apple.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jdk.agent.service.impl; 2 | 3 | import com.hisen.jdk.agent.service.Fruit; 4 | 5 | /** 6 | * @Author hisenyuan 7 | * @Description $end$ 8 | * @Date 2019/3/29 23:18 9 | */ 10 | public class Apple implements Fruit { 11 | 12 | @Override 13 | public void show() { 14 | System.out.println("Apple show method is invoked"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/jdk/agent/service/impl/Orange.java: -------------------------------------------------------------------------------- 1 | package com.hisen.jdk.agent.service.impl; 2 | 3 | import com.hisen.jdk.agent.service.Fruit; 4 | 5 | /** 6 | * @Author hisenyuan 7 | * @Description $end$ 8 | * @Date 2019/3/29 23:26 9 | */ 10 | public class Orange implements Fruit { 11 | @Override 12 | public void show() { 13 | System.out.println("Orange show method is invoked"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatis/SimplePojo/SimplePojo.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatis.SimplePojo; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * idea 上的 MybatisHelper 自动生成代码插件(sql,dao,xml,services) 7 | * Created by hisenyuan on 2017/4/19 at 11:21. 8 | */ 9 | public class SimplePojo { 10 | 11 | private int id; 12 | private String name; 13 | private int age; 14 | private Date date; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatis/SimplePojo/SimplePojo.sql: -------------------------------------------------------------------------------- 1 | -- auto Generated on 2017-04-19 11:22:16 2 | -- DROP TABLE IF EXISTS `simple_pojo`; 3 | CREATE TABLE simple_pojo( 4 | `id` INTEGER(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id', 5 | `name` VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'name', 6 | `age` INTEGER(12) NOT NULL DEFAULT -1 COMMENT 'age', 7 | `date` DATETIME NOT NULL DEFAULT '1000-01-01 00:00:00' COMMENT 'date', 8 | PRIMARY KEY (`id`) 9 | )ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT 'simple_pojo'; 10 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatis/SimplePojo/SimplePojoDao.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatis.SimplePojo; 2 | 3 | import java.util.List; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | public interface SimplePojoDao { 7 | 8 | int insert(@Param("pojo") SimplePojo pojo); 9 | 10 | int insertList(@Param("pojos") List pojo); 11 | 12 | List select(@Param("pojo") SimplePojo pojo); 13 | 14 | int update(@Param("pojo") SimplePojo pojo); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatis/SimplePojo/SimplePojoService.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatis.SimplePojo; 2 | 3 | import java.util.List; 4 | import javax.annotation.Resource; 5 | import org.springframework.stereotype.Service; 6 | 7 | @Service 8 | public class SimplePojoService { 9 | 10 | @Resource 11 | private SimplePojoDao simplePojoDao; 12 | 13 | public int insert(SimplePojo pojo) { 14 | return simplePojoDao.insert(pojo); 15 | } 16 | 17 | public int insertList(List pojos) { 18 | return simplePojoDao.insertList(pojos); 19 | } 20 | 21 | public List select(SimplePojo pojo) { 22 | return simplePojoDao.select(pojo); 23 | } 24 | 25 | public int update(SimplePojo pojo) { 26 | return simplePojoDao.update(pojo); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatis/model/Appointment.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatis.model; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * MyBatis-generator自动生成 7 | */ 8 | public class Appointment extends AppointmentKey { 9 | 10 | /** 11 | * This field was generated by MyBatis Generator. 12 | * This field corresponds to the database column appointment.appoint_time 13 | * 14 | * @mbggenerated Wed Mar 22 09:54:59 CST 2017 15 | */ 16 | private Date appointTime; 17 | 18 | /** 19 | * This method was generated by MyBatis Generator. 20 | * This method returns the value of the database column appointment.appoint_time 21 | * 22 | * @return the value of appointment.appoint_time 23 | * @mbggenerated Wed Mar 22 09:54:59 CST 2017 24 | */ 25 | public Date getAppointTime() { 26 | return appointTime; 27 | } 28 | 29 | /** 30 | * This method was generated by MyBatis Generator. 31 | * This method sets the value of the database column appointment.appoint_time 32 | * 33 | * @param appointTime the value for appointment.appoint_time 34 | * @mbggenerated Wed Mar 22 09:54:59 CST 2017 35 | */ 36 | public void setAppointTime(Date appointTime) { 37 | this.appointTime = appointTime; 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatisStudy/no4/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatisStudy.no4.dao; 2 | 3 | import com.hisen.mybatisStudy.po.User; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by hisen on 17-3-25. 8 | */ 9 | public interface UserDao { 10 | 11 | //根据id查询用户信息 12 | public User findUserById(int id) throws Exception; 13 | 14 | //根据用户名列查询用户列表 15 | public List findUserByName(String name) throws Exception; 16 | 17 | //添加用户信息 18 | public void insertUser(User user) throws Exception; 19 | 20 | //删除用户信息 21 | public void deleteUser(int id) throws Exception; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatisStudy/no4/dao/UserDaoImplTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatisStudy.no4.dao; 2 | 3 | import com.hisen.mybatisStudy.po.User; 4 | import java.io.InputStream; 5 | import org.apache.ibatis.io.Resources; 6 | import org.apache.ibatis.session.SqlSessionFactory; 7 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | /** 12 | * Created by hisen on 17-3-25. 13 | */ 14 | public class UserDaoImplTest { 15 | 16 | // 创建sqlSessionFactory 17 | private SqlSessionFactory sqlSessionFactory; 18 | 19 | // 此方法是在执行testFindUserById之前执行 20 | @Before 21 | public void setUp() throws Exception { 22 | // mybatis配置文件 23 | String resource = "SqlMapConfig.xml"; 24 | // 得到配置文件流 25 | InputStream inputStream = Resources.getResourceAsStream(resource); 26 | // 创建会话工厂,传入mybatis的配置文件信息 27 | sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); 28 | } 29 | 30 | @Test 31 | public void testFindUserById() throws Exception { 32 | // 创建UserDao的对象 33 | UserDao userDao = new UserDaoImpl(sqlSessionFactory); 34 | // 调用UserDao的方法 35 | User user = userDao.findUserById(1); 36 | System.out.println(user); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatisStudy/no4/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatisStudy.no4.mapper; 2 | 3 | import com.hisen.mybatisStudy.po.User; 4 | import com.hisen.mybatisStudy.po.UserCustom; 5 | import com.hisen.mybatisStudy.po.UserQueryVo; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by hisen on 17-3-25. 10 | */ 11 | public interface UserMapper { 12 | 13 | //根据id查询用户信息 14 | public User findUserById(int id) throws Exception; 15 | 16 | //根据用户名列查询用户列表 17 | public List findUserByName(String name) throws Exception; 18 | 19 | //添加用户信息 20 | public void insertUser(User user) throws Exception; 21 | 22 | //删除用户信息 23 | public void deleteUser(int id) throws Exception; 24 | 25 | //更新用户 26 | public void updateUser(User user) throws Exception; 27 | 28 | //用户信息综合查询 29 | public List findUserList(UserQueryVo userQueryVo) throws Exception; 30 | 31 | //用户信息综合查询总数 32 | public int findUserCount(UserQueryVo userQueryVo) throws Exception; 33 | 34 | //根据id查询用户信息,使用resultMap输出 35 | public User findUserByIdResultMap(int id) throws Exception; 36 | 37 | //用户信息综合查询 - 带判断条件 38 | public List findUserList_if(UserQueryVo userQueryVo) throws Exception; 39 | 40 | //用户信息综合查询总数 - 带判断条件 41 | public int findUserCount_if(UserQueryVo userQueryVo) throws Exception; 42 | 43 | //用户信息综合查询 - foreach 44 | public List findUserList_one(UserQueryVo userQueryVo) throws Exception; 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatisStudy/po/User.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatisStudy.po; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Created by hisen on 17-3-25. 7 | */ 8 | public class User { 9 | 10 | private int id; 11 | private String username;// 用户姓名 12 | private String sex;// 性别 13 | private Date birthday;// 生日 14 | private String address;// 地址 15 | 16 | @Override 17 | public String toString() { 18 | return "User{" + 19 | "id=" + id + 20 | ", username='" + username + '\'' + 21 | ", sex='" + sex + '\'' + 22 | ", birthday=" + birthday + 23 | ", address='" + address + '\'' + 24 | '}'; 25 | } 26 | 27 | public int getId() { 28 | return id; 29 | } 30 | 31 | public void setId(int id) { 32 | this.id = id; 33 | } 34 | 35 | public String getUsername() { 36 | return username; 37 | } 38 | 39 | public void setUsername(String username) { 40 | this.username = username; 41 | } 42 | 43 | public String getSex() { 44 | return sex; 45 | } 46 | 47 | public void setSex(String sex) { 48 | this.sex = sex; 49 | } 50 | 51 | public Date getBirthday() { 52 | return birthday; 53 | } 54 | 55 | public void setBirthday(Date birthday) { 56 | this.birthday = birthday; 57 | } 58 | 59 | public String getAddress() { 60 | return address; 61 | } 62 | 63 | public void setAddress(String address) { 64 | this.address = address; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatisStudy/po/UserCustom.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatisStudy.po; 2 | 3 | /** 4 | * Created by hisen on 17-3-25. 5 | */ 6 | public class UserCustom extends User { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/mybatisStudy/po/UserQueryVo.java: -------------------------------------------------------------------------------- 1 | package com.hisen.mybatisStudy.po; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by hisen on 17-3-25. 7 | */ 8 | public class UserQueryVo { 9 | //在这里包装所需要的查询条件 10 | 11 | //用户查询条件 12 | private UserCustom userCustom; 13 | //可以包装其它的查询条件,订单、商品 14 | //.... 15 | //传入多个id 16 | private List ids; 17 | 18 | public UserCustom getUserCustom() { 19 | return userCustom; 20 | } 21 | 22 | public void setUserCustom(UserCustom userCustom) { 23 | this.userCustom = userCustom; 24 | } 25 | 26 | public List getIds() { 27 | return ids; 28 | } 29 | 30 | public void setIds(List ids) { 31 | this.ids = ids; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/programLogicOfThinking/Part5.java: -------------------------------------------------------------------------------- 1 | package com.hisen.programLogicOfThinking; 2 | 3 | /** 4 | * 关于类的基本概念 5 | * Created by hisen on 17-8-15. 6 | * E-mail: hisenyuan@gmail.com 7 | */ 8 | public class Part5 { 9 | 10 | /** 11 | * 与类方法一样,类变量可以直接通过类名访问 12 | */ 13 | // 类变量 14 | public static final double PI = 3.14159265358979323846; 15 | // 类方法 16 | public static void countArea(double r){ 17 | System.out.println(Part5.PI * r * r); 18 | } 19 | 20 | /** 21 | * 实例变量和实例方法 22 | * 23 | * 通过对象来访问和操作其内部的数据是一种基本的面向对象思维 24 | */ 25 | // 实例变量 26 | private int x; 27 | private int y; 28 | // 实例方法,计算直角三角形的斜边长 29 | public double distance(){ 30 | return Math.sqrt(x*x + y*y); 31 | } 32 | 33 | public static void main(String[] args) { 34 | // 调用类方法,在其他类也可以直接通过这种方式调用 35 | Part5.countArea(2.0); 36 | // 创建实例/对象 37 | Part5 p = new Part5(); 38 | // 给实例变量赋值 39 | p.x = 3; 40 | p.y = 4; 41 | // 调用实例方法 42 | double distance = p.distance(); 43 | System.out.println(distance); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/programLogicOfThinking/README.md: -------------------------------------------------------------------------------- 1 | ## 计算机程序的思维逻辑 2 | 这个系列的文章还不错 3 | 4 | [目录---微信公众号](http://mp.weixin.qq.com/s/u_WmkE5meMWuZ81G5gHhBQ) 5 | 6 | [目录---掘金(1-6缺失)](https://juejin.im/user/5791632a165abd00584bb496) 7 | 8 | ## 说明 9 | 版权归原作者所有 10 | 11 | 感觉文章不错,一边看一边实践。 12 | 13 | 有时候从头开始学习也会有另一番风味。 14 | 15 | 兴趣是最好的老师,唯有坚持才是实现梦想的唯一途径。 -------------------------------------------------------------------------------- /src/main/java/com/hisen/programLogicOfThinking/basics/Operation.java: -------------------------------------------------------------------------------- 1 | package com.hisen.programLogicOfThinking.basics; 2 | 3 | /** 4 | * Created by hisen on 17-8-13. 5 | * E-mail: hisenyuan@gmail.com 6 | */ 7 | public class Operation { 8 | 9 | public static void main(String[] args) { 10 | //2147483647是int能表示的最大值 11 | int a = 2147483647 * 2;//结果 -2 12 | // 正确姿势 13 | long a1 = 2147483647 * 2L; 14 | System.out.printf("错误:%s,正确:%s\n", a, a1); 15 | // 错误:-2,正确:4294967294 16 | 17 | // 整数相除不是四舍五入,而是取整 18 | double d = 10 / 4; 19 | // 正确姿势 20 | double d1 = 10 / 4.0; 21 | double d2 = 10 / (double) 4; 22 | System.out.printf("错误:%s,正确:%s,正确:%s\n", d, d1, d2); 23 | // 错误:2.0,正确:2.5,正确:2.5 24 | 25 | /** 26 | * 小数计算结果不精确 27 | * 这需要理解float和double的二进制表示 28 | */ 29 | float f = 0.1f * 0.1f; 30 | double dd = 0.1 * 0.1; 31 | System.out.printf("惊人的结果f = %s,dd = %s\n", f, dd); 32 | // 惊人的结果f = 0.010000001,dd = 0.010000000000000002 33 | 34 | /** 35 | * 比较 36 | * == 判断的是对象是否相同,而不是内容是否相同 37 | */ 38 | int[] arrA = new int[] {1,2,3}; 39 | int[] arrB = new int[] {1,2,3}; 40 | System.out.println(arrA==arrB);//false 41 | 42 | /** 43 | * 小结 44 | * 正整数相乘的结果居然出现了负数 45 | * 非常基本的小数运算结果居然不精确 46 | * 字符类型怎么也可以进行算术运算和比较 47 | */ 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/regex/IPTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.regex; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * 提取ip地址 8 | * Created by hisenyuan on 2017/8/3 at 14:07. 9 | */ 10 | public class IPTest { 11 | 12 | public static void main(String[] args) { 13 | String s = "114.245.46.24 - - [02/Aug/2017:06:55:44 +0800] \"POST /cloud/?mod=private HTTP/1.1\" 200 18 \"-\" \"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)\"\n"; 14 | String regex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"; 15 | Pattern p = Pattern.compile(regex); 16 | Matcher matcher = p.matcher(s); 17 | // System.out.println(matcher.group()); 18 | //必须得先判断,否则会报异常:java.lang.IllegalStateException 19 | if (matcher.find()) { 20 | System.out.println(matcher.group()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/regex/IsEmail.java: -------------------------------------------------------------------------------- 1 | package com.hisen.regex; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * 正则表达式验证邮箱 8 | */ 9 | public class IsEmail { 10 | 11 | public static void main(String[] args) { 12 | String email = "hisenyuan@gmail.com"; 13 | String patternstr = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; 14 | Pattern pattern = Pattern.compile(patternstr); 15 | Matcher matcher = pattern.matcher(email); 16 | if (matcher.matches()) { 17 | System.out.println("邮箱地址正确"); 18 | } else { 19 | System.out.println("邮箱地址错误"); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/regex/PWD.java: -------------------------------------------------------------------------------- 1 | package com.hisen.regex; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | import org.junit.Test; 6 | 7 | /** 8 | * 匹配解压密码 9 | * Created by hisenyuan on 2017/8/8 at 21:27. 10 | */ 11 | public class PWD { 12 | 13 | public static void main(String[] args) { 14 | 15 | } 16 | 17 | /** 18 | * 获取文档中的解压密码 19 | */ 20 | @Test 21 | public void getPwd(){ 22 | String s = "

\n" 23 | + "\t解压密码:www.250sb.cn__1324\n" 24 | + "

"; 25 | //匹配 26 | String regex = "解压密码.*\\s"; 27 | Pattern p = Pattern.compile(regex); 28 | Matcher matcher = p.matcher(s); 29 | String t = "\\s"; 30 | if (matcher.find()){ 31 | System.out.println(matcher.group()); 32 | }else { 33 | System.out.println(t); 34 | } 35 | } 36 | 37 | @Test 38 | public void isHaveUrl(){ 39 | String url = "这是京东官网:www.jd.com"; 40 | Pattern pattern = Pattern.compile(".*www.jd.com.*"); 41 | Matcher matcher = pattern.matcher(url); 42 | if (matcher.find()){ 43 | System.out.println(matcher.group()); 44 | }else { 45 | System.out.println("未匹配"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/File2Base64.java: -------------------------------------------------------------------------------- 1 | package com.hisen.string; 2 | 3 | import com.hisen.utils.Base64Util; 4 | import com.hisen.utils.File2ByteArraysUtil; 5 | 6 | /** 7 | * Created by hisenyuan on 2017/4/18 at 18:13. 8 | */ 9 | public class File2Base64 { 10 | 11 | public static void main(String[] args) { 12 | byte[] bytes = File2ByteArraysUtil.file2Bytes("src/main/java/com/hisen/string/text/tomcat.png"); 13 | //图片加密为base64 14 | String s = Base64Util.encodeBase64(bytes); 15 | System.out.println("图片经Base64加密后的字符:" + s); 16 | //解密 17 | byte[] s1 = Base64Util.decodeBase64(s); 18 | //字符串转换回图片 19 | File2ByteArraysUtil.bytes2File(s1, "src/main/java/com/hisen/string/text/build.png"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/StringSpecharsHandle.java: -------------------------------------------------------------------------------- 1 | package com.hisen.string; 2 | 3 | public class StringSpecharsHandle { 4 | 5 | public static void main(String[] args) { 6 | String s = "\\大/家\\好\b我\f是\n李\r刚\t"; 7 | System.out.println(string2Json(s)); 8 | } 9 | 10 | /** 11 | * 特殊字符处理,比如:“\A1;1300” 12 | * 13 | * @return string 14 | */ 15 | public static String string2Json(String s) { 16 | StringBuffer sb = new StringBuffer(); 17 | for (int i = 0; i < s.length(); i++) { 18 | char c = s.charAt(i); 19 | switch (c) { 20 | case '\"': 21 | sb.append("\\\""); 22 | break; 23 | case '\\': 24 | sb.append("\\\\"); 25 | break; 26 | case '/': 27 | sb.append("\\/"); 28 | break; 29 | case '\b': 30 | sb.append("\\b"); 31 | break; 32 | case '\f': 33 | sb.append("\\f"); 34 | break; 35 | case '\n': 36 | sb.append("\\n"); 37 | break; 38 | case '\r': 39 | sb.append("\\r"); 40 | break; 41 | case '\t': 42 | sb.append("\\t"); 43 | break; 44 | default: 45 | sb.append(c); 46 | } 47 | } 48 | return sb.toString(); 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/split/ReplacePhoneNumber.java: -------------------------------------------------------------------------------- 1 | package com.hisen.string.split; 2 | 3 | /** 4 | * 手机号中间四位脱敏 5 | * Created by hisenyuan on 2017/8/22 at 19:24. 6 | */ 7 | public class ReplacePhoneNumber { 8 | 9 | public static void main(String[] args) { 10 | String p = "15520080808"; 11 | String s = p.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); 12 | System.out.println(s); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/split/SplitLength.java: -------------------------------------------------------------------------------- 1 | package com.hisen.string.split; 2 | 3 | public class SplitLength { 4 | 5 | public static void main(String[] args) { 6 | String s = "5||1||||||||||||"; 7 | int i = s.split("\\|", -1).length; 8 | System.out.println(i);//15 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/split/SplitString.java: -------------------------------------------------------------------------------- 1 | package com.hisen.string.split; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * string line = "20E WED 01PM 0E"; 8 | * 转换为下面的输出结果 9 | * 10 | * @author hisenyuan 2016年4月7日 下午3:16:36 11 | */ 12 | public class SplitString { 13 | 14 | public static void main(String[] args) { 15 | Pattern p = Pattern.compile("(\\d+)(\\w+)\\s+(\\w+)\\s+(\\d+)(\\w+)\\s+(\\d+)(\\w+)"); 16 | 17 | String line = "20E WED 01PM 0E"; 18 | Matcher m = p.matcher(line); 19 | if (!m.matches()) { 20 | throw new IllegalArgumentException("Bad input: " + line); 21 | } else { 22 | int fDegree = Integer.parseInt(m.group(1)); 23 | String fDegreeEW = m.group(2); 24 | String day = m.group(3); 25 | int time = Integer.parseInt(m.group(4)); 26 | String amPm = m.group(5); 27 | int sDegree = Integer.parseInt(m.group(6)); 28 | String sDegreeEW = m.group(7); 29 | 30 | System.out.println("1:" + fDegree); 31 | System.out.println("2:" + fDegreeEW); 32 | System.out.println("3:" + day); 33 | System.out.println("4:" + time); 34 | System.out.println("5:" + amPm); 35 | System.out.println("6:" + sDegree); 36 | System.out.println("7:" + sDegreeEW); 37 | // 输出结果 38 | // 1:20 39 | // 2:E 40 | // 3:WED 41 | // 4:1 42 | // 5:PM 43 | // 6:0 44 | // 7:E 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/split/Str2List.java: -------------------------------------------------------------------------------- 1 | package com.hisen.string.split; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | /** 10 | * 特殊字符串转arraylist 利用正则表达式 11 | * 12 | * @author hisenyuan 13 | */ 14 | public class Str2List { 15 | 16 | public static void main(String[] args) { 17 | function1(); 18 | System.out.println("=====分割线====="); 19 | function2(); 20 | 21 | } 22 | 23 | /* 24 | * 利用正则表达式 25 | */ 26 | public static void function1() { 27 | String st = "[\"2.2.2.2\",\"1.1.1.1\",\"6.6.6.6\",\"4.4.4.4\"]"; 28 | String patternString = "(\\d\\.\\d\\.\\d\\.\\d)"; 29 | Pattern pattern = Pattern.compile(patternString); 30 | Matcher matcher = pattern.matcher(st); 31 | ArrayList list = new ArrayList<>(); 32 | while (matcher.find()) { 33 | list.add(matcher.group(1)); 34 | } 35 | for (String item : list) { 36 | System.out.println("" + item); 37 | } 38 | 39 | } 40 | 41 | /** 42 | * 简单粗暴,直接去掉多余字符,按逗号分割 43 | */ 44 | public static void function2() { 45 | String ipAdd = "[\"2.2.2.2\",\"1.1.1.1\",\"6.6.6.6\",\"4.4.4.4\"]"; 46 | List list1 = Arrays 47 | .asList(ipAdd.replaceAll("\\[|\\]", "").replaceAll("\"", "").split(",")); 48 | for (String s : list1) { 49 | System.out.println(s); 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/stringbuilder/TestSBDelete.java: -------------------------------------------------------------------------------- 1 | package com.hisen.string.stringbuilder; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * @author hisenyuan 7 | * @time 2018/4/17 22:11 8 | * @description 删除Str最后一个字符 9 | */ 10 | public class TestSBDelete { 11 | @Test 12 | public void testDeleteCharAt(){ 13 | StringBuilder builder = new StringBuilder(); 14 | builder.append("a").append("=").append("b").append("&"); 15 | System.out.println(builder.deleteCharAt(builder.length()-1).toString()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/text/build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hisenyuan/IDEAPractice/d44f90a385688fdaf071035519854d5357286f8a/src/main/java/com/hisen/string/text/build.png -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/text/str2File.txt: -------------------------------------------------------------------------------- 1 | hello ---> aGVsbG8= 2 | hello ---> aGVsbG8= 3 | hello ---> hello 4 | hello ---> aGVsbG8= 5 | hisen ---> hisen 6 | hisen ---> aGlzZW4= 7 | hisen ---> aGlzZW4= 8 | aGlzZW4= ---> hisen 9 | hisen ---> aGlzZW4= 10 | aGlzZW4= ---> hisen 11 | hisen ---> aGlzZW4= 12 | aGlzZW4= ---> hisen 13 | aGlzZW4= 14 | aGlzZW4= ---> hisen 15 | hisen ---> aGlzZW4= 16 | aGlzZW4= ---> hisen 17 | aGlzZW4= 18 | aGlzZW4= ---> hisen 19 | hisen ---> aGlzZW4= 20 | aGlzZW4= ---> hisen 21 | hisen ---> aGlzZW4= 22 | aGlzZW4= ---> hisen 23 | aGlzZW4= ---> hisen 24 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/string/text/tomcat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hisenyuan/IDEAPractice/d44f90a385688fdaf071035519854d5357286f8a/src/main/java/com/hisen/string/text/tomcat.png -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/Dp.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | /** 4 | * @Author hisenyuan 5 | * @Description $end$ 6 | * @Date 2018/12/10 16:46 7 | */ 8 | public class Dp { 9 | 10 | public static void main(String[] args) { 11 | int[] ori = new int [200]; 12 | for (int i = 0; i < 199; i++) { 13 | ori[i] = i + 1; 14 | } 15 | final int i = coinChange(ori, 2000); 16 | System.out.println(i); 17 | } 18 | public static int coinChange(int[] coins, int amount) { 19 | if(amount==0) return 0; 20 | 21 | int[] dp = new int [amount+1]; 22 | dp[0]=0; // do not need any coin to get 0 amount 23 | for(int i=1;i<=amount; i++) 24 | dp[i]= Integer.MAX_VALUE; 25 | for(int i=0; i<=amount; i++){ 26 | for(int coin: coins){ 27 | if(i+coin <=amount){ 28 | if(dp[i]==Integer.MAX_VALUE){ 29 | dp[i+coin] = dp[i+coin]; 30 | }else{ 31 | dp[i+coin] = Math.min(dp[i+coin], dp[i]+1); 32 | } 33 | } 34 | } 35 | } 36 | 37 | if(dp[amount] >= Integer.MAX_VALUE) 38 | return -1; 39 | 40 | return dp[amount]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/FileHeaderTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | /** 4 | * @author : hisenyuan@gmail.com 5 | * @date : 2017/10/17 10:10 6 | */ 7 | public class FileHeaderTest { 8 | 9 | public static void main(String[] args) { 10 | System.out.println("阿里巴巴Java开发规范手册"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/GeometricProgression.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | /** 10 | * @Author hisenyuan 11 | * @Description $end$ 12 | * @Date 2018/10/11 12:18 13 | */ 14 | public class GeometricProgression { 15 | public static void main(String[] args) { 16 | int a1 = 5; 17 | int n = 9; 18 | List aNs = new ArrayList<>(); 19 | for (int i = 1; i <= n; i++) { 20 | aNs.add((int) Math.pow(a1,i)); 21 | } 22 | System.out.println(JSON.toJSONString(aNs)); 23 | 24 | 25 | // retries:最大重试次数,默认10 26 | // factor:指数因子使用,默认2 27 | // minTimeout: 第一次重试前等待时间,默认1000ms 28 | // maxTimeout: 间隔两次重试的等待时间,默认Infinity 29 | // randomize: 随机化超时时间,默认false 30 | 31 | int retries = 10; 32 | int factor = 2; 33 | int minTimeout = 5; 34 | int maxTimeout = 10; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/GetPomVersion.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import org.junit.Test; 4 | import org.springframework.core.io.support.PropertiesLoaderUtils; 5 | 6 | import java.io.IOException; 7 | import java.util.Properties; 8 | 9 | /** 10 | * @Author hisenyuan 11 | * @Description .java$ 12 | * @Date 2019-05-16 16:40 13 | */ 14 | public class GetPomVersion { 15 | private static String appVersion; 16 | 17 | public static void main(String[] args) { 18 | getAppVersion(); 19 | } 20 | 21 | @Test 22 | public void testGetVersion(){ 23 | getAppVersion(); 24 | System.out.println(appVersion); 25 | } 26 | 27 | public static String getAppVersion() { 28 | if (null == appVersion) { 29 | try { 30 | // Properties properties = PropertiesLoaderUtils.loadAllProperties("app.properties"); 31 | Properties properties = PropertiesLoaderUtils.loadAllProperties("db.properties"); 32 | if (!properties.isEmpty()) { 33 | appVersion = properties.getProperty("app.version"); 34 | } 35 | } catch (IOException e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | return appVersion; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/RealProgrammer.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/10 at 19:29. 5 | */ 6 | public class RealProgrammer { 7 | 8 | public static void main(String[] args) { 9 | 10 | System.out.println("去市场买一个西瓜,如果看到西红柿,买两个。"); 11 | System.out.println("-------------------------"); 12 | int tomatoe = 1;//1 代表市场上有西红柿 13 | if (tomatoe == 1) { 14 | System.out.println("看到西红柿"); 15 | buyWatermelon(tomatoe); 16 | } 17 | System.out.println("-------------------------"); 18 | tomatoe = 0;//0 代表市场上没有西红柿 19 | if (tomatoe == 0) { 20 | System.out.println("没看到西红柿"); 21 | buyWatermelon(tomatoe); 22 | } 23 | } 24 | 25 | public static void buyWatermelon(int tomatoe) { 26 | int watermelon = 1;//买一个 27 | if (tomatoe != 0) { 28 | watermelon += 1;//如果看到西红柿,就买两个 29 | } 30 | System.out.println("购买西瓜的个数:" + watermelon); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/RetryTime.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import com.github.rholder.retry.Retryer; 4 | import com.github.rholder.retry.RetryerBuilder; 5 | import com.github.rholder.retry.StopStrategies; 6 | import com.github.rholder.retry.WaitStrategies; 7 | import org.junit.Test; 8 | 9 | import java.util.concurrent.Callable; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | /** 13 | * @Author hisenyuan 14 | * @Description $end$ 15 | * @Date 2018/10/11 12:41 16 | */ 17 | public class RetryTime { 18 | @Test 19 | public void retryWaitFibonacciStrategy() { 20 | for (int i = 1; i < 15; i++) { 21 | System.out.println(count4time(i) * 5); 22 | } 23 | } 24 | 25 | public static int count4time(int n) { 26 | if (n==1 || n ==2){ 27 | return 1; 28 | } 29 | return count4time(n-1) + count4time(n-2); 30 | } 31 | 32 | public static void main(String[] args) { 33 | System.out.println(0>0); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/TestMultithreadingSingleton.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | /** 4 | * @author : yhx 5 | * @date : 2017/11/16 21:42 6 | * @descriptor : 7 | */ 8 | public class TestMultithreadingSingleton { 9 | 10 | public static void main(String[] args) { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/TestTrackSingleton.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import com.hisen.interview.MultithreadingSingleton; 4 | 5 | import java.lang.reflect.Constructor; 6 | import java.lang.reflect.InvocationTargetException; 7 | 8 | public class TestTrackSingleton { 9 | public static void main(String[] args) { 10 | Class classType = MultithreadingSingleton.class; 11 | Constructor constructor = null; 12 | try { 13 | constructor = classType.getDeclaredConstructor(null); 14 | constructor.setAccessible(true); 15 | MultithreadingSingleton singleton = constructor.newInstance(); 16 | MultithreadingSingleton instance = MultithreadingSingleton.getInstance(); 17 | System.out.println(singleton == instance); 18 | } catch (NoSuchMethodException e) { 19 | e.printStackTrace(); 20 | } catch (IllegalAccessException e) { 21 | e.printStackTrace(); 22 | } catch (InstantiationException e) { 23 | e.printStackTrace(); 24 | } catch (InvocationTargetException e) { 25 | e.printStackTrace(); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/enum_test/Color.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test.enum_test; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/8/15 at 17:11. 5 | */ 6 | public enum Color { 7 | RED("红色", 1), GREEN("绿色", 2), BLANK("白色", 3), YELLO("黄色", 4); 8 | 9 | private String name ; 10 | private int index ; 11 | 12 | Color(String name, int index) { 13 | this.name = name; 14 | this.index = index; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | 25 | public int getIndex() { 26 | return index; 27 | } 28 | 29 | public void setIndex(int index) { 30 | this.index = index; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/enum_test/UseEnum.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test.enum_test; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/8/15 at 17:14. 5 | */ 6 | public class UseEnum { 7 | 8 | public static void main(String[] args) { 9 | // 输出相关属性 10 | System.out.println(Color.BLANK.getName()); 11 | System.out.println(Color.BLANK.getIndex()); 12 | 13 | /** 14 | * 遍历所有的信息 15 | */ 16 | for (Color color : Color.values()){ 17 | System.out.printf("name:%s,index:%s\n",color.getName(),color.getIndex()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/scriptengine/model.js: -------------------------------------------------------------------------------- 1 | function formula(var1,var2) { 2 | return var1 + var2 * factor; 3 | } -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/snamu.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | /** 4 | * @author : hisenyuan@gmail.com 5 | * @date : 2017/10/22 17:14 6 | */ 7 | public class snamu { 8 | 9 | public static void main(String[] args) { 10 | String s = null; 11 | String s1 = s == null || s.equals("") ? "1" : "2"; 12 | System.out.println(s1); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/test/testShort.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | /** 6 | * @Auther: hisenyuan - yuanhaixing@unapy.com 7 | * @Date: 2018/9/5 17:23 8 | * @Description: 9 | */ 10 | public class testShort { 11 | public static void main(String[] args) { 12 | final DateTime dateTime = new DateTime(); 13 | final int maxValue = Integer.MAX_VALUE; 14 | final DateTime newTime = dateTime.plusSeconds(maxValue); 15 | System.out.println(newTime); 16 | 17 | 18 | String s = "1"; 19 | int i = 1; 20 | System.out.println(s.equals(i + "")); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thinkingInJava/chapter18/DirList.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thinkingInJava.chapter18; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | import java.util.regex.Pattern; 6 | 7 | /** 8 | * Created by hisen on 17-5-6. 9 | * thinking in java 第十八章 java i/o 系统 10 | * 901 11 | */ 12 | public class DirList { 13 | 14 | //input:{args:"/home/hisen/IdeaProjects/IDEAPractice"} 就是当前工程所在根目录 15 | public static void main(String[] args) { 16 | //当前工程所在的根目录 17 | File path = new File("."); 18 | String[] list; 19 | if (args.length == 0) { 20 | list = path.list(); 21 | } else { 22 | list = path.list(new DirFilter(args[0])); 23 | } 24 | for (String dirItem : list) { 25 | System.out.println(dirItem); 26 | } 27 | /* OutPut:可以看出并没有输出子目录 28 | src 29 | pom.xml 30 | IDEAPractice.iml 31 | .idea 32 | .git 33 | ssm_study 34 | target 35 | README.md 36 | */ 37 | } 38 | 39 | static class DirFilter implements FilenameFilter { 40 | 41 | private Pattern pattern; 42 | 43 | public DirFilter(String regex) { 44 | pattern = Pattern.compile(regex); 45 | } 46 | 47 | @Override 48 | public boolean accept(File dir, String name) { 49 | return pattern.matcher(name).matches(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thinkingInJava/chapter18/DirList2.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thinkingInJava.chapter18; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | import java.util.Arrays; 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * Created by hisen on 17-5-6. 10 | */ 11 | public class DirList2 { 12 | public static FilenameFilter filter(final String regex){ 13 | //creation of anonymous inner class 14 | return new FilenameFilter() { 15 | private Pattern pattern=Pattern.compile(regex); 16 | @Override 17 | public boolean accept(File dir, String name) { 18 | return pattern.matcher(name).matches(); 19 | } 20 | };//匿名类部类结束 21 | } 22 | 23 | public static void main(String[] args) { 24 | File path = new File("."); 25 | String[] list; 26 | if (args.length==0) 27 | list=path.list(); 28 | else 29 | list=path.list(filter(args[0])); 30 | //按字母进行排序 31 | Arrays.sort(list,String.CASE_INSENSITIVE_ORDER); 32 | for (String dirItem:list) { 33 | System.out.println(dirItem); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thinkingInJava/chapter18/DirList3.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thinkingInJava.chapter18; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | import java.util.Arrays; 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * Created by hisen on 17-5-6. 10 | * 对前面的一种改进,程序变得更小 11 | */ 12 | public class DirList3 { 13 | 14 | public static void main(String[] args) { 15 | File path = new File("."); 16 | String[] list; 17 | if (args.length==0) 18 | list=path.list(); 19 | else 20 | list=path.list(new FilenameFilter() { 21 | private Pattern pattern=Pattern.compile(args[0]); 22 | @Override 23 | public boolean accept(File dir, String name) { 24 | return pattern.matcher(name).matches(); 25 | } 26 | }); 27 | //按字母进行排序 28 | Arrays.sort(list,String.CASE_INSENSITIVE_ORDER); 29 | for (String dirItem:list) { 30 | System.out.println(dirItem); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thread/count_click_by_redis/ClickRedis.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thread.count_click_by_redis; 2 | 3 | import com.hisen.utils.JedisUtil; 4 | import redis.clients.jedis.JedisPool; 5 | /** 6 | * @author hisenyuan 7 | * @description 操作redis的线程类 8 | */ 9 | public class ClickRedis { 10 | 11 | /** 12 | * 必须使用线程池,而且线程池要大于并发数,否则会出现redis超时 13 | */ 14 | private static JedisPool jedis = JedisUtil.getPool(); 15 | 16 | public static void click() { 17 | jedis.getResource().incrBy("hisen", 1); 18 | } 19 | 20 | public static int getCount() { 21 | return Integer.parseInt(jedis.getResource().get("hisen")); 22 | } 23 | 24 | public static void declare() { 25 | jedis.getResource().del("hisen"); 26 | jedis.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thread/count_click_by_redis/CountClickByRedisThread.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thread.count_click_by_redis; 2 | 3 | /** 4 | * @author hisenyuan 5 | * @description 执行点击的线程 6 | */ 7 | public class CountClickByRedisThread extends Thread{ 8 | 9 | private int id; 10 | public CountClickByRedisThread(int id) { 11 | this.id = id; 12 | } 13 | 14 | @Override 15 | public void run() { 16 | super.run(); 17 | ClickRedis.click(); 18 | int count = ClickRedis.getCount(); 19 | System.out.println("task:" + id + "\t 执行完毕\t线程编号:" + this.getId() + "\t当前值:" + count); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thread/count_click_by_redis/Main.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thread.count_click_by_redis; 2 | 3 | import java.util.concurrent.ArrayBlockingQueue; 4 | import java.util.concurrent.ThreadPoolExecutor; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class Main { 8 | 9 | public static void main(String[] args) throws InterruptedException { 10 | /** 11 | * 5 - corePoolSize:核心池的大小 12 | * 10 - maximumPoolSize:线程池最大线程数,它表示在线程池中最多能创建多少个线程 13 | * 200 - keepAliveTime:表示线程没有任务执行时最多保持多久时间会终止。 14 | * unit - unit:参数keepAliveTime的时间单位,有7种取值 15 | * workQueue:一个阻塞队列,用来存储等待执行的任务 16 | */ 17 | ThreadPoolExecutor executor = new ThreadPoolExecutor( 18 | 50, 19 | 100, 20 | 200, 21 | TimeUnit.MICROSECONDS, 22 | new ArrayBlockingQueue(50)); 23 | // 开启50个线程 24 | for (int i = 0; i < 50; i++) { 25 | executor.execute(new CountClickByRedisThread(i)); 26 | } 27 | System.out.println("已经开启所有的子线程"); 28 | // 启动一次顺序关闭,执行以前提交的任务,但不接受新任务。 29 | executor.shutdown(); 30 | // 判断所有线程是否已经执行完毕 31 | while (true) { 32 | if (executor.isTerminated()) { 33 | System.out.println("所有的子线程都结束了!"); 34 | // 清除redis数据 35 | ClickRedis.declare(); 36 | break; 37 | } 38 | Thread.sleep(100); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thread/progressbar/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hisenyuan/IDEAPractice/d44f90a385688fdaf071035519854d5357286f8a/src/main/java/com/hisen/thread/progressbar/1.jpg -------------------------------------------------------------------------------- /src/main/java/com/hisen/thread/threadTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thread; 2 | 3 | // 创建一个新的线程 4 | class NewThread implements Runnable { 5 | 6 | Thread t; 7 | 8 | NewThread() { 9 | // 创建第二个新线程 10 | t = new Thread(this, "Demo Thread"); 11 | System.out.println("Child thread: " + t); 12 | t.start(); // 开始线程 13 | } 14 | 15 | // 第二个线程入口 16 | public void run() { 17 | try { 18 | for (int i = 5; i > 0; i--) { 19 | System.out.println("Child Thread: " + i); 20 | // 暂停线程 21 | Thread.sleep(50); 22 | } 23 | } catch (InterruptedException e) { 24 | System.out.println("Child interrupted."); 25 | } 26 | System.out.println("Exiting child thread."); 27 | } 28 | } 29 | 30 | public class threadTest { 31 | 32 | public static void main(String args[]) { 33 | new NewThread(); // 创建一个新线程 34 | try { 35 | for (int i = 5; i > 0; i--) { 36 | System.out.println("CrcUtils Thread: " + i); 37 | Thread.sleep(100); 38 | } 39 | } catch (InterruptedException e) { 40 | System.out.println("CrcUtils thread interrupted."); 41 | } 42 | System.out.println("CrcUtils thread exiting."); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/thread/threadpool/TestThreadPool.java: -------------------------------------------------------------------------------- 1 | package com.hisen.thread.threadpool; 2 | 3 | /** 4 | * Created by hisen on 17-8-12. 5 | */ 6 | public class TestThreadPool { 7 | 8 | public static void main(String[] args) { 9 | //创建一个容量为3的线程池 10 | ThreadPool threadPool = ThreadPool.getThreadPool(3); 11 | //添加线程 12 | threadPool.execute(new Runnable[]{new Task(),new Task(),new Task()}); 13 | threadPool.execute(new Runnable[]{new Task(),new Task()}); 14 | threadPool.execute(new Runnable[]{new Task()}); 15 | System.out.println(threadPool); 16 | threadPool.destory(); 17 | System.out.println(threadPool); 18 | 19 | // WorkThread number:3 finished task number:0 wait task number:6 20 | // 任务 1 完成 21 | // 任务 2 完成 22 | // 任务 3 完成 23 | // 任务 4 完成 24 | // 任务 6 完成 25 | // 任务 5 完成 26 | // WorkThread number:3 finished task number:6 wait task number:0 27 | } 28 | 29 | // 任务类 30 | static class Task implements Runnable { 31 | private static volatile int i = 1; 32 | @Override 33 | // 执行任务 34 | public void run() { 35 | // 自定义任务内容 36 | System.out.println("任务 " + (i++) + " 完成"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/utils/BuildFileUtil.java: -------------------------------------------------------------------------------- 1 | package com.hisen.utils; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | /** 7 | * Created by hisenyuan on 2017/4/18 at 18:33. 8 | */ 9 | public class BuildFileUtil { 10 | 11 | public static void buildFile(File file) { 12 | if (!file.exists()) { 13 | File parent = file.getParentFile(); 14 | if (parent != null && !parent.exists()) { 15 | parent.mkdirs(); 16 | System.out.println("创建父目录成功!"); 17 | } 18 | try { 19 | file.createNewFile(); 20 | } catch (IOException e) { 21 | e.printStackTrace(); 22 | } 23 | System.out.println("新建路径:" + file); 24 | System.out.println("创建文件完成!"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/utils/CommonUtils.java: -------------------------------------------------------------------------------- 1 | package com.hisen.utils; 2 | 3 | import com.google.common.util.concurrent.ThreadFactoryBuilder; 4 | 5 | import java.util.concurrent.*; 6 | 7 | /** 8 | * @Author hisenyuan 9 | * @Description $end$ 10 | * @Date 2019/4/26 11:18 11 | */ 12 | public class CommonUtils { 13 | // 初始化一个连接池 14 | public static ExecutorService getThreadPoolExecutor(String threadName, int core, int max, int queueSize) { 15 | ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat(threadName).build(); 16 | return new ThreadPoolExecutor( 17 | core, 18 | max, 19 | 10L, 20 | TimeUnit.SECONDS, 21 | new LinkedBlockingQueue<>(queueSize), 22 | namedThreadFactory, 23 | new ThreadPoolExecutor.AbortPolicy()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/utils/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.hisen.utils; 2 | 3 | import java.util.Date; 4 | import org.joda.time.DateTime; 5 | import org.joda.time.format.DateTimeFormat; 6 | import org.joda.time.format.DateTimeFormatter; 7 | 8 | /** 9 | * @author hisenyuan 10 | * @time 2018/3/28 9:58 11 | * @description Date与字符串之间的转换 12 | */ 13 | public class DateUtils { 14 | 15 | /** 16 | * 将字符串转换为日期 17 | * @param strTime 字符串的时间 18 | * @param formatStr 字符串格式 19 | * @return date时间 20 | */ 21 | public static Date str2Date(String strTime,String formatStr){ 22 | DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(strTime); 23 | DateTime dateTime = dateTimeFormatter.parseDateTime(formatStr); 24 | return dateTime.toDate(); 25 | } 26 | 27 | /** 28 | * 将日期转换为字符串 29 | * @param dateTime 日期 30 | * @param formatStr 格式 31 | * @return 返回时间字符串 32 | */ 33 | public static String date2str(Date dateTime,String formatStr){ 34 | DateTime time = new DateTime(dateTime.getTime()); 35 | return time.toString(formatStr); 36 | } 37 | 38 | /** 39 | * 获得当前时间的字符串格式 40 | * @param formatStr 想要的日期格式 41 | * @return 42 | */ 43 | public static String getFormatTimeStr(String formatStr){ 44 | DateTime time = new DateTime(); 45 | return time.toString(formatStr); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.hisen.utils; 2 | 3 | import com.google.common.io.Files; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.charset.Charset; 8 | 9 | /** 10 | * @Author hisenyuan 11 | * @Description $end$ 12 | * @Date 2019/3/17 02:24 13 | */ 14 | public class FileUtils { 15 | public static File getFile(String path) throws IOException { 16 | final File file = new File(path); 17 | if (!file.exists()) { 18 | file.createNewFile(); 19 | } 20 | return file; 21 | } 22 | 23 | public static void apendContext(File file, String context) throws IOException { 24 | Files.append(context, file, Charset.forName("UTF-8")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/utils/GetAllFileUtil.java: -------------------------------------------------------------------------------- 1 | package com.hisen.utils; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * Created by hisenyuan on 2017/4/20 at 16:55. 7 | */ 8 | public class GetAllFileUtil { 9 | 10 | public static void main(String[] args) { 11 | String filePath = "c:" + File.separator + "1" + File.separator + "hisenyuan"; 12 | String replace = filePath + "\\"; 13 | getAllFile(filePath, replace); 14 | } 15 | 16 | /** 17 | * 获取当前文件夹下所有的文件名 18 | * 19 | * @param filePath 文件夹路径 20 | * @param replace 文件夹路径\(最后控制是否输出相对路径) 21 | */ 22 | public static void getAllFile(String filePath, String replace) { 23 | replace = replace == null ? "" : replace; 24 | File file = new File(filePath); 25 | if (file.exists()) { 26 | File[] files = file.listFiles(); 27 | if (files == null) { 28 | System.out.println("文件夹为空"); 29 | } else { 30 | for (File file2 : files) { 31 | if (file2.isDirectory()) { 32 | //System.out.println("文件夹:"+file2.getAbsolutePath()); 33 | getAllFile(file2.getAbsolutePath(), replace); 34 | } else { 35 | String replace1 = file2.getAbsolutePath().replace(replace, ""); 36 | //System.out.println("替换前:"+file2.getAbsolutePath()); 37 | System.out.println("替换后:" + replace1); 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hisen/utils/JavaShellUtil.java: -------------------------------------------------------------------------------- 1 | package com.hisen.utils; 2 | 3 | import java.io.*; 4 | 5 | /** 6 | * @Author hisenyuan 7 | * @Description $end$ 8 | * @Date 2018/12/5 16:07 9 | */ 10 | public class JavaShellUtil { 11 | public static String execute(String command) { 12 | String returnString = ""; 13 | Process pro = null; 14 | Runtime runTime = Runtime.getRuntime(); 15 | if (runTime == null) { 16 | System.err.println("Create runtime false!"); 17 | } 18 | try { 19 | System.out.println("开始转换"); 20 | pro = runTime.exec(command); 21 | BufferedReader input = new BufferedReader(new InputStreamReader(pro.getInputStream())); 22 | PrintWriter output = new PrintWriter(new OutputStreamWriter(pro.getOutputStream())); 23 | String line; 24 | while ((line = input.readLine()) != null) { 25 | System.out.println("line: " + line); 26 | returnString = returnString + line + "\n"; 27 | } 28 | System.out.println("返回值:" + returnString); 29 | input.close(); 30 | output.close(); 31 | pro.destroy(); 32 | } catch (IOException ex) { 33 | ex.printStackTrace(); 34 | } 35 | return returnString; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/translate/baidu/Main.java: -------------------------------------------------------------------------------- 1 | package com.translate.baidu; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | 6 | public class Main { 7 | 8 | private static final String APP_ID = "20180226000127578"; 9 | private static final String SECURITY_KEY = "_noh4JkwGf1kEtUsseTc"; 10 | 11 | public static void main(String[] args) { 12 | TransApi api = new TransApi(APP_ID, SECURITY_KEY); 13 | 14 | String query = "مع سّلامة"; 15 | final String result = api.getTransResult(query, "aoto", "zh"); 16 | 17 | System.out.println(result); 18 | 19 | final JSONObject parseObject = JSONObject.parseObject(result); 20 | final JSONArray trans_result = parseObject.getJSONArray("trans_result"); 21 | final JSONObject res = trans_result.getJSONObject(0); 22 | final String src = res.get("src").toString(); 23 | final String dst = res.get("dst").toString(); 24 | System.out.println("源头: " + src + ", 结果:" + dst); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/translate/baidu/TransApi.java: -------------------------------------------------------------------------------- 1 | package com.translate.baidu; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class TransApi { 7 | private static final String TRANS_API_HOST = "http://api.fanyi.baidu.com/api/trans/vip/translate"; 8 | 9 | private String appid; 10 | private String securityKey; 11 | 12 | public TransApi(String appid, String securityKey) { 13 | this.appid = appid; 14 | this.securityKey = securityKey; 15 | } 16 | 17 | public String getTransResult(String query, String from, String to) { 18 | Map params = buildParams(query, from, to); 19 | return HttpGet.get(TRANS_API_HOST, params); 20 | } 21 | 22 | private Map buildParams(String query, String from, String to) { 23 | Map params = new HashMap<>(); 24 | params.put("q", query); 25 | params.put("from", from); 26 | params.put("to", to); 27 | 28 | params.put("appid", appid); 29 | 30 | // 随机数 31 | String salt = String.valueOf(System.currentTimeMillis()); 32 | params.put("salt", salt); 33 | 34 | // 签名 35 | String src = appid + query + salt + securityKey; // 加密前的原文 36 | params.put("sign", MD5.md5(src)); 37 | 38 | return params; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/translate/google/QuickstartSample.java: -------------------------------------------------------------------------------- 1 | package com.translate.google; 2 | 3 | 4 | import com.google.cloud.translate.Translate; 5 | import com.google.cloud.translate.TranslateOptions; 6 | import com.google.cloud.translate.Translation; 7 | 8 | /** 9 | * @Author hisenyuan 10 | * @Description $end$ 11 | * @Date 2019/1/14 21:36 12 | */ 13 | public class QuickstartSample { 14 | public static void main(String... args) throws Exception { 15 | // Instantiates a client 16 | Translate translate = TranslateOptions.getDefaultInstance().getService(); 17 | // Translate translate = TranslateOptions.newBuilder().setApiKey("AIzaSyAG_70jWZnF4nC8slbqMgIE09ef6vvggBw").build().getService(); 18 | // The text to translate 19 | String text = "Hello, world!"; 20 | 21 | // Translates some text into Russian 22 | Translation translation = 23 | translate.translate( 24 | text, 25 | Translate.TranslateOption.sourceLanguage("en"), 26 | Translate.TranslateOption.targetLanguage("ru")); 27 | 28 | 29 | System.out.printf("Text: %s%n", text); 30 | System.out.printf("Translation: %s%n", translation.getTranslatedText()); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/resources/No3/SqlMapConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/resources/db.properties: -------------------------------------------------------------------------------- 1 | jdbc.driver=com.mysql.jdbc.Driver 2 | jdbc.url=jdbc:mysql://127.0.0.1:3306/mvc?characterEncoding=utf-8 3 | jdbc.username=root 4 | jdbc.password=password -------------------------------------------------------------------------------- /src/main/resources/files/1-150316141F4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hisenyuan/IDEAPractice/d44f90a385688fdaf071035519854d5357286f8a/src/main/resources/files/1-150316141F4.gif -------------------------------------------------------------------------------- /src/main/resources/generator.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverLocation=D:\\maven\\com\\oracle\\ojdbc14\\10.2.0.4.0\\ojdbc14-10.2.0.4.0.jar 2 | jdbc.driverClass=oracle.jdbc.driver.OracleDriver 3 | jdbc.connectionURL=jdbc:oracle:thin:@//localhost:1521/XE 4 | jdbc.userId=LOUIS 5 | jdbc.password=123456 -------------------------------------------------------------------------------- /src/main/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 17 | 18 | 19 | 20 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Global logging configuration 2 | log4j.rootLogger=DEBUG, stdout 3 | # Console output... 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | addFont//要与下面的名称相同 9 | com.hisen.image.controller.addFont//调用的类的位置 10 | 11 | 12 | 13 | addFont 14 | /hello.do//url标识 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/webapp/firstJsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: Administrator 4 | Date: 2017/3/24 5 | Time: 19:20 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | Insert title here 13 | 14 | 15 |

Do you come in?

16 | 17 | Select:
18 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.hisen.image.ShowImageByBase64" %><%-- 2 | Created by IntelliJ IDEA. 3 | User: Administrator 4 | Date: 2017/5/11 5 | Time: 18:55 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <% String imageStr = ShowImageByBase64.showimage();%> 10 | 11 | 12 | Title 13 | 14 | 15 | base64图片 16 | 17 | 18 | -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/dao/AppointmentDao.java: -------------------------------------------------------------------------------- 1 | package com.hisen.dao; 2 | 3 | import com.hisen.entity.Appointment; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | /** 7 | * Created by hisenyuan on 2017/4/6 at 16:59. 8 | */ 9 | public interface AppointmentDao { 10 | 11 | /** 12 | * 插入预约图书记录 13 | * 14 | * @param bookId 15 | * @param studentId 16 | * @return 插入的行数 17 | */ 18 | int insertAppointment(@Param("bookId") long bookId, @Param("studentId") long studentId); 19 | 20 | /** 21 | * 通过主键查询预约图书记录,并且携带图书实体 22 | * 23 | * @param bookId 24 | * @param studentId 25 | * @return 26 | */ 27 | Appointment queryByKeyWithBook(@Param("bookId") long bookId, @Param("studentId") long studentId); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/dao/BookDao.java: -------------------------------------------------------------------------------- 1 | package com.hisen.dao; 2 | 3 | import com.hisen.entity.Book; 4 | import java.util.List; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | /** 8 | * Created by hisenyuan on 2017/4/6 at 16:58. 9 | */ 10 | public interface BookDao { 11 | 12 | /** 13 | * 通过ID查询单本图书 14 | * 15 | * @param id 16 | * @return 17 | */ 18 | Book queryById(long id); 19 | 20 | /** 21 | * 查询所有图书 22 | * 23 | * @param offset 查询起始位置 24 | * @param limit 查询条数 25 | * @return 26 | */ 27 | List queryAll(@Param("offset") int offset, @Param("limit") int limit); 28 | 29 | /** 30 | * 减少馆藏数量 31 | * 32 | * @param bookId 33 | * @return 如果影响行数等于>1,表示更新的记录行数 34 | */ 35 | int reduceNumber(long bookId); 36 | 37 | 38 | /** 39 | * 增加图书 40 | * 41 | * @param book 42 | * @return 43 | */ 44 | int addBook(Book book); 45 | 46 | /** 47 | * 统计行数 48 | * @return 49 | */ 50 | int countNum(); 51 | } 52 | -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/dto/Result.java: -------------------------------------------------------------------------------- 1 | package com.hisen.dto; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 17:26. 5 | * 封装json对象,所有返回结果都使用它 6 | * 7 | * 一般我们使用DTO类来继承entity实体类, 8 | * 在DTO类里放一些业务字段,并提供get、set方法。 9 | * 当我们在业务逻辑层或者交互层用到一些数据库中不存在的字段时, 10 | * 我们就需要在DTO类里放这些字段, 11 | * 这些字段的意义就相当于一些经处理过的数据库字段, 12 | * 实质意义就是方便数据交互,提高效率。 13 | */ 14 | public class Result { 15 | 16 | private boolean success;// 是否成功标志 17 | 18 | private T data;// 成功时返回的数据 19 | 20 | private String error;// 错误信息 21 | 22 | public Result() { 23 | } 24 | 25 | // 成功时的构造器 26 | public Result(boolean success, T data) { 27 | this.success = success; 28 | this.data = data; 29 | } 30 | 31 | // 错误时的构造器 32 | public Result(boolean success, String error) { 33 | this.success = success; 34 | this.error = error; 35 | } 36 | 37 | // 省略getter和setter方法 38 | 39 | public boolean isSuccess() { 40 | return success; 41 | } 42 | 43 | public void setSuccess(boolean success) { 44 | this.success = success; 45 | } 46 | 47 | public T getData() { 48 | return data; 49 | } 50 | 51 | public void setData(T data) { 52 | this.data = data; 53 | } 54 | 55 | public String getError() { 56 | return error; 57 | } 58 | 59 | public void setError(String error) { 60 | this.error = error; 61 | } 62 | } -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/entity/Appointment.java: -------------------------------------------------------------------------------- 1 | package com.hisen.entity; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 16:56. 5 | */ 6 | import java.util.Date; 7 | 8 | public class Appointment { 9 | 10 | private long bookId;// 图书ID 11 | 12 | private long studentId;// 学号 13 | 14 | private Date appointTime;// 预约时间 15 | 16 | // 多对一的复合属性 17 | private Book book;// 图书实体 18 | 19 | // 省略构造方法,getter和setter方法,toString方法 20 | 21 | @Override 22 | public String toString() { 23 | return "Appointment{" + 24 | "bookId=" + bookId + 25 | ", studentId=" + studentId + 26 | ", appointTime=" + appointTime + 27 | ", book=" + book + 28 | '}'; 29 | } 30 | 31 | public long getBookId() { 32 | return bookId; 33 | } 34 | 35 | public void setBookId(long bookId) { 36 | this.bookId = bookId; 37 | } 38 | 39 | public long getStudentId() { 40 | return studentId; 41 | } 42 | 43 | public void setStudentId(long studentId) { 44 | this.studentId = studentId; 45 | } 46 | 47 | public Date getAppointTime() { 48 | return appointTime; 49 | } 50 | 51 | public void setAppointTime(Date appointTime) { 52 | this.appointTime = appointTime; 53 | } 54 | 55 | public Book getBook() { 56 | return book; 57 | } 58 | 59 | public void setBook(Book book) { 60 | this.book = book; 61 | } 62 | } -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/entity/Book.java: -------------------------------------------------------------------------------- 1 | package com.hisen.entity; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 16:58. 5 | */ 6 | public class Book { 7 | 8 | private long bookId;// 图书ID 9 | 10 | private String name;// 图书名称 11 | 12 | private int number;// 馆藏数量 13 | 14 | // 省略构造方法,getter和setter方法,toString方法 15 | 16 | @Override 17 | public String toString() { 18 | return "Book{" + 19 | "bookId=" + bookId + 20 | ", name='" + name + '\'' + 21 | ", number=" + number + 22 | '}'; 23 | } 24 | 25 | public long getBookId() { 26 | return bookId; 27 | } 28 | 29 | public void setBookId(long bookId) { 30 | this.bookId = bookId; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public int getNumber() { 42 | return number; 43 | } 44 | 45 | public void setNumber(int number) { 46 | this.number = number; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/enums/AppointStateEnum.java: -------------------------------------------------------------------------------- 1 | package com.hisen.enums; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 17:19. 5 | */ 6 | /** 7 | * 使用枚举表述常量数据字典 8 | */ 9 | public enum AppointStateEnum { 10 | 11 | SUCCESS(1, "预约成功"), NO_NUMBER(0, "库存不足"), REPEAT_APPOINT(-1, "重复预约"), INNER_ERROR(-2, "系统异常"); 12 | 13 | private int state; 14 | 15 | private String stateInfo; 16 | 17 | private AppointStateEnum(int state, String stateInfo) { 18 | this.state = state; 19 | this.stateInfo = stateInfo; 20 | } 21 | 22 | public int getState() { 23 | return state; 24 | } 25 | 26 | public String getStateInfo() { 27 | return stateInfo; 28 | } 29 | 30 | public static AppointStateEnum stateOf(int index) { 31 | for (AppointStateEnum state : values()) { 32 | if (state.getState() == index) { 33 | return state; 34 | } 35 | } 36 | return null; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/exception/AppointException.java: -------------------------------------------------------------------------------- 1 | package com.hisen.exception; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 17:21. 5 | * 预约业务异常 6 | */ 7 | public class AppointException extends RuntimeException { 8 | 9 | public AppointException(String message) { 10 | super(message); 11 | } 12 | 13 | public AppointException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/exception/NoNumberException.java: -------------------------------------------------------------------------------- 1 | package com.hisen.exception; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 17:20. 5 | * 库存不足异常 6 | */ 7 | public class NoNumberException extends RuntimeException { 8 | 9 | public NoNumberException(String message) { 10 | super(message); 11 | } 12 | 13 | public NoNumberException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/exception/RepeatAppointException.java: -------------------------------------------------------------------------------- 1 | package com.hisen.exception; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 17:21. 5 | * 重复预约异常 6 | */ 7 | public class RepeatAppointException extends RuntimeException { 8 | 9 | public RepeatAppointException(String message) { 10 | super(message); 11 | } 12 | 13 | public RepeatAppointException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ssm_study/src/main/java/com/hisen/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.hisen.service; 2 | 3 | import com.hisen.dto.AppointExecution; 4 | import com.hisen.entity.Book; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by hisenyuan on 2017/4/6 at 17:22. 9 | * 业务接口:站在"使用者"角度设计接口 三个方面:方法定义粒度,参数,返回类型(return 类型/异常) 10 | */ 11 | public interface BookService { 12 | 13 | /** 14 | * 查询一本图书 15 | * 16 | * @param bookId 17 | * @return 18 | */ 19 | Book getById(long bookId); 20 | 21 | /** 22 | * 查询所有图书 23 | * 24 | * @return 25 | */ 26 | List getList(int start, int pageNum); 27 | 28 | /** 29 | * 预约图书 30 | * 31 | * @param bookId 32 | * @param studentId 33 | * @return 34 | */ 35 | AppointExecution appoint(long bookId, long studentId); 36 | 37 | /** 38 | * 添加图书 39 | * 40 | * @param book 41 | * @return 42 | */ 43 | int addBook(Book book); 44 | 45 | /** 46 | * 统计行数 47 | * @return 48 | */ 49 | int countNum(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ssm_study/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driver=com.mysql.jdbc.Driver 2 | jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=utf8 3 | jdbc.username=root 4 | jdbc.password=hisen -------------------------------------------------------------------------------- /ssm_study/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ssm_study/src/main/resources/mapper/AppointmentDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | INSERT ignore INTO appointment (book_id, student_id) 9 | VALUES (#{bookId}, #{studentId}) 10 | 11 | 12 | 29 | -------------------------------------------------------------------------------- /ssm_study/src/main/resources/mapper/BookDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 18 | 24 | 25 | 36 | 37 | 38 | UPDATE book 39 | SET number = number - 1 40 | WHERE 41 | book_id = #{bookId} 42 | AND number > 0 43 | 44 | 45 | 46 | INSERT INTO book(`book_id`, `name`, `number`) 47 | VALUES(#{bookId}, #{name}, #{number}) 48 | 49 | -------------------------------------------------------------------------------- /ssm_study/src/main/resources/mapper/sql/ssm_study.sql: -------------------------------------------------------------------------------- 1 | -- 创建图书表 2 | CREATE TABLE `book` ( 3 | `book_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '图书ID', 4 | `name` varchar(100) NOT NULL COMMENT '图书名称', 5 | `number` int(11) NOT NULL COMMENT '馆藏数量', 6 | PRIMARY KEY (`book_id`) 7 | ) ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 COMMENT='图书表' 8 | 9 | -- 初始化图书数据 10 | INSERT INTO `book` (`book_id`, `name`, `number`) 11 | VALUES 12 | (1000, 'Java程序设计', 10), 13 | (1001, '数据结构', 10), 14 | (1002, '设计模式', 10), 15 | (1003, '编译原理', 10) 16 | 17 | -- 创建预约图书表 18 | CREATE TABLE `appointment` ( 19 | `book_id` bigint(20) NOT NULL COMMENT '图书ID', 20 | `student_id` bigint(20) NOT NULL COMMENT '学号', 21 | `appoint_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '预约时间' , 22 | PRIMARY KEY (`book_id`, `student_id`), 23 | INDEX `idx_appoint_time` (`appoint_time`) 24 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='预约图书表' -------------------------------------------------------------------------------- /ssm_study/src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ssm_study/src/main/resources/spring/spring-service.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ssm_study/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | seckill-dispatcher 9 | org.springframework.web.servlet.DispatcherServlet 10 | 14 | 15 | contextConfigLocation 16 | classpath:spring/spring-*.xml 17 | 18 | 19 | 20 | seckill-dispatcher 21 | 22 | / 23 | 24 | -------------------------------------------------------------------------------- /ssm_study/src/main/webapp/images/avator.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hisenyuan/IDEAPractice/d44f90a385688fdaf071035519854d5357286f8a/ssm_study/src/main/webapp/images/avator.jpg -------------------------------------------------------------------------------- /ssm_study/src/test/java/com/hisen/test/AppointmentDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import com.hisen.dao.AppointmentDao; 4 | import com.hisen.entity.Appointment; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | /** 9 | * Created by hisenyuan on 2017/4/6 at 17:17. 10 | */ 11 | public class AppointmentDaoTest extends BaseTest { 12 | 13 | @Autowired 14 | private AppointmentDao appointmentDao; 15 | 16 | @Test 17 | public void testInsertAppointment() throws Exception { 18 | long bookId = 1000; 19 | long studentId = 12345678910L; 20 | int insert = appointmentDao.insertAppointment(bookId, studentId); 21 | System.out.println("insert=" + insert); 22 | } 23 | 24 | @Test 25 | public void testQueryByKeyWithBook() throws Exception { 26 | long bookId = 1000; 27 | long studentId = 12345678910L; 28 | Appointment appointment = appointmentDao.queryByKeyWithBook(bookId, studentId); 29 | System.out.println(appointment); 30 | System.out.println(appointment.getBook()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ssm_study/src/test/java/com/hisen/test/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | /** 4 | * Created by hisenyuan on 2017/4/6 at 17:02. 5 | */ 6 | 7 | import org.junit.runner.RunWith; 8 | import org.springframework.test.context.ContextConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | /** 12 | * 配置spring和junit整合,junit启动时加载springIOC容器 spring-test,junit 13 | */ 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | // 告诉junit spring配置文件 16 | @ContextConfiguration({ "classpath:spring/spring-dao.xml", "classpath:spring/spring-service.xml" }) 17 | public class BaseTest { 18 | 19 | } -------------------------------------------------------------------------------- /ssm_study/src/test/java/com/hisen/test/BookDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import com.hisen.dao.BookDao; 4 | import com.hisen.entity.Book; 5 | import java.util.List; 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | 9 | /** 10 | * Created by hisenyuan on 2017/4/6 at 17:03. 11 | */ 12 | public class BookDaoTest extends BaseTest { 13 | 14 | @Autowired 15 | private BookDao bookDao; 16 | 17 | @Test 18 | public void testQueryById() throws Exception { 19 | long bookId = 1000; 20 | Book book = bookDao.queryById(bookId); 21 | System.out.println(book); 22 | } 23 | 24 | @Test 25 | public void testQueryAll() throws Exception { 26 | List books = bookDao.queryAll(0, 5); 27 | for (Book book : books) { 28 | System.out.println(book); 29 | } 30 | } 31 | 32 | @Test 33 | public void testReduceNumber() throws Exception { 34 | long bookId = 1000; 35 | int update = bookDao.reduceNumber(bookId); 36 | System.out.println("update=" + update); 37 | } 38 | 39 | @Test 40 | public void setCountNum() { 41 | int num = bookDao.countNum(); 42 | int countNum = num / 10 + (num % 10) > 0 ? 1 : 0; 43 | int i = (num % 10) > 0 ? 1 : 0; 44 | System.out.println(num + ":" + countNum + ":" + i); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ssm_study/src/test/java/com/hisen/test/BookServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package com.hisen.test; 2 | 3 | import com.hisen.dto.AppointExecution; 4 | import com.hisen.entity.Book; 5 | import com.hisen.service.BookService; 6 | import java.util.Random; 7 | import org.junit.Test; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | 10 | /** 11 | * Created by hisenyuan on 2017/4/6 at 17:25. 12 | */ 13 | public class BookServiceImplTest extends BaseTest { 14 | 15 | @Autowired 16 | private BookService bookService; 17 | 18 | /** 19 | * 测试图书预约功能 20 | * @throws Exception 21 | */ 22 | @Test 23 | public void testAppoint() throws Exception { 24 | long bookId = 1001; 25 | long studentId = 12345678910L; 26 | AppointExecution execution = bookService.appoint(bookId, studentId); 27 | System.out.println(execution); 28 | } 29 | 30 | /** 31 | * 批量添加图书数据 32 | */ 33 | @Test 34 | public void testAdd(){ 35 | for (int i = 1; i < 100; i++) { 36 | Book book = new Book(); 37 | book.setBookId(i); 38 | book.setName(String.valueOf((char) i+20048)); 39 | book.setNumber(i*10); 40 | bookService.addBook(book); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /websocket-demo/src/main/java/com/hisen/netty/ClientApp4Java.java: -------------------------------------------------------------------------------- 1 | package com.hisen.netty; 2 | 3 | import com.neovisionaries.ws.client.WebSocket; 4 | import com.neovisionaries.ws.client.WebSocketAdapter; 5 | import com.neovisionaries.ws.client.WebSocketException; 6 | import com.neovisionaries.ws.client.WebSocketFactory; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import java.io.IOException; 10 | 11 | public class ClientApp4Java { 12 | /** 13 | * java 客户端,可以给websocket发送消息 14 | * 15 | * @throws IOException 16 | * @throws WebSocketException 17 | * @throws InterruptedException 18 | */ 19 | @Test 20 | public void testClientApp4Java() throws IOException, WebSocketException { 21 | WebSocket websocket = new WebSocketFactory() 22 | // 发送地址和参数 23 | .createSocket("ws://10.1.1.157:9999/ws") 24 | // 新增一个监听者 25 | .addListener(new WebSocketAdapter() { 26 | @Override 27 | public void onTextMessage(WebSocket ws, String message) { 28 | // 接收到的信息 29 | System.out.println(message); 30 | } 31 | }) 32 | .connect(); 33 | for (int i = 0; i < 10; i++) { 34 | // 消息格式 sender,uid,message 35 | websocket.sendText("hisen,1,test" + i); 36 | } 37 | // 不关闭服务端会报错 38 | websocket.disconnect(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /websocket-demo/src/main/java/com/hisen/netty/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.hisen.netty; 2 | 3 | import io.netty.channel.Channel; 4 | 5 | /** 6 | * @author hisenyuan 7 | * @time 2018/7/31 10:09 8 | * @description 9 | */ 10 | public class UserInfo { 11 | /** 12 | * userId 13 | */ 14 | private String userId; 15 | /** 16 | * 地址 17 | */ 18 | private String addr; 19 | /** 20 | * 通道 21 | */ 22 | private Channel channel; 23 | 24 | public String getAddr() { 25 | return addr; 26 | } 27 | 28 | public void setAddr(String addr) { 29 | this.addr = addr; 30 | } 31 | 32 | public Channel getChannel() { 33 | return channel; 34 | } 35 | 36 | public void setChannel(Channel channel) { 37 | this.channel = channel; 38 | } 39 | 40 | public String getUserId() { 41 | return userId; 42 | } 43 | 44 | public void setUserId(String userId) { 45 | this.userId = userId; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /websocket-demo/src/main/java/com/hisen/ws/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.hisen.ws.util; 2 | 3 | public class Constants { 4 | // 发送方式 all,one 5 | public static String METHOD = "method"; 6 | // 发送给一个人 7 | public static String METHOD_SINGLE = "methodSingle"; 8 | // 发送给所有人 9 | public static String METHOD_ALL = "methodAll"; 10 | // 当前连接人 11 | public static String USER = "user"; 12 | // 发送给谁 13 | public static String SEND_TO = "sendTo"; 14 | } 15 | -------------------------------------------------------------------------------- /websocket-demo/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | --------------------------------------------------------------------------------