spring集成beetlsql

spring集成beetlsql

按以下流程操作
- pom配置
- spring注入配置
- 资源文件
- 测试


感谢闲大赋开发这么好用的组件
http://ibeetl.com/guide/#beetlsql


1.pom配置


  <beetl.version>2.5.2beetl.version>
  <beetlsql.version>2.6.5beetlsql.version>
        <dependency>
            <groupId>com.ibeetlgroupId>
            <artifactId>beetlartifactId>
            <version>${beetl.version}version>
        dependency>
        <dependency>
            <groupId>com.ibeetlgroupId>
            <artifactId>beetlsqlartifactId>
            <version>${beetlsql.version}version>
        dependency>

2.spring注入配置


    <bean id="sqlManager" class="org.beetl.sql.ext.spring4.SqlManagerFactoryBean">
        <property name="sqlLoader">
            <bean class="org.beetl.sql.core.ClasspathLoader">
            
                <property name="sqlRoot" value="/beetlsql">property>
            bean>
        property>
        <property name="nc">
            <bean class="org.beetl.sql.core.DefaultNameConversion">bean>
        property>
        <property name="interceptors">
            <list>
                <bean class="org.beetl.sql.ext.DebugInterceptor">bean>
            list>
        property>
        <property name="cs">
            <bean class="org.beetl.sql.ext.spring4.BeetlSqlDataSource">
                <property name="masterSource" ref="dataSource">property>
            bean>
        property>
        <property name="dbStyle">
            <bean class="org.beetl.sql.core.db.OracleStyle">bean>
        property>
        <property name="configLocation" value="classpath:beetlsql.properties">property>
    bean>

3.资源文件


3.1 beetlsql.properties

ENGINE=org.beetl.sql.core.engine.SQLTemplateEngine
DELIMITER_PLACEHOLDER_START=#{
DELIMITER_PLACEHOLDER_END=}
DELIMITER_STATEMENT_START=@
DELIMITER_STATEMENT_END=
HTML_TAG_SUPPORT = false
CHARSET=
FN.use = org.beetl.sql.core.engine.UseFunction
FN.globalUse = org.beetl.sql.core.engine.GlobalUseFunction
FN.text = org.beetl.sql.core.engine.TextFunction
FN.join = org.beetl.sql.ext.JoinFunction
FN.isEmpty=org.beetl.sql.ext.EmptyExpressionFunction
FN.page=org.beetl.sql.core.engine.PageQueryFuntion
FN.orm.many=org.beetl.sql.core.orm.ORMManyEntityFunction
FN.orm.single=org.beetl.sql.core.orm.ORMSingleEntityFunction
TAG.trim= org.beetl.sql.core.engine.TrimTag
TAG.pageTag= org.beetl.sql.core.engine.PageQueryTag
ERROR_HANDLER = org.beetl.sql.core.engine.BeetlSQLTemplateExceptionHandler
PRODUCT_MODE = false
OFFSET_START_ZERO = false 

3.2 asd.md(beetlsql md文件)

list
===
select * from tb_ds where id=#{id}

4.测试


@Controller
@RequestMapping("/mobile")
public class beetlsqlController extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(MobileController.class);

    @Autowired
     SQLManager sqlManager;

     @RequestMapping(value="/aa")
     public void aa(){
         Map paras=new HashMap();
         paras.put("id", "12");
         LOGGER.info("list.toString():"+ paras.keySet());
         List list = sqlManager.select("ads.list", Map.class, paras);
         LOGGER.info("list.toString():"+list.toString());
     }
}

测试通过

你可能感兴趣的:(技术杂谈)