文档章节

MyBatisGenerator工具生成的类与XML对Oracle数据库模糊查询的支持

北风其凉
 北风其凉
发布于 2016/06/15 00:17
字数 2516
阅读 357
收藏 4
点赞 1
评论 0

MyBatis Generator 工具可以用来生成一些工具类和XML模板,用于为用户使用Java语言访问数据库提供便利。

我使用的数据库版本为Oracle11g,JDK版本为1.8。

建表语句如下:

CREATE TABLE PERSON_INFO
(
    ID NUMBER(12, 0) PRIMARY KEY,
    NAME VARCHAR(50),
    COMPANY VARCHAR(200)
);

INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (1, 'Tsybius', 'Dog Head Inc');
INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (2, 'Galatea', 'Dog Head Inc');
INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (3, 'Quintus', 'Dog Head Inc');
INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (4, 'Gaius', 'State Grid Corporation of Mars');
INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (5, 'Titus', 'Tyrannosaurus Company Limited');
INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (6, 'Test1', 'Dog Head%');
INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (7, 'Test2', 'Dog Head%Test');
INSERT INTO PERSON_INFO (ID, NAME, COMPANY) VALUES (8, 'Test3', 'Test%Dog Head%Test');

COMMIT;
/

如果我们要在这个表中查询所有COMPANY字段包含“Head%”的数据,可以使用下面的SQL:

SELECT *
FROM   PERSON_INFO
WHERE  COMPANY LIKE '%Dog Head/%%' ESCAPE '/'
ORDER  BY ID ASC

查询结果如下:

我们使用 MyBatis Generator 工具生成四个文件:

1、PersonInfoMapper.java

2、PersonInfoMapper.xml

3、PersonInfo.java

4、PersonInfoExample.java

生成方法可参考下面两篇博客:

1、http://my.oschina.net/Tsybius2014/blog/676973

2、http://my.oschina.net/Tsybius2014/blog/678840

PersonInfoExample类中会生成andNameLike、andNameNotLike、andCompanyLike、andCompanyNotLike四个函数,但这四个函数并不能满足我们上面例子中的要求:一是传入的value必须左右手工添加百分号,二是这样传入的value不能支持查询“%”和“_”两个通配符(即oracle中的escape关键字)

为了支持在模糊查询时可以准确查询出通配符“_”和“%”,需要对PersonInfoExample.java和PersonInfoMapper.xml进行修改。

1、对PersonInfoExample.java的改动

修改的部分都用“【新加入的代码】”做了标记,改动的地方包括:

1)对所有Like和NotLike函数都做了改造

2)新加了一个布尔型的变量escapeValue,用于标记Like和NotLike需要转义

3)为Criterion类新加了一个构造函数,用于为Like和NotLike两类条件创建Criterion

package GenTarget.object_example_java;

import java.util.ArrayList;
import java.util.List;

public class PersonInfoExample {
    protected String orderByClause;

    protected boolean distinct;

    protected List<Criteria> oredCriteria;

    public PersonInfoExample() {
        oredCriteria = new ArrayList<Criteria>();
    }

    public void setOrderByClause(String orderByClause) {
        this.orderByClause = orderByClause;
    }

    public String getOrderByClause() {
        return orderByClause;
    }

    public void setDistinct(boolean distinct) {
        this.distinct = distinct;
    }

    public boolean isDistinct() {
        return distinct;
    }

    public List<Criteria> getOredCriteria() {
        return oredCriteria;
    }

    public void or(Criteria criteria) {
        oredCriteria.add(criteria);
    }

    public Criteria or() {
        Criteria criteria = createCriteriaInternal();
        oredCriteria.add(criteria);
        return criteria;
    }

    public Criteria createCriteria() {
        Criteria criteria = createCriteriaInternal();
        if (oredCriteria.size() == 0) {
            oredCriteria.add(criteria);
        }
        return criteria;
    }

    protected Criteria createCriteriaInternal() {
        Criteria criteria = new Criteria();
        return criteria;
    }

    public void clear() {
        oredCriteria.clear();
        orderByClause = null;
        distinct = false;
    }

    protected abstract static class GeneratedCriteria {
        protected List<Criterion> criteria;

        protected GeneratedCriteria() {
            super();
            criteria = new ArrayList<Criterion>();
        }

        public boolean isValid() {
            return criteria.size() > 0;
        }

        public List<Criterion> getAllCriteria() {
            return criteria;
        }

        public List<Criterion> getCriteria() {
            return criteria;
        }

        protected void addCriterion(String condition) {
            if (condition == null) {
                throw new RuntimeException("Value for condition cannot be null");
            }
            criteria.add(new Criterion(condition));
        }

        protected void addCriterion(String condition, Object value, String property) {
            if (value == null) {
                throw new RuntimeException("Value for " + property + " cannot be null");
            }
            criteria.add(new Criterion(condition, value));
        }

        protected void addCriterion(String condition, Object value1, Object value2, String property) {
            if (value1 == null || value2 == null) {
                throw new RuntimeException("Between values for " + property + " cannot be null");
            }
            criteria.add(new Criterion(condition, value1, value2));
        }

        /**
         * 【新加入的代码】生成带有转义字符的Criterion
         * @param condition
         * @param value1
         * @param value2
         * @param property
         */
        protected void addCriterionEscape(String condition, Object value1, Object value2, String property) {
            if (value1 == null || value2 == null) {
                throw new RuntimeException("Value or escape for " + property + " cannot be null");
            }
            criteria.add(new Criterion(condition, value1, value2, null, null));
        }
        
        public Criteria andIdIsNull() {
            addCriterion("ID is null");
            return (Criteria) this;
        }

        public Criteria andIdIsNotNull() {
            addCriterion("ID is not null");
            return (Criteria) this;
        }

        public Criteria andIdEqualTo(Long value) {
            addCriterion("ID =", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdNotEqualTo(Long value) {
            addCriterion("ID <>", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdGreaterThan(Long value) {
            addCriterion("ID >", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdGreaterThanOrEqualTo(Long value) {
            addCriterion("ID >=", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdLessThan(Long value) {
            addCriterion("ID <", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdLessThanOrEqualTo(Long value) {
            addCriterion("ID <=", value, "id");
            return (Criteria) this;
        }

        public Criteria andIdIn(List<Long> values) {
            addCriterion("ID in", values, "id");
            return (Criteria) this;
        }

        public Criteria andIdNotIn(List<Long> values) {
            addCriterion("ID not in", values, "id");
            return (Criteria) this;
        }

        public Criteria andIdBetween(Long value1, Long value2) {
            addCriterion("ID between", value1, value2, "id");
            return (Criteria) this;
        }

        public Criteria andIdNotBetween(Long value1, Long value2) {
            addCriterion("ID not between", value1, value2, "id");
            return (Criteria) this;
        }

        public Criteria andNameIsNull() {
            addCriterion("NAME is null");
            return (Criteria) this;
        }

        public Criteria andNameIsNotNull() {
            addCriterion("NAME is not null");
            return (Criteria) this;
        }

        public Criteria andNameEqualTo(String value) {
            addCriterion("NAME =", value, "name");
            return (Criteria) this;
        }

        public Criteria andNameNotEqualTo(String value) {
            addCriterion("NAME <>", value, "name");
            return (Criteria) this;
        }

        public Criteria andNameGreaterThan(String value) {
            addCriterion("NAME >", value, "name");
            return (Criteria) this;
        }

        public Criteria andNameGreaterThanOrEqualTo(String value) {
            addCriterion("NAME >=", value, "name");
            return (Criteria) this;
        }

        public Criteria andNameLessThan(String value) {
            addCriterion("NAME <", value, "name");
            return (Criteria) this;
        }

        public Criteria andNameLessThanOrEqualTo(String value) {
            addCriterion("NAME <=", value, "name");
            return (Criteria) this;
        }

        /**
         * 【新加入的代码】模糊查询
         * @param value
         * @return
         */
        public Criteria andNameLike(String value) {
            if(value != null){
                value = value.replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_");
                value = "%" + value + "%";
            }
            addCriterionEscape("NAME like", value, "/", "name");
            return (Criteria) this;
        }

        /**
         * 【新加入的代码】模糊查询
         * @param value
         * @return
         */
        public Criteria andNameNotLike(String value) {
            //模糊匹配的通配符
            if(value != null){
                value = value.replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_");
                value = "%" + value + "%";
            }
            addCriterionEscape("NAME not like", value, "/", "name");
            return (Criteria) this;
        }

        public Criteria andNameIn(List<String> values) {
            addCriterion("NAME in", values, "name");
            return (Criteria) this;
        }

        public Criteria andNameNotIn(List<String> values) {
            addCriterion("NAME not in", values, "name");
            return (Criteria) this;
        }

        public Criteria andNameBetween(String value1, String value2) {
            addCriterion("NAME between", value1, value2, "name");
            return (Criteria) this;
        }

        public Criteria andNameNotBetween(String value1, String value2) {
            addCriterion("NAME not between", value1, value2, "name");
            return (Criteria) this;
        }

        public Criteria andCompanyIsNull() {
            addCriterion("COMPANY is null");
            return (Criteria) this;
        }

        public Criteria andCompanyIsNotNull() {
            addCriterion("COMPANY is not null");
            return (Criteria) this;
        }

        public Criteria andCompanyEqualTo(String value) {
            addCriterion("COMPANY =", value, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyNotEqualTo(String value) {
            addCriterion("COMPANY <>", value, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyGreaterThan(String value) {
            addCriterion("COMPANY >", value, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyGreaterThanOrEqualTo(String value) {
            addCriterion("COMPANY >=", value, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyLessThan(String value) {
            addCriterion("COMPANY <", value, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyLessThanOrEqualTo(String value) {
            addCriterion("COMPANY <=", value, "company");
            return (Criteria) this;
        }

        /**
         * 【新加入的代码】模糊查询
         * @param value
         * @return
         */
        public Criteria andCompanyLike(String value) {
            //模糊匹配的通配符
            if(value != null){
                value = value.replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_");
                value = "%" + value + "%";
            }
            addCriterionEscape("COMPANY like", value, "/", "company");
            return (Criteria) this;
        }

        /**
         * 【新加入的代码】模糊查询
         * @param value
         * @return
         */
        public Criteria andCompanyNotLike(String value) {
            if(value != null){
                value = value.replaceAll("/", "//").replaceAll("%", "/%").replaceAll("_", "/_");
                value = "%" + value + "%";
            }
            addCriterionEscape("COMPANY not like", value, "/", "company");
            return (Criteria) this;
        }

        public Criteria andCompanyIn(List<String> values) {
            addCriterion("COMPANY in", values, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyNotIn(List<String> values) {
            addCriterion("COMPANY not in", values, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyBetween(String value1, String value2) {
            addCriterion("COMPANY between", value1, value2, "company");
            return (Criteria) this;
        }

        public Criteria andCompanyNotBetween(String value1, String value2) {
            addCriterion("COMPANY not between", value1, value2, "company");
            return (Criteria) this;
        }
    }

    public static class Criteria extends GeneratedCriteria {

        protected Criteria() {
            super();
        }
    }

    public static class Criterion {
        private String condition;

        private Object value;

        private Object secondValue;

        private boolean noValue;

        private boolean singleValue;

        private boolean betweenValue;

        /** 【新加入的代码】为true时按转义字符处理添加escape关键字 */
        private boolean escapeValue;

        private boolean listValue;

        private String typeHandler;

        public String getCondition() {
            return condition;
        }

        public Object getValue() {
            return value;
        }

        public Object getSecondValue() {
            return secondValue;
        }

        public boolean isNoValue() {
            return noValue;
        }

        public boolean isSingleValue() {
            return singleValue;
        }

        public boolean isBetweenValue() {
            return betweenValue;
        }

        /**
         * 【新加入的代码】为true时按转义字符处理添加escape关键字
         * @return
         */
        public boolean isEscapeValue() {
            return escapeValue;
        }

        public boolean isListValue() {
            return listValue;
        }

        public String getTypeHandler() {
            return typeHandler;
        }

        protected Criterion(String condition) {
            super();
            this.condition = condition;
            this.typeHandler = null;
            this.noValue = true;
        }

        protected Criterion(String condition, Object value, String typeHandler) {
            super();
            this.condition = condition;
            this.value = value;
            this.typeHandler = typeHandler;
            if (value instanceof List<?>) {
                this.listValue = true;
            } else {
                this.singleValue = true;
            }
        }

        protected Criterion(String condition, Object value) {
            this(condition, value, null);
        }

        protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
            super();
            this.condition = condition;
            this.value = value;
            this.secondValue = secondValue;
            this.typeHandler = typeHandler;
            this.betweenValue = true;
        }

        protected Criterion(String condition, Object value, Object secondValue) {
            this(condition, value, secondValue, null);
        }
        
        /**
         * 【新加入的代码】生成带有转义字符的Criterion
         * @param condition
         * @param value
         * @param escapeValue
         * @param typeHandler
         * @param dummy
         */
        protected Criterion(String condition, Object value, Object escapeValue, String typeHandler, Object dummy) {
            super();
            this.condition = condition;
            this.value = value;
            this.secondValue = escapeValue;
            this.typeHandler = typeHandler;
            this.escapeValue = true;
        }
    }
}

2、对PersonInfoMapper.xml的改动

修改的部分都用“【新加入的代码】”做了标记,改动的地方包括:

1)sql代码段:Example_Where_Clause

2)sql代码段:Update_By_Example_Where_Clause

<?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="GenTarget.mapper_java.PersonInfoMapper" >
  <resultMap id="BaseResultMap" type="GenTarget.object_example_java.PersonInfo" >
    <id column="ID" property="id" jdbcType="DECIMAL" />
    <result column="NAME" property="name" jdbcType="VARCHAR" />
    <result column="COMPANY" property="company" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                
                <!-- 【新加入的代码】添加转义字符 START -->
                <when test="criterion.escapeValue" >
                  and ${criterion.condition} #{criterion.value} escape #{criterion.secondValue}
                </when>
                <!-- 【新加入的代码】添加转义字符 END -->
                
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                
                <!-- 【新加入的代码】添加转义字符 START -->
                <when test="criterion.escapeValue" >
                  and ${criterion.condition} #{criterion.value} escape #{criterion.secondValue}
                </when>
                <!-- 【新加入的代码】添加转义字符 END -->
                
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    ID, NAME, COMPANY
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="GenTarget.object_example_java.PersonInfoExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from PERSON_INFO
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from PERSON_INFO
    where ID = #{id,jdbcType=DECIMAL}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from PERSON_INFO
    where ID = #{id,jdbcType=DECIMAL}
  </delete>
  <delete id="deleteByExample" parameterType="GenTarget.object_example_java.PersonInfoExample" >
    delete from PERSON_INFO
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="GenTarget.object_example_java.PersonInfo" >
    insert into PERSON_INFO (ID, NAME, COMPANY
      )
    values (#{id,jdbcType=DECIMAL}, #{name,jdbcType=VARCHAR}, #{company,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="GenTarget.object_example_java.PersonInfo" >
    insert into PERSON_INFO
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        ID,
      </if>
      <if test="name != null" >
        NAME,
      </if>
      <if test="company != null" >
        COMPANY,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=DECIMAL},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="company != null" >
        #{company,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="GenTarget.object_example_java.PersonInfoExample" resultType="java.lang.Integer" >
    select count(*) from PERSON_INFO
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update PERSON_INFO
    <set >
      <if test="record.id != null" >
        ID = #{record.id,jdbcType=DECIMAL},
      </if>
      <if test="record.name != null" >
        NAME = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.company != null" >
        COMPANY = #{record.company,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update PERSON_INFO
    set ID = #{record.id,jdbcType=DECIMAL},
      NAME = #{record.name,jdbcType=VARCHAR},
      COMPANY = #{record.company,jdbcType=VARCHAR}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="GenTarget.object_example_java.PersonInfo" >
    update PERSON_INFO
    <set >
      <if test="name != null" >
        NAME = #{name,jdbcType=VARCHAR},
      </if>
      <if test="company != null" >
        COMPANY = #{company,jdbcType=VARCHAR},
      </if>
    </set>
    where ID = #{id,jdbcType=DECIMAL}
  </update>
  <update id="updateByPrimaryKey" parameterType="GenTarget.object_example_java.PersonInfo" >
    update PERSON_INFO
    set NAME = #{name,jdbcType=VARCHAR},
      COMPANY = #{company,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=DECIMAL}
  </update>
</mapper>

调用此功能的Java代码如下:

package GenMyBatisTest;
 
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import GenTarget.mapper_java.PersonInfoMapper;
import GenTarget.object_example_java.PersonInfo;
import GenTarget.object_example_java.PersonInfoExample;

/**
 * MyBatis使用测试
 * @author Tsybius2014
 * @date 2016年5月22日
 * @time 下午10:44:06
 * @remark
 */
public class MyBatisTest {
    public static void main(String[] args) {
        try {
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session = sqlSessionFactory.openSession();
            try {
                PersonInfoMapper mapper = session.getMapper(PersonInfoMapper.class);
                //模糊查询
                PersonInfoExample example = new PersonInfoExample();
                PersonInfoExample.Criteria criteria = example.createCriteria();
                criteria.andCompanyLike("Dog Head%");
                example.setOrderByClause("id desc");
                List<PersonInfo> personInfoList = new ArrayList<PersonInfo>();
                personInfoList.addAll(mapper.selectByExample(example));
                if (personInfoList != null && personInfoList.size() > 0) {
                    for (PersonInfo personInfo : personInfoList) {
                        System.out.println(
                            "id:" + personInfo.getId() + ";" +
                            "name:" + personInfo.getName() + ";" +
                            "company:" + personInfo.getCompany());
                    }
                } else {
                    System.out.println("personInfoList is emply");
                }
                System.out.println("done.");
            } finally {
                session.close();
            }
        } catch (Exception ex) {
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            ex.printStackTrace(printWriter);
            System.out.println(stringWriter.toString());
        }
    }
}

Console中输出的结果如下:

id:8;name:Test3;company:Test%Dog Head%Test
id:7;name:Test2;company:Dog Head%Test
id:6;name:Test1;company:Dog Head%
done.

注:本文中介绍的只是实现此类功能的一种方法,仅供参考。

END

© 著作权归作者所有

共有 人打赏支持
北风其凉

北风其凉

粉丝 114
博文 497
码字总数 462457
作品 4
朝阳
程序员
SpringMVC+MyBatis项目总结(一)

环境Spring3.2+Mybatis 3.2.7,JDK 1.6,开发工具Myeclipse 2014 GA Pro,数据库MySQL 5.5(数据采用之前Oracle的,直接用Navicat从Oracle导入到Mysql,然后改了一下数据类型,主键自增) Mappe...

Eviltuzki
2015/06/05
0
2
【MyBatis】学习纪要十一:逆向工程

写在前面的话 前面学习MyBatis的运行原理,刚学完,回头想想还是非常复杂的,也因为之前没有这样去分析过源码,所以这一节算是卡住了,可能会花一定的时间,为了不卡住学习进度,所以我们继续...

Wenyi_Feng
05/10
0
0
MyBatis insert 返回主键的方法

数据库:SqlServer2005,表结构: /==============================================================// Table: Dic_City //============================================================......

凯文加内特
2015/03/04
0
0
Spring boot Mybatis 整合(完整版)

个人开源项目 springboot+mybatis+thymeleaf+docker构建的个人站点开源项目(集成了个人主页、个人作品、个人博客) 朋友自制的springboot接口文档组件swagger2 更多干货 SpringBoot系列目录...

舒运
07/09
0
0
使用Mybatis Generator自动生成Mybatis相关代码

本文将简要介绍怎样利用Mybatis Generator自动生成Mybatis的相关代码: 一、构建一个环境: 1. 首先创建一个表: Sql代码 1. CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), spec...

JavaOlder
2012/11/15
0
2
使用Mybatis Generator自动生成Mybatis相关代码

本文将简要介绍怎样利用Mybatis Generator自动生成Mybatis的相关代码: 一、构建一个环境: 1. 首先创建一个表: CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR...

天外飞鱼
2013/10/16
0
1
Spring Security实现RBAC权限管理

Spring Security实现RBAC权限管理 一简介 在企业应用中,认证和授权是非常重要的一部分内容,业界最出名的两个框架就是大名鼎鼎的 Shiro和Spring Security。由于Spring Boot非常的流行,选择...

小忽悠
06/21
0
0
mybatis实战教程(mybatis in action),mybatis入门到精通

转自:http://www.yihaomen.com/article/java/302.htm (读者注:其实这个应该叫做很基础的入门一下下,如果你看过Hibernate了那这个就非常的简单) (再加一条,其实大家可以看官方的教程更...

一枚Sir
2015/05/13
0
0
SSM框架——使用MyBatis Generator自动创建代码

这两天需要用到MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的ORM框架,所以主要的工作就是配置Mapping映射文件,但是由于手写映射文件很容易出错,所以可利用MyBatis生成器自动...

Carl_
2015/07/17
0
0
SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)

使用SSM(Spring、SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方。之前没有记录SSM整合的过程...

Carl_
2015/07/17
0
3

没有更多内容

加载失败,请刷新页面

加载更多

下一页

MacOS和Linux内核的区别

导读 有些人可能认为MacOS和Linux内核有相似之处,因为它们可以处理类似的命令和类似的软件。甚至有人认为苹果的MacOS是基于linux的。事实上,这两个内核的历史和特性是非常不同的。今天,我...

问题终结者
5分钟前
0
0
SpringBoot | 第八章:统一异常、数据校验处理

前言 在web应用中,请求处理时,出现异常是非常常见的。所以当应用出现各类异常时,进行异常的捕获或者二次处理(比如sql异常正常是不能外抛)是非常必要的,比如在开发对外api服务时,约定了响...

oKong
13分钟前
0
0
mysql高级

一、存储引擎 InnoDB MyISAM 比较 二、数据类型 整型 浮点数 字符串 时间和日期 三、索引 索引分类 索引的优点 索引优化 B-Tree 和 B+Tree 原理 四、查询性能优化 五、切分 垂直切分 水平切分...

丁典
33分钟前
0
0
rsync通过同步服务、系统日志、screen工具

rsync通过后台服务同步 在远程主机中建立一个rsync服务器,在服务器上配置好rsync的各种应用,然后将本机作为rsync的一个客户端连接远程的rsync服务器。 首先在A机器上建立并且配置rsync的配...

黄昏残影
今天
3
0
Spring Cloud Gateway 接口文档聚合实现

在微服务架构下,通常每个微服务都会使用Swagger来管理我们的接口文档,当微服务越来越多,接口查找管理无形中要浪费我们不少时间,毕竟懒是程序员的美德。 由于swagger2暂时不支持webflux 走...

冷冷gg
今天
99
2
流利阅读笔记31-20180720待学习

克罗地亚:输了世界杯,却赢了全世界 雪梨 2018-07-20 1.今日导读 1998 年,年轻的克罗地亚国家队在法国世界杯给全世界留下了不可磨灭的印象,格子军团一举夺得了季军。4 年后,克罗地亚折戟...

aibinxiao
今天
3
0
OSChina 周五乱弹 —— 我们是食物链的最底层

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @温家成 :分享谢安琪的单曲《姿色份子》 《姿色份子》- 谢安琪 手机党少年们想听歌,请使劲儿戳(这里) @贪吃飒:最近p2p怎么了、半个月爆了...

小小编辑
今天
681
13
Android Studio 3.0 之后打包apk出现应用未安装问题

1、废话 出现这个问题的原因,并不是只有一个,而是有多个原因,不懂的估计会被搞得一头雾水,下面我列举的是我遇到的几种问题和网友遇到的几种问题,但不一定是全部,也有可能有些莫名其妙的...

她叫我小渝
今天
0
0
前端基础

1. get请求传参长度的误区 误区:我们经常说get请求参数的大小存在限制,而post请求的参数大小是无限制的。 实际上HTTP 协议从未规定 GET/POST 的请求长度限制是多少。对get请求参数的限制是...

wenxingjun
今天
0
0
拦截SQLSERVER的SSL加密通道替换传输过程中的用户名密码实现运维审计(一)

工作准备 •一台SQLSERVER 2005/SQLSERVER 2008服务 •SQLSERVER jdbc驱动程序 •Java开发环境eclipse + jdk1.8 •java反编译工具JD-Core 反编译JDBC分析SQLSERVER客户端与服务器通信原理 SQ...

紅顏為君笑
今天
12
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部