si用例

context-datasource,

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="globalDataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="org.gjt.mm.mysql.Driver" />
        <property name="url" value="jdbc:mysql://IP:端口/数据库名?autoReconnection=true" />
        <property name="username" value="******" />
        <property name="password" value="******" />
        <property name="initialSize" value="5" />
<!--         <property name="minIdle" value="1" /> -->
        <property name="maxIdle" value="2" />
        <property name="maxActive" value="5" />
        <property name="maxWait" value="6000" />
        <property name="testOnBorrow" value="true" />
        <property name="testOnReturn" value="true" />
        <property name="validationQuery" value="select 1 from dual" />
    </bean>
</beans>
sqlmap-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
    <settings enhancementEnabled="true" useStatementNamespaces="true"/>
    <sqlMap resource="***/ibatis query的文件名.xml"/>
    ......    
</sqlMapConfig>
context-ibatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

	<bean name="sqlMapClient"
		class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:/spring/sqlmap-config.xml" />
	</bean>

	<bean name="webFrontMapClient"
		class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource" ref="globalDataSource" />
		<property name="configLocation" value="classpath:/spring/sqlmap-config.xml" />
	</bean>
</beans>


@Controller
@RequestMapping("/TestService")
public class TestService {
    @Resource
    public SQLDBService service;

    @RequestMapping(value = "/get***ByName.do", method = RequestMethod.POST)
    @ResponseBody
    public String getVideoByName(@RequestBody String para) throws Exception {
        return service.get***ByName(paras);
    }
    ......
}


public interface SQLDBService {
    public List<Video> get***ByName(HashMap<String, Object> inputParams);
}


@Service
public class SQLDBImpl implements SQLDBService {    
    @Resource
    private SQLDBDAO sqlDBDao;
    @Override
    public List<Video> get***ByName(HashMap<String, Object> inputParams) {
        return sqlDBDao.get***ByName(inputParams);    
    }
}


@Repository
public class SQLDBDAO extends SqlMapClientDaoSupport {
    @Resource(name="webFrontMapClient")    
    protected void initDAO(SqlMapClient sqlMapClient) {
        this.setSqlMapClient(sqlMapClient);
    }

    public List<Video> get***ByName(HashMap<String, Object> inputParams) {
        SqlMapClientTemplate sql = getSqlMapClientTemplate();
        return (List<Video>)sql.queryForList("WebResourceSearch.get***ByName", inputParams);
    }
}


Video.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="WebResourceSearch">
    <typeAlias alias="video" type="对应class的路径"/>
     <resultMap id="videoInfo" class="video">
        <result property="id" column="id"/>
        ........
    </resultMap>
    
    <select id="get***ByName" parameterClass="java.util.HashMap" resultClass="video">
            select *******
            from test
            left join ******
            left join ******
        <isEqual property="accurate" compareValue="AccurateName" prepend=" where ">
            test.*** = #name#
        </isEqual>
        <isEqual property="accurate" compareValue="" prepend=" where ">
            test.title like '$name$%'
        </isEqual>
        <isEqual property="accurate" compareValue="Accurate" prepend=" where ">
            test.id = #id#
        </isEqual>
            group by ***
            order by ***
        <isNotEmpty property="limitNum">
            limit $limitNum$    
        </isNotEmpty>
    </select>
</sqlMap>    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值