Because there is no WeChat public number, so learning to pay can not go down.
Tables are related:
create table `product_info`( `product_id` varchar(32) not null, `product_name` varchar(64) not null comment 'Trade name', `product_price` decimal(8,2) not null comment 'Unit Price', `product_stock` int not null comment 'Stock', `product_description` varchar(64) comment 'describe', `product_ico` varchar(512) comment 'Small graph', `product_status` tinyint(3) default '0' comment 'Commodity status, 0 normal 1 off shelf' `category_type` int not null comment 'Category number', `create_time` timestamp not null default current_timestamp comment 'Creation time', `update_time` timestamp not null default current_timestamp on update current_timestamp comment 'Modification time', primary key(`product_id`) )comment 'Commodity list'; # Automatically create time, update time with @DynamicUpdate (on entity class) and jpa
The use of jpa
public interface OrderMasterRepository extends JpaRepository<OrderMaster,String> { Page<OrderMaster> findByBuyerOpenid(String buyerOpenid, Pageable pageable); }
enumeration
Define multiple enumerations as needed. If the order status can be one, the payment status can be one. Do not define all States in one enumeration.
jpa paging
public interface OrderMasterRepository extends JpaRepository<OrderMaster,String> { Page<OrderMaster> findByBuyerOpenid(String buyerOpenid, Pageable pageable); }
controller: Accept page,size:
PageRequest pageRequest = new PageRequest(page,size); Page<OrderDTO> orderDTOPage = orderService.findList(openid, pageRequest);
DTO
Define DTO delivery in business as needed
Control the length of time for negotiation:
public class Date2LongSerializer extends JsonSerializer<Date> { @Override public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeNumber(date.getTime()/1000); } } //Then use it in the transfer class variable. @JsonSerialize(using = Date2LongSerializer.class) private Date createTime; //Effect: 3 bits shorter time
Return to json
public class ProductVO { @JsonProperty("name") private String categoryName; @JsonProperty("type") private Integer categoryType; @JsonProperty("foods") private List<ProductInfoVO> productInfoVOList; } json The return field is: name type foods
Remove the display for null fields in json
spring: jackson: default-property-inclusion: non_null
Object copy
Copy the field values in the orderMaster object to the fields in the orderDTO (only the values in variables with the same name are copied)
BeanUtils.copyProperties(orderMaster,orderDTO);
Form validation controller accepts judgment like this
public ResultVO<Map<String,String>>create(@Valid OrderForm orderForm, BindingResult bindingResult){ Map<String,String> map = new HashMap<>(); if(bindingResult.hasErrors()){ log.error("[The form parameters are incorrect. orderForm={}",orderForm ); throw new SellException(ResultEnum.PARAM_ERROR.getCode(), bindingResult.getFieldError().getDefaultMessage()); }
Lambda expression
List<Integer> categoryTypeList = productInfoList.stream() .map(e -> e.getCategoryType()) .collect(Collectors.toList()); //Traverse the product Info. getCategoryType () in the collection productInfoList through the categoryTypeList