forked from staven630/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
512 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 不同作用域 Bean 的依赖配置 | ||
|
||
## 循环依赖 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
## 集合类型的依赖注入 | ||
|
||
### list 与 set | ||
|
||
  <list\>类型与<set\>的配置方式类似,使用子元素<value\>配置字符串等简单类型,使用子元素<ref\>的 Bean 属性配置其他 Bean 的依赖。 | ||
|
||
```xml | ||
<property name="myList"> | ||
<list> | ||
<value>value1</value> | ||
<value>value2</value> | ||
<ref bean="foo" /> | ||
</list> | ||
</property> | ||
``` | ||
|
||
### map | ||
|
||
  <map\>使用子元素<entry\>配置键值对的元素,属性 key 指定键的名称,value 配置对应的值,使用 value-ref 配置其他 Bean 的引用。 | ||
|
||
```xml | ||
<map> | ||
<entry key="key1" value="value1" /> | ||
<entry key="key2"> | ||
<value>value 2</value> | ||
</entry> | ||
<entry key="bean ref" value-ref="foo" /> | ||
</map> | ||
``` | ||
|
||
### props | ||
|
||
  <map\>对应的是 java.util.Properties 的对象,用来配置字符串类型的键和值的属性,可以看成是对<map>的简化。使用<prop>子元素的 key 指定键,子元素的内容为值。 | ||
|
||
```xml | ||
<props> | ||
<prop key="key1">value1</prop> | ||
<prop key="key2">value2</prop> | ||
</props> | ||
``` | ||
|
||
## 内部 Bean 的依赖注入 | ||
|
||
  ref 属性常用来引用外部 Bean。当引用的 Bean 只有当前 Bean 使用,可以以年内部 Bean 的方式注入。 | ||
|
||
  内部 Bean 是匿名的,不能独立访问,不需要指定 id 或 name 作为标识。直接在<bean\>配置的内部嵌套内部 Bean 配置。 | ||
|
||
```xml | ||
<bean id="outBean" class="com.staven.OutBeanClass"> | ||
<constructor-arg> | ||
<bean class="com.staven.InnerBeanClass"> | ||
<property name="name" value="inner" /> | ||
<!-- or --> | ||
<!-- <constructor-org name="name" value="inner" /> --> | ||
</bean> | ||
</constructor-arg> | ||
</bean> | ||
``` | ||
|
||
## Bean 方法的替换 | ||
|
||
  当第三方提供的类方法无法满足需求时,可以配置 Bean 的 replaced-method 元素来覆盖方法。 | ||
|
||
  通过新的类替换旧的类的方法: | ||
|
||
> OldBean | ||
```java | ||
public class OldBean { | ||
public String study(String name) { | ||
String str = ""; | ||
return str; | ||
} | ||
} | ||
``` | ||
|
||
  新的类需要实现 MethodReplacer 接口并重写 reimplement 方法: | ||
|
||
> NewBean | ||
```java | ||
public class NewBean implements MethodReplacer { | ||
@Override | ||
public Object reimplement(Object o, Method method, Object[] objects) throws Throwable { | ||
String inputParam = (String) objects[0]; | ||
String str = inputParam + ", new String= react"; | ||
return str; | ||
} | ||
} | ||
``` | ||
|
||
  Bean 配置如下; | ||
|
||
```xml | ||
<bean id="newBean" class="com.staven.NewBean"/> | ||
<bean id="oldBean" class="com.staven.OldBean"> | ||
<replaced-method name="study" replacer="newBean"> | ||
<arg-type>Spring</arg-type> | ||
</replaced-method> | ||
|
||
|
||
</bean> | ||
``` | ||
|
||
## 前置依赖注入 | ||
|
||
  假设 Bean A 和 Bean B,A 和 B 互不依赖,但是 B 的某些值的初始化又依赖于 A,这种关系叫前置依赖。Spring 中使用 depends-on 属性配置前置依赖。 | ||
|
||
```xml | ||
<bean id="beanB" class="com.staven.BeanBClass" depends-on="com.staven.BeanAClass" /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
  Spring 提供了自动装配的功能,可以在全局范围内设定,也可以对单个 Bean 进行个别设定。 | ||
|
||
## 全局设定 | ||
|
||
  在 beans 的根元素设置 default-autowire 的值可以开启整个应用中配置 Bean 的依赖自动注入,容器会根据 default-autowire 设置的匹配类型自动查找符合的 Bean 实例进行注入。 | ||
|
||
  default-autowire 属性可以设置为: | ||
|
||
- byName: 根据 Bean 的标识(id, name 和别名)查找 | ||
- byType: 根据 Bean 的 type 类型查找 | ||
- constructor: 根据构造器中的参数类型查找 | ||
|
||
```xml | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" | ||
default-autowire="byName"> | ||
|
||
<bean id="foo" class="com.staven.Foo" /> | ||
<bean id="bar" class="com.staven.Bar" /> | ||
|
||
</beans> | ||
``` | ||
|
||
  如果某一个 Bean 不作为依赖被其他 Bean 使用,可以添加 autowire-candidate 的属性值为 false。 | ||
|
||
## 个别设定 | ||
|
||
  不推荐全局设置,可以通过配置<bean\>的 autowire 属性来指定单个依赖的自动装配。 | ||
|
||
```xml | ||
<bean id="foo" class="com.staven.Foo" autowire="byName" /> | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
  [PointGraphics](https://staven630.github.io/cesium-doc-zh/PointGraphics.html)用来绘制点。 | ||
|
||
| 名称 | 类型 | 是否必填 | 默认值 | 描述 | | ||
| :----------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------- | :------------------- | ------------------------------------------------------- | | ||
| show | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| boolean | <可选> | true | 一个布尔属性,指定点的可见性。 | | ||
| pixelSize | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| number | <可选> | 1 | 以像素为单位指定大小的数字属性。 | | ||
| heightReference | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| [HeightReference](https://staven630.github.io/cesium-doc-zh/global.html#HeightReference) | <可选> | HeightReference.NONE | 一个属性,指定高度相对于什么。 | | ||
| color | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| [Color](https://staven630.github.io/cesium-doc-zh/Color.html) | <可选> | Color.WHITE | 指定 Color 点的属性。 | | ||
| outlineColor | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| [Color](https://staven630.github.io/cesium-doc-zh/Color.html) | <可选> | Color.BLACK | 指定 Color 轮廓的属性。 | | ||
| outlineWidth | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| number | <可选> | 0 | 一个数字属性,以像素为单位指定轮廓宽度。 | | ||
| scaleByDistance | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| [NearFarScalar](https://staven630.github.io/cesium-doc-zh/NearFarScalar.html) | <可选> | | 一个 NearFarScalar 属性用于扩展基于距离的点。 | | ||
| translucencyByDistance | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| [NearFarScalar](https://staven630.github.io/cesium-doc-zh/NearFarScalar.html) | <可选> | | 一个 NearFarScalar 属性用来设置半透明基于从相机的距离。 | | ||
| distanceDisplayCondition | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| [DistanceDisplayCondition](https://staven630.github.io/cesium-doc-zh/DistanceDisplayCondition.html) | <可选> | | 一个属性,指定该点将在距相机多远的距离处显示。 | | ||
| disableDepthTestDistance | [Property](https://staven630.github.io/cesium-doc-zh/Property.html) \| number | <可选> | | 一个属性,指定要禁用深度测试的距离相机的距离。 | | ||
|
||
```js | ||
viewer.entities.add({ | ||
// 此点的Cartesian3位置 | ||
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), | ||
point: { | ||
// 确定是否显示该点 | ||
show: true, | ||
|
||
// 获取或设置点的内部大小(以像素为单位) | ||
pixelSize: 10, | ||
|
||
// 选择点的ID | ||
id: "1", | ||
|
||
// 相对于地形的位置 | ||
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, | ||
|
||
// 获取或设置点的内部颜色 | ||
color: Cesium.Color.YELLOW, | ||
|
||
// 获取或设置点的轮廓颜色 | ||
outlineColor: Cesium.Color.BLUE, | ||
|
||
// 获取或设置以像素为单位的轮廓宽度 | ||
outlineWidth: 20, | ||
|
||
// 获取或设置基于点与摄影机的距离的点的近缩放和远缩放属性。 | ||
// 当相机距离pointPrimitive 1500米时,将pointPrimitive的scaleByDistance设置为缩放为15,当相机距离接近8.0e6米时消失。 | ||
scaleByDistance: new Cesium.NearFarScalar(1.5e2, 15, 8.0e6, 0.0), | ||
|
||
// 基于点与摄影机的距离获取或设置点的近半透明和远半透明属性。 | ||
// 当相机距点1500米时,将点的半透明度设置为1.0,当相机距离接近8.0e6米时,半透明度消失。 | ||
translucencyByDistance: new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.0), | ||
|
||
// 指定该点将在距相机多远的距离处显示 | ||
// 只有当距离相机在10到20米之间时才可见。 | ||
distanceDisplayCondition:new Cesium.DistanceDisplayCondition(10.0, 20.0); | ||
|
||
// 指定要禁用深度测试的距离相机的距离。 | ||
disableDepthTestDistance: false | ||
}, | ||
}); | ||
``` | ||
|
||
![img](../img/point.png) | ||
|
||
  可以动态改变 Point 的属性: | ||
|
||
```js | ||
const entity = viewer.entities.add({ | ||
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, 300000.0), | ||
point: { | ||
pixelSize: 2, | ||
}, | ||
}); | ||
|
||
const point = entity.point; | ||
point.pixelSize = 20.0; | ||
point.color = Cesium.Color.YELLOW.withAlpha(0.33); | ||
``` | ||
|
||
[Sandcastle Points](https://sandcastle.cesium.com/index.html?src=Points.html) |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Oops, something went wrong.