Configuration files are often used in projects, which are commonly defined as properties, and are typically configured in the spring configuration file for ease of use: Context:property-placeholder ignore-unresolvable = "true" Location = "Classpath*:/application.properties" />This allows you to directly fetch the value of the variable defined in the properties file by using @
Background
The spring development process often encounters the need to inject special values into member variables, such as normal values, files, URLs, configuration information, system variables, and so on. Spring mainly uses annotation @value to inject the corresponding value into the variable.Commonly used injection
Type of the return value of spring processing method, spring Processing Method
Spring mvc supports the following return methods: ModelAndView, Model, ModelMap, Map, View, String, void. The specific descriptions are as follows:
ModeAndView:
@RequestMapping("/show1") public ModelAndView show1(HttpServletRequest reque
One, the spring component overrides the constructor method, and reference @value in the constructor method is nullBecause the spring instantiation order is the first to execute the constructor method and then inject the member variable, the order is to execute the construction method first and then inject the member variable, so the ING instantiation
Spring MVC reads the configuration content of. properties through the @ Value annotation, @ value. properties
Step 1:
Configure in applicationContext. xml:
1
Step 2:
Create a configuration file:
Example: userPageSize = 5
Step 3:
Use annotations in the Controller to obtain the configuration item content:
1 @Value(
://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">4. Entity BeanPackage cn.itcast.springmvc.domain;public class User {private String name;Private String address;Private Integer age;Private String Tel;Public String GetName () {return name;}public void SetName (String name) {System.out.println ("The value of name is being injected by the SetName method:" + name);T
When using spring MVC, there are actually two spring containers:1,dispatcher-servlet.xml is a, our controller is right here, So this inside also needs to inject the attribute file Org.springframework.web.servlet.DispatcherServlet here is finally using webapplicationcontext parent = Webapplicationcontextutils.getwebapplicationcontext (Getservletcontext ()); Create a spri
Spring gets the value method of propertiesConfiguring in Spring.xmlOddly enough, the Context-param loaded spring.xml cannot use ${xxx}Must be handed over to Dispatcherservlet management springmvc.xml to use?To give Springmvc dispatcherservlet to scan, instead of Spring listener Contextloaderlistener to scan, it can be more convenient to use "${xxx" to inject.1. U
configuration file is to look at the P:bigornot property inside the oven, where we can compare two values by contrast to produce the final result.Test output:Midoven size:12.566370614359172Oven is not bigSmalloven size:10.0Oven is bigBigoven size:40.0Oven is bigWe just showed the part above, it has:> greater than Summary: In this chapter we discuss the value of the Spel values.Catalog: http://blog.csdn.net/raylee2007/article/details/50611627My github
Spring receives request parameters:
1, using HttpServletRequest to get Java code @RequestMapping ("/login.do") public String Login (HttpServletRequest request) {string name = Request.getpa Rameter ("name") String pass = Request.getparameter ("Pass")}
2,spring automatically injects form parameters into method parameters, and the Name property of the form remains the same. As with Struts2 Java code @RequestM
Example code:/** * If the barcode field value is NULL then do not process * If the barcode field value is not null before the original value of the Mosaic del:@param dealer @return * /@Modifying @Transactional @Query ("update Dealer D set "+ " D.deleteflag = 1, "+ " D.barcode = case when D.barcode was NULL then D
Package DemoImport Java.lang.reflect.Method;Import org.springframework.web.bind.annotation.RequestMapping;Import Com.demo.controller.TicketController;/*** Document Description: Get the value of requestmapping by reflection* Author: Zhao Peng* Time: 2016-10-8-09:04:53*/public class Test {/*** Method Description: Main method Test* Author: Zhao Peng* Time: 2016-10-8-09:04:53*/public static void Main (string[] args) {Get bytecode file "only need to change
The property values for a Java instance can have many data types, primitive type values, string types, Java instances, and even other bean instances, Java collections, arrays, and so on. So spring allows you to specify values for the properties of the bean instance through the following elements:ValueRefBeanlist, set, map, propsFirst, Value: Set normal property valuesThe 1 public class Valuetest {2 //de
In the use of spring boot, you can assign a value to a class by @configurationproperties and @Value two annotations, but two are used differently, and the following is an official description and an introduction to your own use.
1. According to their comparison, you can simply understand:
1 untie the set:
@ConfigurationProperties
Spring Get propertise the value in the fileThe way Spring acquires Propertise, in addition to the annotations injected using @value mentioned in the previous blog post, can also be obtained by means of encoding, which is mainly about using the Embeddedvalueresolveraware interface.First, prepare Propertise fileUnder the
Original link: http://blog.csdn.net/yunhaibin/article/details/9001198
Recent research into Redis, and spring data support for Redis, has found a strange phenomenonFirst say the phenomenon, through the redistemplate under the Opsforhash method to store the value of the hash type, after the successful operation, to the Redis console to display the keys *, found a strange phenomenon, the inserted hash typ
configure the scope of the bean:id= "role" class= "Spring.chapter2.maryGame.Role" scope= "Request"/> 4. SessionThe session scope indicates that a new bean will be generated for each HTTP request, and that the bean is valid only within the current HTTP session, configuration instance: configuration instance: As with the request configuration instance, the configuration of the Web boot file can be configured as follows:id= "role" class= "Spring.chapter2.maryGame.Role" Scope= "session"/> 5. Global
In front of the dependency injection, we are generally a property of injecting a bean reference into another bean or constructor parameter or setter parameter, which is about to associate an object with another object.Another aspect of bean assembly is the injection of a value into the bean's property or constructor parameter, which we can hard code in the configuration class, which is also hard-coded in the XML (all values are written out). 1, if yo
Spring AOP Gets the parameter name and parameter value of the Intercept method
Note: This approach requires JDK1.8 version support
Begin:
1.AOP configuration:
Note This configuration needs to be configured in the Spring MVC configuration file because the controller layer method needs to be intercepted
Or, in the case of a
Spring Read configuration file:1. Spring load config file: 2. configuration file Contents: ytz_special_user_phone=13912622596,18721293900,18656253360ytz_special_user_phone2= 13912622596,18721293900,186562533603. Inject the attribute value through spring.//Read the user name and phone number @
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.