Latest article

Java design patterns – decorator design pattern (structural design pattern)

Original address: yxlaisj/p/10446504.html Decorator Pattern In fact, the IO-related tools in the toolkit provided by Java generally use the decorator pattern. ,For example, IO classes that serve as decoration functions such as BufferedInputStream, etc.,Also known as advanced streams,Usually the basic stream is passed in as a parameter of the advanced stream constructor,As an advanced stream An associated object to extend and decorate its functions. Decorator Pattern,Dynamicly add some additional responsibilities to an object,In terms of adding functionality,Decorator Pattern More flexible than subclassing. —-“Dahua Design Pattern” The decorator pattern uses hierarchical objects to dynamically and transparently add responsibilities to a single object. The following is the UML class diagram of the decorator pattern: The decorator implements the decoration object(Component) The interface to which all requests are forwarded for processing adds extra functionality before/after forwarding requests. The steps to use are: Use a Decorator to implement/inherit the object Component that needs to be modified; Add a reference to the Component in the Decorator; In the Decorator In the constructor, add a Component parameter to initialize the Component; In the Decorator class, use the reference to the Component to forward all requests to the corresponding method of the Component. ; All Override self-Component…

Java dynamically adds attributes to entity classes

Java dynamically adds attributes to entity classes There are two required jar packages: cglib-3.1.jar and google-collections-1.0.jar If it is a maven project, there is no need for cglib-3.1.jar, just use the one that comes with spring org. springframework.cglibis enough. 1. Create an entity: DynamicBean public class DynamicBean { private Object target; private BeanMap beanMap; public DynamicBean(Class superclass, Map< String, Class> propertyMap) { this .target = generateBean(superclass, propertyMap ); this.beanMap = BeanMap. create(; } public void setValue(String property , Object value) { beanMap.put(property, value); } public Object getValue(String property) { return beanMap. get(property); } public Object getTarget() { return; } /** * According to Property generation object* */ private Object generateBean(Class superclass , Map<String, Class> propertyMap) { BeanGenerator generator = new BeanGenerator(); if (null != superclass) { generator.setSuperclass(superclass); } BeanGenerator.addProperties(generator, propertyMap); return generator.create(); }} 2. Create a mapping class to generate dynamic beans public class ReflectUtil { private static Logger logger = LoggerFactory.getLogger(ReflectUtil.class); public static Object getObject(Object dest, Map< String, Object> addProperties) { PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); PropertyDescriptor [] descriptors = propertyUtilsBean.getPropertyDescriptors( dest); Map<String, Class> propertyMap = Maps.newHashMap(); for (PropertyDescriptor d : descriptors) { if (!”class”.equalsIgnoreCase(d.getName())) { propertyMap.put(d .getName(), d.getPropertyType ()); } } addProperties.forEach((k, v) -> { String sclass…

java WeChat graphic messages_Java WeChat public platform development (5) Implementation of text and graphic message replies

In the previous article, we mentioned that replying to messages can be divided into [ordinary messages] and [multimedia messages] depending on whether files need to be uploaded to the WeChat server. Here we will talk about the implementation of replying to ordinary messages. There is a key field [openid] in the reply. It is the unique identification of the public account for WeChat users. I won’t explain too much here. I will give time to explain the keywords in the WeChat ecosystem later. xff01; (1) Reply to text message Previously we have completed the classification of messages and the establishment of reply message entities,Here we need to reply to text messages It is our TextMessage. We reply text messages in the [Text Message] type. When we reply to a message, we need to set the recipient of the message ToUserName (openid), the sender of the message FromUserName, Message type MsgType, creation time CreateTime and message body Content. Since our message reply format needs to be xml, we ultimately need to convert it into xml before returning the output. First, we made some modifications and additions to the code of the tool class MessageUtil, and the final version was implemented as…

Technical picture

How to set a shortcut key for the set or get method of a property in Java

The specific steps are as follows: On the homepage, define properties in the class, for example: public Sting name; Secondly, Alt+Shift+S, select Generate Getters and Setter…This item, then as shown in the picture   You can get it public String getName() { return name; } public void setName(String name) { = name; } The following is a demo public class testApp { public String name; public int age; public String address; public String getName() { System.out.println(“My name:”+name) ; return name; } public void setName(String name) { = name; } public int getAge() { System.out.println(“My age: “+age) ; returnage; } public void setAge(intage) { this.age =age; } public String getAddress() { System.out.println(“My address:”+address) ; returnaddress; } public void setAddress(String address) { this.address =address; } @Test //Test public void adad() { System.out.println(“\n==Time information===========”); testApp a = new testApp(); this.setName(“Zhang San”);//Assignment this.setAge(10); this.setAddress(“Zhengzhou·Henan”); this.getAddress();//Get the value this.getName(); this.getAge(); } }   How to set the shortcut key for the set or get method of a property in Java

Is system a keyword? A keyword in Java language

In Eclipse, when we enter certain words, these words will automatically change color. These are Java keywords. Of course, there are exceptions: Although const and goto also change colors, they will report errors. These two words are called reserved words of Java. In addition to these two reserved words, Java has 51 keywords. The first is the basic data type: int defines an integer variable short defines a short integer variable long defines a long integer variable byte defines a byte variable float defines a single-precision character variable double defines a double-precision floating-point variable boolean defines a Boolean variable p> char defines character variables Additional return value is empty: void Then there is a loop structure: while do…while if else for continue break selection structure: 1. switch Access modifier: public default protected private Related to package: package import Related to class: class: definition of class extends: inheritance of class interface: definition of interface implements: inheritance of interface abstract: definition of abstract class final: attributes or methods modified with final Neither can be inherited super: this: static: return: new: instance Object Volatile: used to represent member variables that can be modified asynchronously by multiple threads. Related to exceptions: try catch…

java-captcha implements verification code (2)

captcha implements verification code to verify user login and prevent passwords from being violently cracked. The following is run in the Springmvc framework. Friendly links: (implementation of verification code and QR code) Imported jar package: kaptcha-2.3.2.jar Download address: Or in maven —pom.xml: configure as follows kaptcha2.3.2 Web.xml configuration kaptcha kaptcha /kaptcha.jpg springmvc.xml configuration (captchaProducer is equivalent to a class, and users have modified its properties according to their own requirements) yes 105,179,90 blue 125 45 45 code 4 Song, Kai, Microsoft Yahei parsing class (used to parse beans in springmvc.xml) package com.authc.utils; import org.springframework.context.ApplicationContext; import; /** * @author lyx * *2015-8-18 3:53:19 pm * *com.utils.SpringUtil *TODO */ public class SpringUtil { private static ApplicationContext ctx =new ClassPathXmlApplicationContext(“springmvc.xml”); public static Object getBean(String beanId) { return ctx.getBean(beanId); } } UserController control layer class @Controller @RequestMapping(“/member”) public class UserController { private Producer captchaProducer; @RequestMapping(value = “captcha-image”) public ModelAndView getKaptchaImage(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); //Get the captchaProducer Bean in springmvc.xml captchaProducer = (Producer) SpringUtil.getBean(“captchaProducer”); String code = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY); System.out.println(“Verification code generated by the system: ” + code ); response.setDateHeader(“Expires”, 0); response.setHeader(“Cache-Control”, “no-store, no-cache, must-revalidate”); response.addHeader(“Cache-Control”, “post-check=0, pre-check=0”); response.setHeader(“Pragma”, “no-cache”); response.setContentType(“image/jpeg”); String capText…

Java daily exercises, make a little progress every day (53)_java

Catalogue 1. In Java, no matter where it is called, static attributes must be prefixed with the class name. 2. If there is a definition statement: int a=10; double b=3.14; then the value type of the expression ‘A’+a+b is () 3. The correct statement about the SSH MVC development model is ( ) 4. Which of the following statements about garbage collection is correct 5. Which of the following statements is correct: 6. Among the structural patterns, the most extensible pattern is () 7. What can we use when we need all threads to execute to a certain place before executing subsequent code? 8. Suppose a is a global variable with an initial value of 0 shared by thread 1 and thread 2. Then thread 1 and thread 2 execute the following code at the same time, and finally a 9. Which of the following stream classes does not belong to the character-oriented stream () 10. What is the result of running the following JAVA program ( ) Answer summary: Summary Thanks to your love, let’s make a little progress together every day! (Click the blank space with your mouse to view the answer) 1. In Java, no matter where…

es6 deep copy_understand javascript deep copy and shallow copy in one article

(Add a star to the front-end encyclopedia , Improve front-end skills) Author:Front-end Craftsman Official Account/ Langlixingzhoujun (This article is from the author’s contribution) Preface There are different ways to copy objects in Javascript ,if you are not familiar with the language yet&# xff0c;It is easy to fall into the trap when copying objects,So how can we copy an object correctly? After reading this article,Hope you can understand, #xff1a; What is deep/shallow copy,How are they different from assignment? There are several ways to implement deep/shallow copy ? Shallow copy and deep copy Shallow copy creates a new object&#xff0c ;This object has an exact copy of the original object’s property values. If the attribute is a basic type, the value copied is the value of the basic type. If the attribute is a reference type, the memory address is copied. So if one of the objects changes this address ,It will affect another object. Deep copy is to completely copy an object from the memory, open up a new area from the heap memory to store the new object, and modify the new object Does not affect the original object. var a1 = {b: {c: {}};var a2 = shallowClone(a1); // Shallow copy…

Java8 | Consumer interface in Java with examples

Java 8 | Consumer Interface in Java with Examples Original text: https://www . geesforgeks . org/Java-8-Consumer-Interface-Example/ The consumer interface is part of the java.util.function package, which was introduced starting with java 8 for Implement functional programming in Java. It represents a function that accepts one parameter and produces a result. However, such functions do not return a value. Therefore, this functional interface adopts a common name, namely:- T: Indicates the type of input parameters of the operation A lambda expression assigned to an object of type Consumer is used to define its accept() which ultimately applies the given operation to its argument. Consumers are useful when there is no need to return any value, as they are expected to operate via side effects. Functions in the consumer interface The consumer interface consists of the following two functions: 1. Accept() This The method accepts a value and performs operations on the given parametersSyntax: void accept(T t) Parameters:This method takes one parameter: t–Input parameters Return:This method does not return value. The following is the code that illustrates the accept() method:Program 1: Java language (a computer language, especially used for creating websites) // Java Program to demonstrate// Consumer’s accept () methodimport java.util.ArrayList;import java.util.LinkedList;import…

The secret of recursive algorithm (java)

Article Table of Contents 1. Recursive Algorithm 1. Algorithm Overview 1.1 Algorithm Essence 1.2 Algorithmic Thoughts 2. Give an algorithm example 2.1 Question 2.2 Solution 2.3 Summary 1. Recursive algorithm 1. Algorithm overview Recursive algorithm is a function that calls itself directly or indirectly Or the algorithm of the method. To put it simply, it is the call of the program itself. 1.1 The essence of the algorithm The recursive algorithm is to continuously decompose the original problem into smaller sub-problems, and then recursively call methods to express Solution to the problem. (Use the same method to solve problems of different scales) 1.2 Algorithm ideas Recursive algorithm, As the name suggests, there are two major The stages of “recursion and return” are that there is going, “passing away”, and there is “return”. Decompose the recursive problem into several smaller sub-problems with the same form as the original problem. These sub-problems can Use the same problem-solving ideas to solveReturn:When you continue to reduce the size of the problem and pass it on,There must be a clear critical point to end the pass(Recursive exit& #xff09;,Once this critical point is reached, return from that point to the original point,Finally the problem is solved.…

Contact Us

Contact us


Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top