JAVA
java
Cynicism°(玩世不恭)
这个作者很懒,什么都没留下…
展开
-
JAVA普通类或者工具类调用Service层或者Mapper层报空指针
一、使用示例代码如下(示例):@Componentpublic class XXXTest{ @Autowired private XXXService xxxService; @Autowired private XXXMapper xxxMapper; public XXXTest(){} public static XXXTest xxxTest; @PostConstruct public void init(){ xxxTest原创 2021-11-30 14:30:44 · 4985 阅读 · 4 评论 -
验证数据是否存在,别再使用count了
学习目标:验证数据是否存在,写法优化常见写法:目前比较常见的写法// SQL写法select count(*) from table where A = 1 and B = 2// java写法int num = xxDao.XXXCount(params);if(num > 0){ // 存在执行这里代码}else{ // 不存在执行这里代码}优化写法:优化后的写法// SQL写法select 1 from table where A = 1 AND B =原创 2021-10-29 16:38:32 · 233 阅读 · 0 评论 -
String类型字符串截取
一、字符串从前往后截取1.从前往后截取遇到某个字符截止String str = "我爱你_JAVA";String s = str.substring(0,str.indexOf("_"));System.out.println(s);我爱你二、字符串从后往前截取1. 从后往前截取遇到某个字符截止String str = "测试Excel_往前截取.xlsx";String substring = str.substring(str.lastIndexOf("_") + 1);Sys原创 2021-10-25 15:07:14 · 1835 阅读 · 0 评论 -
@RequestBody和@RequestParam 同时在方法体里面,使用postman传递参数报错
问题描述:提示:如果同时存在 @RequestBody和@RequestParam 的方法接收参数,数据传输过程中出现数据传输格式错误@PostMapping("/test")public void test(@RequestBody Test test,@RequestParam Long id) {}原因分析:解决方案@RequestBody如果实体属性不是必传参数,这个里面可以不填参数但是必须要有{},传递的json格式@RequestParam 传递参数的格式两种原创 2020-11-27 16:44:34 · 2005 阅读 · 0 评论