常用语句

模糊查询

 <select id="search" resultMap="resultMap">
        select
        <include refid="Columns"/>
        from user where nickName like CONCAT(CONCAT('%',#{search}),'%') or nickName like CONCAT(CONCAT('%',#{search}),'%')
</select>

一对一

<association column="superior" property="superior" javaType="com.sykj.xdd.entity.User" select="com.sykj.xdd.dao.UserDao.findById"/>

一对多

<collection property="roles" column="id" ofType="com.sykj.xdd.entity.Role"
                select="com.sykj.xdd.dao.UserRoleDao.findRoleByUserId"/>

返回自增主键

<insert id="insert" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
	insert into user
	<trim prefix="(" suffix=")" suffixOverrides=",">
		<if test="id != null">id,</if>
			...
	</trim>
	<trim prefix="values (" suffix=")" suffixOverrides=",">
		<if test="id != null">#{id},</if>
			...
	</trim>
</insert>

sql 大于小于

原符号       <        <=      >       >=       &        '        "
替换符号    &lt;    &lt;=   &gt;    &gt;=   &amp;   &apos;  &quot;

例如:sql如下:

create_date_time &gt;= #{startTime} and  create_date_time &lt;= #{endTime}

例子

<select id="searchCount" resultType="java.lang.Integer">
	select count(*) from money_log
	<where>
		<if test="arg0 != null">and user = #{arg0}</if>
		<if test="arg1 != null">and type like concat(concat('%',#{arg1}),'%')</if>
		<if test="arg2 != null and arg3 != null">and createDate &gt; #{arg2} and createDate &lt; #{arg3}</if>
	</where>
</select>

数据库命名问题

问题
数据库表的名称是用逆向工程不区分大小写
解决方式
mysql 表命名时 采用下划线分割单词