在mapper.xml
<select
id="finname"
parameterType="String"
resultType="java.util.Map"
statementType="STATEMENT">
select count(*) from ${codeName} where status='yes'
</select>
Mapper.java
public Map<String, String> finname(@Param("codeName") String codeName);
在Service
public Map<String, String> finname(String codeName) {
// TODO Auto-generated method stub
return userMapper.finname(codeName);
}
在controller
//动态调用表名
@RequestMapping("/finname")
public String findname(HttpSession session) {
String codeName="ccc";
Map<String, String> a=new HashMap<String, String>();
a=userService.finname(codeName);
System.out.println(a);
System.out.println(JSONObject.fromObject(a));
Object aString=JSONObject.fromObject(a).get("count(*)");
System.out.println(aString);
String bbString=String.valueOf(aString);
System.out.println(bbString);
session.setAttribute("aa", bbString);
session.getAttribute("aa");
System.out.println(session);
return "login";
}
在HTML上面显示
<%=session.getAttribute("aa")%>
运行出现的打印
可能会出现的问题
解决办法
在pom.xml上面加
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>