当前位置:网站首页>Interview-01

Interview-01

2022-06-27 03:32:00 csx_ zzh

Catalog

1. Self introduction.

2. Introduce your project

3. Yes spring Understanding of the framework (ioc aop)

IOC

AOP

4.redis Five basic types of + Two advanced data types

5. How do comments on comments come about

[email protected] How to realize the function

7. The realization of like function

8. Is your project front end and back end separated ?

9. About Ajax

10. Common algorithms you encounter in competitions

1. Longest text substring (dp)

2. Traversal of binary tree ( Deep search + Guang Shu )

11. Do you have anything to ask ?


1. Self introduction.

2. Introduce your project

The overall structure of this project comes from Niuke , Mainly used Springboot、Mybatis、MySQL、Redis、Kafka、 Tools such as . It mainly realizes the registration of users 、 Sign in 、 Post 、 give the thumbs-up 、 System notification 、 Sort by heat 、 Search and other functions . In addition, it introduces redis Database to improve the overall performance of the website , It realizes the access of user credentials 、 Like the functions concerned . be based on Kafka Realize system notification : When users get likes 、 Get notified after comments . Use the timed task to calculate the scores of posts regularly , And show the hot post ranking list on the page .

3. Yes spring Understanding of the framework (ioc aop)

IOC

First of all IOC, What exactly is IOC Well ?IOC(Inversion Of Control) be called Inversion of control . It is mainly a design idea , It can hand over the process of manually creating instances to spring To deal with it . The goal is to simplify development . therefore ,IOC It also provides IOC Container to store these instances .

IOC The main implementation of is DI Dependency injection ,Spring It helps our production objects 、 Management object 、 Manage dependencies between objects . Reduced code coupling 、 Easy to develop .

There are also several ways of dependency injection

1、 Create by constructor

2、 adopt set Method creation

3、 use p Namespace

4、 Use annotations :@Autowired/@Resource

AOP

AOP(Aspect Oriented Programming) be called Section oriented programming .

AOP It's a kind of programming idea , It can combine those with It's not business , But for Jointly called by business modules The logic of ( For example, transaction processing 、 Log management 、 Authority control, etc ) encapsulated , Reduce the repetitive code of the system , Reduce the coupling between modules , have Extensibility and Maintainability

AOP The principle of implementation is A dynamic proxy , There are two kinds of :JDK A dynamic proxy and CGLIB A dynamic proxy

Now realize AOP There are two main ways , One is Spring AOP, The other is AspectJ AOP, among Spring AOP It's integrated AspectJ, The difference between the two :AspectJ More powerful and better performance , but SpringAOP It's simpler ,

4.redis Five basic types of + Two advanced data types

Redis Support 5 Basic data types : character string (String), list (List), aggregate (set), Hash structure (hash), Ordered set (sorted set); There are also two data structures :HyperLogLog and BitMap.

(UV: Unique visitors to the site )(DAU: Daily active user )

HyperLogLogs What problems are cardinality statistics used to solve

This structure can save a lot of memory to count all kinds of counts , Such as registration IP Count 、 Visit... Daily IP Number of pages in real time UV、 Number of online users , Number of common friends, etc .

Bitmap Bit graph data structure , It's all operating bits to record , Only 0 and 1 Two states .

  • What problem to solve

such as : Statistics user information , active , Inactive ! Sign in , Not logged in ! Clock in , Don't punch in ! Two states of , You can use Bitmaps

How much memory is needed to store a year's punch in status ? 365 God = 365 bit 1 byte = 8bit 46 In bytes or so !

5. How do comments on comments come about

There are three ways to add comments :① Reply ,② Reply to comments ,③ Reply to sb.'s comments .

① stay discuss-detail Click the reply at the bottom of the page , Mapping to CommentController Layer of /add/{discussPostId}. Into entityType = 1 and entityId = post.id .
② Reply below the comment , And ① The mapping is the same , Pass in entityType = 2 and entityId = comment.id.
③ Reply to sb.'s comments , And ① The mapping is the same , Pass in entityType = 2 and entityId = comment.id and targetId.
The incoming comment Further settings userId,Status,CreateTime. And then call commentService.addComment(comment) Method to insert the database .
commentService.addComment Transaction annotations are used . The method is right comment Of content Transference HTML Mark and filter sensitive words . And then use commentMapper.insertComment Insert comments . And then through commentMapper.selectCountByEntity Query the number of comments on the post , Reuse discussPostService.updateCommentCount Method to insert the number of comments into the post details table .

[email protected] How to realize the function

7. The realization of like function

give the thumbs-up
Premise : stay util Of RedisKeyUtil Write in the tool class getEntityLikeKey Method , Pass in entityType, entityId Returns an entity ( Post or reply ) Yes yes key value .
Divided into two :① Like the post ② Like the response .

① Like the post content on the post details page , Button pass discuss.js take entityType=0 , post id:entityId and entityUserId adopt /like The mapping is passed to LikeController Layer. like Method .
like Method by calling likeService Layer of like Perform the like function , Then call... In turn findEntityLikeCount,findEntityLikeStatus Method to query the number of likes of the post , Query the like status of the currently logged in user .
likeService Layer of like Methods first, judge whether you have liked it , without , It's just Redis In this post key Corresponding set Add the likes of userId, And add one to the total number of likes of users of this post . If you like it, remove it UserId, And the total number of likes of users of this post is reduced by one .( Transactions are used here , Because two businesses need to be carried out at the same time )
Trigger Topic by TOPIC_LIKE Events : structure Event, Set the current login user id, Like the object type, Like the object id, The post of the liked object id( Because the likes may be posts or replies ), Users who are like objects id. And then call eventProducer take Event Publish to specified Topic.
Load the number and status of likes into map, adopt json String returns . Show... In the browser .
② Reply like on the post details page , Button pass discuss.js take entityType=1 and reply id:entityId and entityUserId adopt /like The mapping is passed to LikeController Layer. like Method .
notes : In addition to HomeController Layer /index Mapping method , Increase the function of returning the number of post likes to the browser . stay DiscussPostController Layer /detail/{discussPostId} Mapping method , Add the function of returning the number and status of likes in the post and reply list to the browser .

8. Is your project front end and back end separated ?

9. About Ajax

10. Common algorithms you encounter in competitions

1. Longest text substring (dp)

2. Traversal of binary tree ( Deep search + Guang Shu )

11. Do you have anything to ask ?

原网站

版权声明
本文为[csx_ zzh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270327461462.html