Thymeleaf模板页面直接调用后台service层的方法

service层

1
2
3
public interface TestService {
List<String> getTestDictList();
}

service层实现类

1
2
3
4
5
6
7
8
9
10
@Service("test")
public class TestServiceImpl implements TestService {
@Override
public List<String> getTestDictList() {
return new ChainArrayList<String>()
.chainAdd("学校")
.chainAdd("姓名")
.chainAdd("班级");
}
}

thymeleaf的Html

1
2
3
4
<select th:with="options=${@test.getTestDictList()}">
<option>所有</option>
<option th:each="option:${options}" th:text="${option}"></option>
</select>