我正在编写从字符串映射构建UserProfile对象的代码.目前我正在将代码划分为几个构建用户配置文件部分的Builder对象,如下所示:
public UserProfile getUserProfile(int id) {
Map<String, String> data = this.service.getUserProfileData(int id);
UserProfile profile = userProfileBuilder.build(data);
profile.setMarketingPreferences( marketingPreferencesBuilder.build(data) );
profile.setAddress( addressBuilder.build(data) );
...
return profile;
}
Run Code Online (Sandbox Code Playgroud)
能够拥有一个构建器对象列表是很好的,这样我就可以动态添加其他构建器而无需触及类并打破OCP.
也许是这样的,相反:
private List<ProfileBuilder> builders;
public void buildBuilders() {
this.builders = new ArrayList<ProfileBuilder>();
builders.add( new BasicDetailsBuilder() );
builders.add( new AddressBuilder() );
builders.add( new MarkettingPreferencesBuilder() );
...
}
public UserProfile getUserProfile(int id) {
Map<String, String> data = this.service.getUserProfileData(int id);
UserProfile profile = new UserProfile();
for(ProfileBuilder builder : this.builders) { …Run Code Online (Sandbox Code Playgroud) 注意:我使用的是Maven 3.2.2,Eclipse Luna
这是我使用Android AAR存档的pom.xml中的依赖项
<dependency>
<groupId>com.github.gabrielemariotti.cards</groupId>
<artifactId>library</artifactId>
<version>1.7.3</version>
<type>aar</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我可以在target/classes文件夹中看到安装的类.
但是当我尝试使用AAR中的类时,Eclipse显示的类无法解析.我在pom.xml中使用由JAR依赖项添加的类没有问题
任何帮助将不胜感激.
嘿,我是JavaScript的新手,我喜欢MyClass.class和MyClass.methodsRuby,在JavaScript中是否有任何等价来检查可用的对象类型和方法?
BTW typeof操作员似乎总是回来'object',我不知道为什么.
我目前正在将我的项目从Google Code迁移到Github.当我最初创建我的项目时,我使用com.googlecode.*作为我的包名.现在我转移到Github,所以将我的包切换到com.github.*似乎是合适的.
然而,其他人已经向我指出,每次移动托管平台时都必须更改我的软件包(考虑到所有最近的托管时尚,这可能会发生很大变化)可能是个问题.他们建议我应该使用自己的域名,但我对这种方法持怀疑态度:域名可能会过期,维护域名的开销虽然不是很大,但也不是最小的.
以下方法的优缺点是什么:
即使域名包命名约定只是一个约定,我知道中央Maven存储库不允许您在域名包下上传,除非您可以证明您已注册DNS条目,因此这很重要.
我正在尝试使用Spring @Secured注释和AspectJ自动代理来使用我的Spring MVC应用程序,但它似乎没有代理或识别我的@Secured注释.我有一个像这样的控制器:
@Controller
@RequestMapping("/")
public class ApplicationController {
private ApplicationFactory applicationFactory;
@Inject
public ApplicationController(ApplicationFactory applicationFactory) {
super();
this.applicationFactory = applicationFactory;
}
@Secured("ROLE_USER")
@ResponseBody
@RequestMapping(method = GET)
public Application getApplicationInfo() {
return applicationFactory.buildApplication(this);
}
}
Run Code Online (Sandbox Code Playgroud)
一个Spring安全XML看起来像这样:
码:
<security:global-method-security secured-annotations="enabled" mode="aspectj" proxy-target-class="true" />
<security:http auto-config="true" use-expressions="true">
<security:http-basic/>
</security:http>
Run Code Online (Sandbox Code Playgroud)
上面是由no-xml Spring @Configuration组件加载的,如下所示:
@Configuration
@ComponentScan(basePackages = {"com.example"})
@EnableWebMvc
@ImportResource("classpath:security.xml")
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
}
Run Code Online (Sandbox Code Playgroud)
反过来使用Servlet 3.0 WebApplicationInitializer加载:
public class SpringMvcInitializer implements WebApplicationInitializer {
private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
public …Run Code Online (Sandbox Code Playgroud)