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>
<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>
IDEA中的run和debug,在debug模式下,有些修改是热启动的,而有些情况又不是。
适用的情况:
- 修改方法体内的内容,实例方法或是静态方法。
不适用的情况:
- 新增、删除实例方法、静态方法时。
- 新增、删除实力变量、类变量时。
- 引入了新创建的内部类或外部类时。
- 方法当中有对变量或实例变量的引用,或是当外部变量被修改时。
参考
在Intellij IDEA中使用debug 参考
//数组 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");
}
public class A {private Long id;
}
//现有集合 as
List<A> as
//故可以写成
List<Long> ids = as.steam().map(A::getId).List());
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));
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()));
//新建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());
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就是将对应的元素按照给定的方法进行转换
List<String> list = Arrays.asList("11","22","33","11");
list.stream().distinct().forEach(System.out::println);
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进行降序排序,再按照年龄进行降序排序
//返回集合前几个元素
List<String> list = Arrays.asList("33","22","11");
list.stream().limit(2).forEach(System.out::println); //33 22
//删除前两个元素
List<String> list = Arrays.asList("33","22","11");
list.stream().skip(2).forEach(System.out::println); // 11
List<String> list = Arrays.asList("不相","信眼","泪");
String result = duce("互联网",(a,b) -> (a+b);
sout(result);//互联网不相信眼泪
//获取年龄最小的学生
//学生集合 stuents
Student minAgeStu = students.stream().min((stu1,stu2) -> Age(),Age()).toget();
//最大值 max同理
//学生集合 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()));
//输出int数据
Double s = 2.5;
Float k = 2.7f;System.out.println(k.intValue());//2
System.out.println(s.intValue());//2
//就是丢掉小数位
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作为传入值
BigDecimal bd1,bd2;
bd1 = new BigDecimal("100.123");
bd2 = new BigDecimal("50.56");System.out.println(bd1.subtract(bd2));//49.563
ALTER TABLE 'sku'
ADD COLUMN 'goods_style' tinyint(4) NOT NULL DEFAULT 0 COMMENT '商品风格(0-普通商品;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关系';
List<carProduct> list = ListProduct(id);list.forEach(item -> {xxxIdList.Id());xxxMap.SkuId(),TopicId());......
});
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);
/***有一商品集合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();
//写两个方法作判断
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);
Collection主要是为了存储和访问数据,而Stream则主要是用于描述对数据的计算
(这个也很好理解,我们使用Stream就是为了应对各种各样的计算场景)集合.stream()
最后又toList()
结尾).stream()
和并行parallelStream()
问题:
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)}
}
Long[] ids 转换为List<Long> ids2Arrays.asList(ids)// Arrays.asList 和 Collections.singletonList()的区别1.Arrays.asList() 得到的List是可变的,根据数组大小确定。不具备add方法,但是可以用set方法进行增值,默认长度是10而Collections.singletonList是不可变的2.Collections.singletionList()得到的元素只能有一个,不要尝试对其元素进行修改
一:新增的接口,注意几点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 >```
实体类里的注解
@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注解,则非空验证则不会执行
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;}}
报错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 条评论) |