1 首先在dao层 写一个增删改查的接口 SqlAdapterMapper
public interface SqlAdapterMapper {
List<Map<String, Object>> selectSQL(String sql);
int updateSQL(String sql);
int deleteSQL(String sql);
int insertSQL(String sql);
}
2 在配置文件中 新建SqlAdapterMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.rf.sys.dao.SqlAdapterMapper" >
<select id="selectSQL" parameterType="String" resultType="hashmap">
${value}
</select>
<insert id="insertSQL" parameterType="String" >
${value}
</insert>
<update id="updateSQL" parameterType="String" >
${value}
</update>
<delete id="deleteSQL" parameterType="String" >
${value}
</delete>
</mapper>
3 在services 层 直接拼写sql语句 然后 然后 传入到 SqlAdapterMapper 中对应的方法 中去执行。
private Map<String, Object> geDetial(String detial){
StringBuffer sql=new StringBuffer("select t.* from BUS_SCREEN t where t.code='"+detial+"'");
List<Map<String, Object>> list=sqlAdapterMapper.selectSQL(sql.toString());
if(list!=null&&list.size()>0){
return list.get(0);
}else{
return null;
}
}