package com.bbaqw.util;
import org.springframework.stereotype.Service;
/**
* @Component 是一个泛化的概念,仅仅表示一个组件 (Bean) ,可以作用在任何层次。
* @Service 通常作用在业务层,但是目前该功能与 @Component 相同。
* @Constroller 通常作用在控制层,但是目前该功能与 @Component 相同。
* 总结:通过在类上使用 @Repository、@Component、@Service 和 @Constroller 注解,
* Spring 会自动创建相应的 BeanDefinition 对象,并注册到 ApplicationContext 中。
* 这些类就成了 Spring 受管组件。这三个注解除了作用于不同软件层次的类,其使用方式与 @Repository 是完全相同的。
* 如果不加,不会被注册为bean,也无法使用
*/
@Service
public class PublicUtil {
public String getname(int id){
System.out.println("输出ID:"+id);
if(id==1){
return "北";
}else if(id==2){
return "清";
}else{
return "哈工";
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>FreeMarker3</title>
</head>
<body>
<h2>Test:${name}</2>
<#--assign指令的用法有多种,包含创建或替换一个顶层变量,或者创建或替换多个变量等-->
<#assign name=publicUtil.getname(1)>
<#if name=='北'>
北大学的编号
<#elseif name=='清'>
清大学编号
<#else>
哈工大编号
</#if><br/>
<#--if判断添加-->
<#if list??&&(list?size>=3)>
list集合长度大于或者等于三
<#else>
lisst集合长度小于三条
</#if><br/>
<#--if判断添加-->
<#if list??&&list?size!=0>
list集合长度大于或者等于三
<#else>
lisst集合长度小于三条
</#if><br/>
</body>
</html>
freemarker中字符串按照某个字符分割遍历展示:
<#list ckworks.tags?split(",") as tag>
<a href="javascript:;">${tag}</a>
</#list>