hutool工具包学习
2021-09-12
数据库操作
DbConfig conf = new DbConfig("jdbc:mysql://localhost:3306/test?useUnicode=true", "root", "123456"); conf.setMaxActive(1); PooledDataSource ds = new PooledDataSource(conf); Connection c = ds.getConnection(); SqlConnRunner r = SqlConnRunner.create(ds); Entity entity = new Entity("tb_cus"); long l = r.count(c, entity); System.out.println(l);
2021-09-24
连表查询
DbConfig conf = new DbConfig("jdbc:mysql://localhost:3306/test?useUnicode=true", "root", "123456"); conf.setMaxActive(1); PooledDataSource ds = new PooledDataSource(conf); Connection c = ds.getConnection(); Db db = new Db(ds); List<Entity> ls = db.query("select res_code from tb_cus where res_code = ?", "11001010000300"); System.out.println(ls.size()); List<vo> v = db.query("select a.res_code, a.res_value, b.S_VIDEO_NAME as name from tb_cus a left join tc_video_info b on (a.res_code = b.S_VIDEO_CODE) where res_code = ?;", vo.class, "11001010000300"); System.out.println(v.size());
redis查询
Setting setting = new Setting(); setting.set("port", "16386"); RedisDS rds = new RedisDS(setting, null); String t = rds.getStr("username"); System.out.println(t);
需要依赖:
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>2.4.2</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.1.0</version> </dependency>
2021-09-26
在获取ID的时候,明明是字符串, 通过.getStr("SID"),返回的是[48, 48, 49, 67, 80, 108, 89, 52, 83, 85, 55, 57, 50, 53, 51, 51]
然后通过get("SID").getClass().getName(),返回是[B,这样就很明显了,这个是Byte的数组,如果想转成字符串,
只能是 new String((byte[])ls.get(0).get("SID"))
第二天对比才知道,原来数据库里SID申明的是varbinary
2021-10-09
配置useUnicode=true时
查某一个字段=xxx中文时,结果为空,实际用数据库查,数据存在。
后来配置改成useUnicode=true&characterEncoding=UTF-8
可以正常查结果了。
2021-10-16
jdk7 版本(v4.6.10)的 cn.hutool.core.util.PinyinUtil 已不能用了,有些中文转不了,比如 妃
要用更高版本(jdk8+ v5+)的cn.hutool.extra.pinyin.PinyinUtil
posted on 2021-09-12 22:32 angelshelter 阅读(438) 评论(0) 编辑 收藏 举报