肯尼小龟的爪洼日记

阅读: 评论:0

肯尼小龟的爪洼日记

肯尼小龟的爪洼日记

6.2

  1. select distinct
    在表中,可能会包含重复值。这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值。
    关键词 DISTINCT 用于返回唯一不同的值。
  2. foreach标签
public List<Entity> queryEntity(List<Long> userids);<select id="queryEntity" resultMap="BaseResultMap">select * form Entitywhere id in<foreach collection="userids" item="userid" index="index" open="(" close=")" separator=",">#{userid}</foreach>
</select>
String getSpuId(@Param("sku") List<Long> sku);<select id="getSpuId" resultType="java.lang.String">select distinct spu_code from skuwhere status = 1<if test="sku != null">and sku_code in<foreach collection="sku" item="item" index="index" open="(" close=")" separator=",">#{item}</foreach></if>
</select>
  1. concat模糊查询
<select id="query" resultMap="BaseResultMap" paramType="Entity">select * from entity<where><if test="name != null">name like ('%',concat(#{name}),'%')</if></where>
</select>
List<Question> list<@Param("keys") String keys,@Params("pageBean") PageBean pageBean);<select id="list" resultMap="BaseResultMap">select<include refid="Base_Column_List"/>from questionwhere is_delete=0<if test="keys!=null and keys !=''">and (title like concat('%',#{keys},'%') or 'keys' like concat('%',#{keys},'%'))</if>order by update_time desclimit #{pageBean.offset},#{pageBean.pageSize}
</select>

6.4

  1. IDEA中的run和debug,在debug模式下,有些修改是热启动的,而有些情况又不是。
    适用的情况:
    - 修改方法体内的内容,实例方法或是静态方法。
    不适用的情况:
    - 新增、删除实例方法、静态方法时。
    - 新增、删除实力变量、类变量时。
    - 引入了新创建的内部类或外部类时。
    - 方法当中有对变量或实例变量的引用,或是当外部变量被修改时。
    参考

  2. 在Intellij IDEA中使用debug 参考

6.5

  1. 在IDEA中使用LeetCode插件
  2. LeetCode:(数组)两数之和。参考
//数组 int nums[] ,目标值 target,在数组中找出两个和为目标值的数,返回下标
//方法一:暴力法: 时间复杂度 O(n^2)  空间复杂度 O(1)
{for(int i=0;i<nums.length;i++){for(int j=i+1;j<nums.length;j++){if(nums[i]+nums[j] == target){return new int[]{i,j};}}}throw new IllegalArgumentException("no TwoSum solution");
}//方法二:用hashmap(两次),利用键值的唯一对应关系 时间复杂度 O(n)  空间复杂度 O(n)
{Map<Integer,Integer>map=new hashMap<>();for(int i=0;i<nums.length;i++){map.put(nums[i],i);}for(int i=0;i<nums.length;i++){int another=target-nums[i];ainsKey(another) && map(another) != i){return new int[]{(another)};}}throw new IllegalArgumentException("no TwoSum solution");
}//方法三:用hashmap(一次),空间复杂度 O(n),空间复杂度 Oo(n)
{Map<Integer,Integer> map=new hashMap<>();for(int i=0;i<nums[i];i++){int another = target - nums[i];ainsKey(another) && (another) != i){return new int[]{(another),i};}map.put(nums[i],i);}throw new IllegalArgumentException("no TwoSum solution");
}

6.8

  1. (流式计算)获取集合里面的某个字段再组成普通LIst集合
public class A {private Long id;
}
//现有集合 as
List<A> as
//故可以写成
List<Long> ids = as.steam().map(A::getId).List());
  1. (流式计算) 获取集合里的某些字段再组成map集合
public class B {private Long id;private String name;
}
//现有集合 bs
List<B> bs
//新建容器
Map<Long,String> map = new HsahMap<>();
//故可以写成
map = bs.stream().Map(B::getId,B::getName));
  1. (流式计算)某集合B,现把B.id为键,B为值组成map集合
static <T> Function<T, T> identity(){return t -> T;
}public class B {private Long id;private String name;
}
//现有集合 bs
List<B> bs
//故可以写成
Map<Long,B> map = bs.stream().Map(B::getId,Function.identity()));

6.9

  1. stream入门练习 参考
  • filter 筛选
//新建Student类
public class Student{private int id;private String name;private int age;private String address;//无参、有参、get、set、tostring
}// >>>filter<< (筛选)
Student s1 = new Student(1L,"kenny",15,"浙江");
Student s2 = new Student(2L,"jay",15,"江苏");
Student s3 = new Student(3L,"turtle",17,"上海");
Student s4 = new Student(4L,"kongfu",17,"北京");
students.add(s1);
..
..
//筛选年龄大于15的学生
List<Student> result = students.stream().filter(s -> s.getAge()>15).List());
//筛选住在浙江省的学生
List<Student> result = students.stream().filter(s -> "浙江".Address())).List());
  • map 转换
Student s1 = new Student(1L,"kenny",15,"浙江");
Student s2 = new Student(2L,"jay",15,"江苏");
Student s3 = new Student(3L,"turtle",17,"上海");
Student s4 = new Student(4L,"kongfu",17,"北京");
students.add(s1);
..
..
//在地址前面加上部分信息,只获取地址输出
List<Student> result = students.stream().map(s -> "地址:"&#Address()).List())
//map就是将对应的元素按照给定的方法进行转换
  • distinct 去重
List<String> list = Arrays.asList("11","22","33","11");
list.stream().distinct().forEach(System.out::println);
  • sorted 排序
List<String> list = Arrays.asList("33","22","11");
list.stream().sorted().forEach(System.out::println); //33 22 11//------------------------------------------------------------------
students.stream().sorted(stu1,stu2) -> Id(),Id()).sorted(stu1,stu2) -> Age(),Age()).forEach(System.out::println);
//指定排序规则,先按照学生的id进行降序排序,再按照年龄进行降序排序
  • limit 限制返回个数
//返回集合前几个元素
List<String> list = Arrays.asList("33","22","11");
list.stream().limit(2).forEach(System.out::println); //33 22
  • skip 删除元素
//删除前两个元素
List<String> list = Arrays.asList("33","22","11");
list.stream().skip(2).forEach(System.out::println); // 11
  • reduce 聚合
List<String> list = Arrays.asList("不相","信眼","泪");
String result = duce("互联网",(a,b) -> (a+b);
sout(result);//互联网不相信眼泪
  • min 最小值
//获取年龄最小的学生
//学生集合 stuents
Student minAgeStu = students.stream().min((stu1,stu2) -> Age(),Age()).toget();
//最大值 max同理
  • anyMatch / allMatch /noneMatch 匹配
//学生集合 students
//是否有浙江人
Boolean amyMatch = students.stream().anyMatch(s -> "浙江".Adress()));
//是否所有学生都满15岁
Boolean allMatch = students.stream().allMatch(s -> s.getAge()>15);
//是否没有人叫kenny
Boolean nonMatch = students.stream().nonMatch(s -> "kenny".Name()));
  1. IntValue()方法
//输出int数据
Double s = 2.5;
Float k = 2.7f;System.out.println(k.intValue());//2
System.out.println(s.intValue());//2
//就是丢掉小数位
  1. BigDecimal(num).setScale ROUND_HALF_UP
String num = "176.5555";
System.out.println(new BigDecimal(num).setScale(3.BigDecimal.ROUND_HALF_UP));//176.556
double num = "176.5555";
System.out.println(new BigDecimal(num).setScale(3.BigDecimal.ROUND_HALF_UP));//176.555
//故为确保准确性,尽量使用String作为传入值
  1. Java.math.BigDecimal.subtract()
BigDecimal bd1,bd2;
bd1 = new BigDecimal("100.123");
bd2 = new BigDecimal("50.56");System.out.println(bd1.subtract(bd2));//49.563

6.22

  1. 在表里增加字段
ALTER TABLE 'sku'
ADD COLUMN 'goods_style' tinyint(4) NOT NULL DEFAULT 0 COMMENT '商品风格(0-普通商品;1-组合商品)'; 
  1. 新增表格
CREATE TABLE 'sku_combined' ('id' int(11) NOT NULL AUTO_INCREMENT COMMENT '主键','sku_id' int(11) NOT NULL DEFAULT '0' COMMENT '组合商品主键',...'goods_price' decimal(32,2) NOT NULL DEFAULT '0.00' COMMENT '销售价','create_user' varchar(32) NOT NULL DEFAULT '' COMMENT '创建人','create_time' datetime NOT NULL COMMENT '创建时间',PRIMARY KEY (’id')
)	ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT = '组合商品sku关系';
  1. 遍历集合
List<carProduct> list = ListProduct(id);list.forEach(item -> {xxxIdList.Id());xxxMap.SkuId(),TopicId());......
});
  1. 将集合中某个对象的指定值,封装成list
public class CollectionExtUtil{....../***更符合java8理念的方式,将集合中对象的指定field value封装成list* T:结果对象泛型   * F:原集合对象泛型*/public static <T, F, C extends Collection<F>> List<T> getPropertyList(C c, Function<? super F, ? extends T> mapper){if(CollectionUtils.isEmpty(c)){ptyList();}return c.stream().map(mapper).List());}
}..
..
/***使用*/
List<SkuEntity> skus = skuService.listByIdList(skuIdList);
List<Long> spuCodeList = PropertyList(skus,SkuEntity::getSpuCode);
  1. 统计现金应该支付的金额
/***有一商品集合list,用户积分credit,售价goodsPrice,数量quantity*商品A,售价x元,可用积分y,商品数量z*商品B,售价xx元,可用积分yy,商品数量zz*商品B,售价xxx元,可用积分yyy,商品数量zzz*...*公式为  ((售价-积分)乘数量)遍历累和*/long shouldCashPay = list.stream().mapToLong(item -> {Long credit = Credit();if(credit == null || credit != 0){return 0;}long margin = dsPrice() - credit;if(margin < 0){return 0;}return margin * Quantity();}).sum();

6.24

  1. (Java8)函数是一等值,将方法作为函数式值来传递
    现在有一个Apple类
//写两个方法作判断
public static boolean isGreenApple(Apple apple){return "green".Color);
}
public static boolean isHeavyApple(Apple apple){Weight()>150;
}//Java8会把条件代码作为参数传递进去
public interface predicate<T>{boolean test(T t);
}                                                  //方法作为predicate参数p传递进去
static List<Apple> filterApples(List<Apple> inventory,predicate<Apple> p){List<Apple> result = new arrayList<>();for(Apple apple : inventory){st(apple){//苹果符合p所代表的条件吗result.add(apple);}}return result;
}
//当要使用这个方法的时候,可以这样
List<Apple> filterColer = filterApples(inventory, Apple::isGreenApple);
List<Apple> filterWeight = filterApples(inventory, Apple::isHeavyApple); 
  1. 关于java8第一章 的笔记,(Stream和编程思想)
  • 显而易见,Stream API和现有的集合API的行为都是差不多:他们都能访问数据项目的序列。不过有一点需要注意,Collection主要是为了存储和访问数据,而Stream则主要是用于描述对数据的计算(这个也很好理解,我们使用Stream就是为了应对各种各样的计算场景)
  • 筛选一个Collection的最快方法常常是将其转化为Stream,进行并行处理,然后再转回List(这里就解释了为什么作为小白的我看到的流式计算都是先集合.stream()最后又toList()结尾)
  • 串行.stream()和并行parallelStream()
  • 函数是一等值:记住方法是如何作为函数式值来传递的

问题:

  • 方法引用,一等值和二等值(不理解)😵😵😵
  • 怎么理解【接口如今可以包含实现类没有提供实现的方法签名了!那谁来实现它呢?缺失的方法主体随接口提供了(因此就有了默认实现),而不是由实现类提供】这句话😵😵😵
  • 怎么理解默认方法默认实现default😵😵😵
  • 如何理解再没有可变共享状态时,函数或方法可以有效、安全地并行执行😵😵😵

7.14

  1. 需求背景:数据库里有一个字段名为跟踪(0-未跟踪,1-跟踪),现有一个需求为根据是否跟踪过来筛选列表。
    预期是,不传值时为查全部,传0值为查为跟踪,1值为跟踪。
    结果是,不传值时,后台拿到的是0 。
    原因:因为我将实体类中的isTrack字段属性定义成了int类型,它将空值自动变为了0,改为Integer可解决。

2.25

1.在开发中,有一些值是规定了的,比如购物车的最大商品数量,比如首页轮播图数量等等,这些可以全放在一个类里。

public class Constants{private final static int INDEX_CAROUSEL_NUMBLE = 5;....
}

2.日志,在controller层,可以通过使用日志类,来打印日志

public class A{private static final Logger logger = Logger(A.class);public String methodA(Long id,String name){logger.info("logger here. id={},name={}",id,name)}
}

3.1

Long[] ids 转换为List<Long> ids2Arrays.asList(ids)//  Arrays.asList 和 Collections.singletonList()的区别1.Arrays.asList() 得到的List是可变的,根据数组大小确定。不具备add方法,但是可以用set方法进行增值,默认长度是10而Collections.singletonList是不可变的2.Collections.singletionList()得到的元素只能有一个,不要尝试对其元素进行修改

3.15

一:新增的接口,注意几点1.可以用PosttMapping2.参数里的类的注解可以用 @RequestBody二:服务层需要加@Transactional注解三:intValue()    //输出int数据四:xml里。```<update id="xxxx" parameterType = "类名">update xxx_xx_xx<set><</set>where xxxxxx</update>``````<insert id="xxxx" parameterType = "类名">insert into xxx_xx_xx<trim prefix="(" suffix=")" suffixOverrides=","><</trim ><trim prefix="values (" suffix=")" suffixOverrides=","><</trim > </insert >```

3.25

  1. 实体类里的注解
    @Data,lombok注解,可以省去getset方法的步骤
    @ApiModelProperty:如果有用到swagger,那这个注解为Swagger接口文档所需
    @NotEmtpy:参数验证的注解,意为非空

@RestController
@Api(value="v1", tage = "用户操作相关接口")
@RequestMapping("/api/v1")
public class PersonAPI{@Resourceprivate UserService userService;private static final Logger logger = Logger(PersonAPI.class);
//1.定义成static final,logger变量不可变,读取速度快
//2.static修饰的变量是不管创建了new了多少个实例,也只能创建一次,节省空间,不然每次都创建Logger的话比较浪费内存;final修饰表示不可更改,
//3.将域定义为static,每个类中只有一个这样的域,而每一个对象对于所有的实例域却都有自己的一份拷贝,用static修饰既节省空间,效率也好。final是指本logger不能再指向其他Logger对象@PostMapping("/user/login")@ApiOperation(value="登陆接口",notes = "返回token")public Result<String>login(@ResuestBody @Valid UserLoginParam userLoginParam){.........}
}

@PostMapping("/user/login")表示登陆请求为post,请求路径为/api/v1/user/login
首先使用@RequestBody注解对登陆参数进行接收并封装📦成UserLoginParam对象,@Valid注解作为验证参数,定义参数时我们使用了@NotEmpty注解,表示该参数不能为空,如果这里不加@Valid注解,则非空验证则不会执行

4.13

1.分页数据封装类
用到了pageHelper工具类,分页用到了五个数据,当前页(pageNum)、页面大小(pageSize)、总页数(totalPage)、总条数(total)、数据(List< T > list)

public class CommonPage<T>{
private Integer pageNum;
private Integer pageSize;
private Integer totalPage;
private Long total;
private List<T> list;
//
get and set
//
//将pagehelper分页后的list转为分页信息public static<T> CommonPage<T> restPage(List<T> list){CommonPage<T> result = new CommonPage<T>();PageInfo<T> pageinfo = new PageInfo<T>();//封装result并返回result.PageNum());result.PageSize());result.Pages());result.Total());result.List());return result;}}

4.19

报错cannot resolve symbol String
重新选一下jdk

表单列横向排列

.el-form-item {
display: inline-block !important;
}

本文发布于:2024-01-29 16:13:40,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170651602216506.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:肯尼   日记
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23