spring-boot

freemarker循环、日期格式化、常用汇总

星期六, 八月 15th, 2020 | JAVA-and-J2EE, spring-boot | 2 Comments

首先权威地址官方地址:https://freemarker.apache.org/

中文版使用手册地址:http://freemarker.foofun.cn/toc.html

1.日期格式及解决日期为NULL报错的写法

${(user.birthday?string("yyyy-MM-dd"))!}
 
//--或者--
${(user.birthday?string("yyyy-MM-dd"))!'--'}

2.判断对象是否存在再进行操作

<#if user?? >「${user.name }<#else></#if>

3.循环及计数使用

<#list listUser as user>
	<#if user?? >「${user.name }<#else></#if>
	<#if user?counter gt 3 >
	 ${user.email}
	</#if>
</#if>

Tags:

Spring Boot 的核心注解SpringBootApplication引起的探究

星期二, 十二月 3rd, 2019 | JAVA-and-J2EE, spring-boot | 没有评论

Spring Boot 的核心注解SpringBootApplication引起的探究

1.Spring Boot 的核心注解是哪个?

先上一个工程的启动配置项看下:

项目比较老混杂了spring boot,dubbo,jersey注册等

	package com.pomelolee.cms;
 
	import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
	import com.pomelolee.boot.dubbo.annotation.EnableDubboProvider;
	import org.glassfish.jersey.server.ResourceConfig;
	import org.glassfish.jersey.servlet.ServletProperties;
	import org.springframework.beans.factory.config.BeanDefinition;
	import org.springframework.boot.SpringApplication;
	import org.springframework.boot.autoconfigure.SpringBootApplication;
	import org.springframework.boot.builder.SpringApplicationBuilder;
	import org.springframework.boot.web.support.SpringBootServletInitializer;
	import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
	import org.springframework.cloud.netflix.feign.EnableFeignClients;
	import org.springframework.context.annotation.Bean;
	import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
	import org.springframework.context.annotation.ImportResource;
	import org.springframework.util.ClassUtils;
 
	import java.util.HashSet;
	import java.util.Set;
 
	@EnableFeignClients
	@SpringBootApplication
	@EnableApolloConfig
	@EnableDiscoveryClient
	@EnableDubboProvider
	@ImportResource("classpath*:/META-INF/spring/spring-job.xml")
	public class Application extends SpringBootServletInitializer {
	  public static void main(String[] args) {
	    SpringApplication.run(Application.class, args);
	  }
 
	  @Override
	  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
	    return application.sources(Application.class);
	  }
 
	  @Bean
	  public ResourceConfig resourceConfig() {
	    ResourceConfig resourceConfig = new ResourceConfig();
	    ClassPathScanningCandidateComponentProvider scanner =
	        new ClassPathScanningCandidateComponentProvider(true);
	    Set<beandefinition> beanDefinitionSet =
	        scanner.findCandidateComponents("com.pomelolee.cms.service");
	    beanDefinitionSet.addAll(scanner.findCandidateComponents("com.pomelolee.cms.facade"));
	    beanDefinitionSet.addAll(scanner.findCandidateComponents("com.pomelolee.cms.config"));
	    Set<Class<?>> clazzSet = new HashSet<Class<?>>();
	    for (BeanDefinition beanDefinition : beanDefinitionSet) {
	      clazzSet.add(
	          ClassUtils.resolveClassName(
	              beanDefinition.getBeanClassName(), resourceConfig.getClassLoader()));
	    }
	    resourceConfig.registerClasses(clazzSet);
	    resourceConfig.property(ServletProperties.FILTER_FORWARD_ON_404, true);
	    return resourceConfig;
	  }
	}
 </beandefinition>

@SpringBootApplication 注解,就是 Spring Boot 的核心注解。

› Continue reading

Tags: ,

Search

文章分类

Links

Meta