作者:古韵卡次 | 来源:互联网 | 2023-07-05 18:40
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
1 简单属性值注入
package com.xy.test1;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Service;@Service public class PropertiesService1 { @Value("${name:xydefault}") private String name; @Value("${num:-1}") private Integer num; @Value("${type:-2}") private Integer type; public void getInfo() { System.out.println("name:" + name + ",num:" + num + ",type:" + type); }}
#src/main/resource新建文件info.propertiesname=xy1num=101type=1
<context:component-scan base-package&#61;"com.xy.test1" /><bean class&#61;"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name&#61;"order" value&#61;"1" /> <property name&#61;"locations"> <list> <value>classpath:info/info.propertiesvalue> list> property>bean>
2 利用util标签注入复杂属性值package com.xy.test2;import java.util.List;import java.util.Map;import java.util.Properties;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Service;&#64;Servicepublic class PropertiesService2 { &#64;Value("#{testPro}") private Properties pros; &#64;Value("#{testList}") private List myList; &#64;Value("#{testMap}") private Map myMap; public Properties getPros() { return pros; } public void setPros(Properties pros) { this.pros &#61; pros; } public List getMyList() { return myList; } public void setMyList(List myList) { this.myList &#61; myList; } public Map getMyMap() { return myMap; } public void setMyMap(Map myMap) { this.myMap &#61; myMap; }}
#src/main/resource新建文件info2.propertiesname&#61;xy2num&#61;102type&#61;2
<context:component-scan base-package&#61;"com.xy.test2" /><util:properties id&#61;"testPro" location&#61;"classpath:info/info2.properties" /><util:list id&#61;"testList" list-class&#61;"java.util.ArrayList"> <value>firstvalue> <value>secondvalue> <value>thirdvalue>util:list><util:map id&#61;"testMap" map-class&#61;"java.util.HashMap"> <entry key&#61;"1" value&#61;"first" /> <entry key&#61;"2" value&#61;"second" /> <entry key&#61;"3" value&#61;"third" />util:map>
给我老师的人工智能教程打call&#xff01;http://blog.csdn.net/jiangjunshow