耗子叔ARTS:第八周

 

Algorithm:

 

/**

 * 21. Merge Two Sorted Lists

 Easy



 2190



 310



 Favorite



 Share

 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.



 Example:



 Input: 1->2->4, 1->3->4

 Output: 1->1->2->3->4->4

 Accepted

 576,774

 Submissions

 1,223,527

 */

 

JAVA:

static class ListNode {

    int val;

    ListNode next;



    ListNode(int x) {

        val = x;

        next = null;

    }

}

public ListNode mergeTwoLists(ListNode l1, ListNode l2) {

    if(l1 == null) return l2;

    if(l2 == null) return l1;

    if(l1.val < l2.val){

        l1.next = mergeTwoLists(l1.next, l2);

        return l1;

    } else{

        l2.next = mergeTwoLists(l1, l2.next);

        return l2;

    }

}
 

GO:

func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {

   if l1 == nil {

      return l2

   }

   if l2 == nil {

      return l1

   }

   if l1.Val < l2.Val {

      l1.Next = mergeTwoLists(l1.Next, l2)

      return l1

   } else {

      l2.Next = mergeTwoLists(l1, l2.Next)

      return l2

   }

}



type ListNode struct {

   Val  int

   Next *ListNode

}

 

Review:

https://onezero.medium.com/the-huawei-disaster-reveals-googles-iron-grip-on-android-b1ccee34504d

 

The Huawei Disaster Reveals Google’s Iron Grip on Android

Open source isn’t as open as you think

 

 

Eric RavenscraftFollow

May 23

https://cdn-images-1.medium.com/max/1600/1*dxoArLWrCKqhapxyUnlvPQ.jpeg

 

 

Credit: John MacDougall/Getty Images

 

https://cdn-images-1.medium.com/max/800/1*MaTdjUVgNF2TxZid3f3Sdw.pngGoogle’s Android is pitched as the open, free-for-everyone alternative to the iPhone. However, to comply with a recent order from the U.S. government, Google pulled the Chinese tech company and smartphone manufacturer Huawei’s license to use the proprietary Google software that sits on top of Android. In doing so, Google quietly exposed the powerful control it has over its supposedly open phone ecosystem.

Most Android manufacturers — including Huawei — are what’s known as Google hardware partners. This relationship lets them build their phones around a collection of Google products, from apps like Google Maps and Assistant, to under-the-hood tools like location services or push notifications. While Google gives off the impression that Android is open and available to everyone, these services represent a quiet control that the company doesn’t often enforce over its hardware partners — though, as it has now proven, it certainly can.

With the recent order, the U.S. government forced Google’s hand. The U.S. Department of Commerce put Huawei on the “Entity List,” which blocks it from buying technology from U.S. companies without government approval. Huawei and Google now have three months to send updates to existing users. For new phones, Huawei may be able to use the open-source version of Android, but it can’t be a Google partner.

The distinction between using Android and being a Google partner seems messy from the outside, but “Android” technically refers to the core operating system that covers basic things like making phone calls or using the camera. The freely available version of Android is called the Android Open Source Project (AOSP) and a company doesn’t have to be a partner to use it.

Most manufacturers like Huawei, however, do choose to become a Google partner. That means Huawei agrees to only make devices that use a collection of Google apps known as Google Mobile Services which includes things like Gmail, YouTube, and the Google Play Store. Under this arrangement, Huawei can’t, for example, make a phone that ships with Microsoft’s Bing and Edge instead of Google Search and Chrome.

Manufacturers generally have little choice but to play by Google’s rules, because the costs of doing otherwise are tremendous.

Partners also have to meet certain security and compatibility conditions. In exchange, they get access to all of Google’s apps and infrastructure, making their phones much more appealing to customers worldwide than they would otherwise be. This arrangement is usually free, though manufacturers who sell in the EU pay a fee and are exempt from the all-or-nothing condition for complicated legal reasons.

According to Bryan Pon, PhD, mobile platform researcher and co-founder of the data analytics firm Caribou Data, this gives Google a lot of control over its platform. “Consumers are attached to the Google products and services that sit on top of the operating system,” explains Pon. “Google has very strong proprietary control over those, and in that sense wields tremendous power, irrespective of the operating system.”

Additionally, Huawei, and Google’s other partners, have to include a collection of developer tools called Google Play Services. These background tools let app developers easily do things like create push notifications, embed maps in their apps, or get a GPS location. Most Android apps distributed through the Google Play Store rely on some of these tools to provide features that are too expensive or difficult for every developer to build themselves.

As Pon explains, some of these tools are crucial features that would normally be part of an operating system. “They’re actually taking functionality out of the core platform,” Pon says. “They’re leaving Android open source, more and more, just a shell. And that core functionality is now part of just proprietary Google services.” Google does this to make it easier to update important features without waiting for a big Android update, but the result consolidates Google’s power over its platform.

Without Google Play Services, Huawei would have to build these tools itself or leave developers to do it. The company has created its own version of some of these features — like a push notification service — but developers still have to add support for Huawei’s version of the tools to their apps in order for them to work on non-Google phones. Huawei is building its own app store alternative, but it could take a long time to build everything else that developers and users are accustomed to getting from Google.

Manufacturers generally have little choice but to play by Google’s rules, because the costs of doing otherwise are tremendous. One of the few companies to opt out of Google’s system was Amazon with its series of Fire Tablets. If you buy a Fire, you’ll have something similar to an Android experience, but with hardly a trace of Google. Instead, you’ll use the Amazon Appstore. You’ll talk to Alexa instead of the Google Assistant. You’ll use Amazon’s Silk Browser instead of Chrome. Under the hood, all your apps will be using Amazon’s version of key features, like notifications or GPS. The approach works fine enough for a tablet, but when Amazon tried to make a phone, it failed miserably.

Samsung tries to walk a middle ground, offering parallel versions of almost everything Google makes, from basic email apps to its own voice assistant, without breaking away from its partner agreement. But if Samsung were to find itself in Huawei’s shoes, even that might not be enough. “I think to some extent, Samsung has to tell itself that it… has a plan B,” says Pon. “But I think, realistically, if they get turned off, like Huawei might get turned off, then they don’t have any good options.”

Under normal circumstances, this symbiotic relationship benefits everyone involved and lends credibility to Google’s claim that Android — unlike the iPhone — is “open,” while still letting the company maintain as much control over Android as possible. If a company like Amazon wants to build its own alternative from scratch, it can. For companies like Samsung and Huawei that can’t afford to or aren’t willing to go that far, they can leverage Google’s massive resources to make a variation of Android that consumers will want, without deviating too far from Google’s master plan.

Now, barring relief in the brewing China-U.S. trade war, Huawei has been forcibly pushed into going the much harder Amazon route. Huawei can’t use Google apps, it can’t support the push notifications or location services most apps use, and it even has to wait longer for security updates before it can push them to users. Existing users won’t be affected for now, thanks to the temporary license granted by the U.S. Commerce Department, but future plans look grim. It took Amazon years to build its own version of Google’s services. Huawei’s CEO says the company has a plan, but it’s unclear how long that plan could take to unfold.

Fortunately, for Huawei, it’s not all bad news. The Google Play Store has been banned in China for years due to the country’s Great Firewall that censors many foreign sites and services including Google search, Facebook, or YouTube. Losing them is of little importance in the Chinese market, which makes up 52% of the company’s overall revenue. Outside China, on the other hand, Huawei stands to lose quite a lot. Globally, it’s hard to sell an Android phone without Google services.

Google can reaffirm its commitment to being “open” and “free” all it wants, but ultimately it’s still a gatekeeper.

Beyond Huawei’s problems — and beyond the reality that geopolitics will play an increasing role in the tech business — this situation reveals a truth that Google has downplayed for years. While Android — the stripped down, open-source operating system — may be available to everyone, all of the Google pieces that make most Android phones worthwhile are locked behind a partner program. Google might let almost everyone into its exclusive club, but it reserves the right to kick them out.

Even if we could assume the best about Google’s intentions to keep Android as open as possible — and Google did not respond to a request by OneZero for comment — the Huawei order demonstrates that Google’s control can be abused by other entities. If the U.S. were in a trade war with South Korea instead of China, Samsung phones — still the most popular in the world over — could face a similar fate. Google can reaffirm its commitment to being “open” and “free” all it wants, but ultimately it’s still a gatekeeper.

 

Tip:

实现幂等:

原来想的实现两种思路。

一种是:增加缓存。设置缓存失效时间(redis

另一种是:查询记录,如果有记录说明已经调用过了。

后来发现项目中有个自定义注解。就是为了防止多次调用进行实现的。

切面设置controller层,以及使用注解的地方。

redis进行缓存。可以解决。

Share:

https://mp.weixin.qq.com/s/m5pHwJFwWfMG78S1394u6w

 

springBoot注解大全

程序员面试 今天

 

 

作者:tanwei81

https://www.cnblogs.com/tanwei81/p/6814022.html

 

一、注解(annotations)列表

 

 

@SpringBootApplication

包含了@ComponentScan、@Configuration和@EnableAutoConfiguration注解。其中@ComponentScan让spring Boot扫描到Configuration类并把它加入到程序上下文。

@Configuration 等同于spring的XML配置文件;使用Java代码可以检查类型安全。

@EnableAutoConfiguration 自动配置。

@ComponentScan 组件扫描,可自动发现和装配一些Bean。

@Component可配合CommandLineRunner使用,在程序启动后执行一些基础任务。

@RestController注解是@Controller和@ResponseBody的合集,表示这是个控制器bean,并且是将函数的返回值直 接填入HTTP响应体中,是REST风格的控制器。

@Autowired自动导入。

@PathVariable获取参数。

@JsonBackReference解决嵌套外链问题。

@RepositoryRestResourcepublic配合spring-boot-starter-data-rest使用。

 

二、注解(annotations)详解

 

 

@SpringBootApplication:申明让spring boot自动给程序进行必要的配置,这个配置等同于:@Configuration ,@EnableAutoConfiguration 和 @ComponentScan 三个配置。

 

package com.example.myproject; 

import org.springframework.boot.SpringApplication; 

import org.springframework.boot.autoconfigure.SpringBootApplication;



@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan 

public class Application { 

public static void main(String[] args) 

SpringApplication.run(Application.class, args); 



}

@ResponseBody:表示该方法的返回结果直接写入HTTP response body中,一般在异步获取数据时使用,用于构建RESTful的api。在使用@RequestMapping后,返回值通常解析为跳转路径,加上@responsebody后返回结果不会被解析为跳转路径,而是直接写入HTTP response body中。比如异步获取json数据,加上@responsebody后,会直接返回json数据。该注解一般会配合@RequestMapping一起使用。示例代码:

@RequestMapping(“/test”) 

@ResponseBody 

public String test(){ 

return”ok”; 

}

 

@Controller:用于定义控制器类,在spring 项目中由控制器负责将用户发来的URL请求转发到对应的服务接口(service层),一般这个注解在类中,通常方法需要配合注解@RequestMapping。示例代码:

@Controller 

@RequestMapping(“/demoInfo”) 

publicclass DemoController { 

@Autowired 

private DemoInfoService demoInfoService;



@RequestMapping("/hello")

public String hello(Map<String,Object> map){

   System.out.println("DemoController.hello()");

   map.put("hello","from TemplateController.helloHtml");

   //会使用hello.html或者hello.ftl模板进行渲染显示.

   return"/hello";

}

}

@RestController:用于标注控制层组件(如struts中的action),@ResponseBody和@Controller的合集。示例代码:

package com.kfit.demo.web;



import org.springframework.web.bind.annotation.RequestMapping

import org.springframework.web.bind.annotation.RestController;





@RestController 

@RequestMapping(“/demoInfo2”) 

publicclass DemoController2 {



@RequestMapping("/test")

public String test(){

   return"ok";

}

}

@RequestMapping:提供路由信息,负责URL到Controller中的具体函数的映射。

@EnableAutoConfiguration:Spring Boot自动配置(auto-configuration):尝试根据你添加的jar依赖自动配置你的Spring应用。例如,如果你的classpath下存在HSQLDB,并且你没有手动配置任何数据库连接beans,那么我们将自动配置一个内存型(in-memory)数据库”。

你可以将@EnableAutoConfiguration或者@SpringBootApplication注解添加到一个@Configuration类上来选择自动配置。如果发现应用了你不想要的特定自动配置类,你可以使用@EnableAutoConfiguration注解的排除属性来禁用它们。

@ComponentScan:表示将该类自动发现扫描组件。个人理解相当于,如果扫描到有@Component、@Controller、@Service等这些注解的类,并注册为Bean,可以自动收集所有的Spring组件,包括@Configuration类。我们经常使用@ComponentScan注解搜索beans,并结合@Autowired注解导入。可以自动收集所有的Spring组件,包括@Configuration类。

我们经常使用@ComponentScan注解搜索beans,并结合@Autowired注解导入。如果没有配置的话,Spring Boot会扫描启动类所在包下以及子包下的使用了@Service,@Repository等注解的类。

@Configuration:相当于传统的xml配置文件,如果有些第三方库需要用到xml文件,建议仍然通过@Configuration类作为项目的配置主类——可以使用@ImportResource注解加载xml配置文件。

@Import:用来导入其他配置类。

@ImportResource:用来加载xml配置文件。

@Autowired:自动导入依赖的bean

@Service:一般用于修饰service层的组件

@Repository:使用@Repository注解可以确保DAO或者repositories提供异常转译,这个注解修饰的DAO或者repositories类会被ComponetScan发现并配置,同时也不需要为它们提供XML配置项。

@Bean:用@Bean标注方法等价于XML中配置的bean。

@Value:注入Spring boot application.properties配置的属性的值。示例代码:

@Value(value = “#{message}”) 

private String message;

@Inject:等价于默认的@Autowired,只是没有required属性;

@Component:泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。

@Bean:相当于XML中的,放在方法的上面,而不是类,意思是产生一个bean,并交给spring管理。

@AutoWired:自动导入依赖的bean。byType方式。把配置好的Bean拿来用,完成属性、方法的组装,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。当加上(required=false)时,就算找不到bean也不报错。

@Qualifier:当有多个同一类型的Bean时,可以用@Qualifier(“name”)来指定。与@Autowired配合使用。@Qualifier限定描述符除了能根据名字进行注入,但能进行更细粒度的控制如何选择候选者,具体使用方式如下:

@Autowired 

@Qualifier(value = “demoInfoService”) 

private DemoInfoService demoInfoService;

@Resource(name=”name”,type=”type”):没有括号内内容的话,默认byName。与@Autowired干类似的事。

 

三、JPA注解

 

 

@Entity:@Table(name=”“):表明这是一个实体类。一般用于jpa这两个注解一般一块使用,但是如果表名和实体类名相同的话,@Table可以省略

 

@MappedSuperClass:用在确定是父类的entity上。父类的属性子类可以继承。

@NoRepositoryBean:一般用作父类的repository,有这个注解,spring不会去实例化该repository。

@Column:如果字段名与列名相同,则可以省略。

@Id:表示该属性为主键。

@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = “repair_seq”):表示主键生成策略是sequence(可以为Auto、IDENTITY、native等,Auto表示可在多个数据库间切换),指定sequence的名字是repair_seq。

@SequenceGeneretor(name = “repair_seq”, sequenceName = “seq_repair”, allocationSize = 1):name为sequence的名称,以便使用,sequenceName为数据库的sequence名称,两个名称可以一致。

@Transient:表示该属性并非一个到数据库表的字段的映射,ORM框架将忽略该属性。如果一个属性并非数据库表的字段映射,就务必将其标示为@Transient,否则,ORM框架默认其注解为@Basic。@Basic(fetch=FetchType.LAZY):标记可以指定实体属性的加载方式

@JsonIgnore:作用是json序列化时将Java bean中的一些属性忽略掉,序列化和反序列化都受影响。

@JoinColumn(name=”loginId”):一对一:本表中指向另一个表的外键。一对多:另一个表指向本表的外键。

@OneToOne、@OneToMany、@ManyToOne:对应hibernate配置文件中的一对一,一对多,多对一。

 

四、springMVC相关注解

 

 

@RequestMapping:@RequestMapping(“/path”)表示该控制器处理所有“/path”的UR L请求。RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。

 

用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。

该注解有六个属性:

  1. params:指定request中必须包含某些参数值是,才让该方法处理。
  2. headers:指定request中必须包含某些指定的header值,才能让该方法处理请求。
  3. value:指定请求的实际地址,指定的地址可以是URI Template 模式
  4. method:指定请求的method类型, GET、POST、PUT、DELETE等
  5. consumes:指定处理请求的提交内容类型(Content-Type),如application/json,text/html;
  6. produces:指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回

@RequestParam:用在方法的参数前面。

@RequestParam 

String a =request.getParameter(“a”)

@PathVariable:路径变量。如

RequestMapping(“user/get/mac/{macAddress}”) 

public String getByMacAddress(@PathVariable String macAddress){ 

//do something; 

参数与大括号里的名字一样要相同。

 

五、全局异常处理

 

 

@ControllerAdvice:包含@Component。可以被扫描到。统一处理异常。

 

@ExceptionHandler(Exception.class):用在方法上面表示遇到这个异常就执行以下方法。

 

 

聚焦程序员面试

 

长按订阅↓

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值