Use leopard jdbc to learn how to use leopard jdbc.
This guide will guide you through the operation of MySQL using leopard jdbc.
How to complete the This guide
You can start from scratch and complete each step, or you can bypass the basic setup steps you're already familiar with. Either way, you can end up with working code.
1. Configure MAVEN Dependencies
In the DAO module, Pom.xml joins
<dependencies> [...] <dependency> <groupId>io.leopard</groupId> <artifactid>leopard-data</ artifactid> <version>0.0.1-SNAPSHOT</version> </dependency> [...] </dependencies> <repositories> <repository> <id>leopard-snapshots</id > <name>leopard snapshots</name> <url>http://leopard.io/nexus/content/ repositories/snapshots/</url> </repository> </repositories>
2. Configure Spring
site-dao/src/main/resources/applicationContext-dao.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" xmlns:leopard= "Http://www.leopard.io/schema/leopard" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsdhttp://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd "><leopard: Component-scan base-package= "Io.leopard.site"/><leopard:jdbc id= "jdbc" host= "112.126.75.27" database= " Example "user=" Example "password=" Leopard "/><leopard:redis id=" Redis "server=" 112.126.75.27:6311 "/></ Beans>
3. Using the JDBC interface
Createsite-dao/src/main/java/io/leopard/site/dao/mysql/UserDaoMyqlImpl.java
Package Io.leopard.site.dao.mysql;import Io.leopard.data4j.jdbc.jdbc;import Io.leopard.data4j.jdbc.builder.insertbuilder;import Io.leopard.site.model.user;import Javax.annotation.Resource; Import org.springframework.stereotype.Repository; @Repositorypublic class Userdaomyqlimpl {@Resourceprivate jdbc jdbc ;p ublic boolean Add (user user) {Insertbuilder builder = new Insertbuilder ("User"), Builder.setlong ("UID", User.getuid ()) ; Builder.setstring ("Passport", User.getpassport ()), Builder.setstring ("nickname", User.getnickname ()); Builder.setdate ("Posttime", User.getposttime ()); return This.jdbc.insertForBoolean (builder); Public User get (long uid) {String sql = ' SELECT * from User where uid=? '; return this.jdbc.query (SQL, user.class);} Public boolean Delete (long uid) {String sql = ' Delete from user where uid=? '; return This.jdbc.updateForBoolean (SQL, UID);}}
Summarize
Congratulations to you! You can already use Leopard Jdbc in your old project configuration, although the functionality is relatively simple, you can expand your business system on this basis and wish you good luck.
Using leopard Jdbc