All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mybatis.pj.util.MyExampleSqlHelp Maven / Gradle / Ivy

There is a newer version: 2.2.1
Show newest version
package com.mybatis.pj.util;

public class MyExampleSqlHelp {
	
	/**
	 * 查询指定列和获取表名
	 * @return 对应sql片段
	 */
	public static String getColumn() {
		return  "\r\n" + 
				"		${item}\r\n" + 
				"	 from  ${tableName[0]}";
	}
	
	
	/**
	 * 查询指定更新列和获取表名
	 * @return 对应sql片段
	 */
	public static String getUpdateColumn() {
		return  "${tableName[0]} SET\r\n" + 
				"		\r\n" + 
				"			\r\n" + 
				"				${key} = #{updateValue[${index}]}\r\n" + 
				"			\r\n" + 
				"		";
	}
	
	
	/**
	 * 是否使用别名,有的话则获取第一个别名
	 * @return 对应sql片段
	 */
	public static String isUseAlias() {
		return "\r\n" + 
				"			${tableAlias[0]}\r\n" + 
				"		";
	}
	
	/**
	 * 是否使用了左连接查询
	 * * @return 对应sql片段
	 */
	public static String isUseLeftJoin() {
		return "\r\n" + 
				"			LEFT JOIN\r\n" + 
				"			\r\n" + 
				"				= 1\">\r\n" + 
				"					${tableName[1]} ${key}\r\n" + 
				"				\r\n" + 
				"			\r\n" + 
				"			ON ${leftJoinOn}\r\n" + 
				"		";
	}
	
	/**
	 * 是否使用了查询和是否使用了等号查询
	* @return 对应sql片段
	 */
	public static String useWhereAndEqualsWhere() {
		return "\r\n" + 
				"			\r\n" + 
				"				\r\n" + 
				"					 " + 
				"						${key} = #{equalsWhereValue[${index}]} " + 
				"					\r\n" + 
				"\r\n" + 
				"					\r\n" + 
				"						AND\r\n" + 
				"					\r\n" + 
				"				"; 
	}
	
	/**
	 * 是否使用了大于查询
	 * @return 对应sql片段
	 */
	public static String useGreaterThan() {
		return "\r\n" + 
				"					 " + 
				"						${key} > #{greaterThanWhereValue[${index}]} " + 
				"					\r\n" + 
				"					\r\n" + 
				"						AND\r\n" + 
				"					\r\n" + 
				"				"; 
	}
	
	/**
	 * 是否使用了小于查询
	 * @return 对应sql片段
	 */
	public static String useLessThan() {
		return "\r\n" + 
				"					 " + 
				"						${key} < #{lessThanWhereValue[${index}]} " + 
				"					\r\n" + 
				"					\r\n" + 
				"						AND\r\n" + 
				"					\r\n" + 
				"				";
	}
	
	/**
	 * 是否使用了不等于查询
	 * @return 对应sql片段
	 */
	public static String useNotEquals() {
		return "\r\n" + 
				"					 " + 
				"						${key} != #{notEqualsWhereValue[${index}]}  " + 
				"					\r\n" + 
				"				\r\n" + 
				"			\r\n" + 
				"		";
	}
	
	/**
	 * 判断是否使用了查询
	 * @return 对应sql片段
	 */
	public static String notUseWhere() {
		return "\r\n" + 
				"			WHERE 1 = 1\r\n" + 
				"		";
	}
	
	/**
	 * 是否使用in查询
	 * @return
	 */
	public static String useIn() {
		return "\r\n" + 
				"			AND\r\n" + 
				"			\r\n" + 
				"				${field} in\r\n" + 
				"				\r\n" + 
				"					\r\n" + 
				"						\r\n" + 
				"							#{value1}\r\n" + 
				"						\r\n" + 
				"					\r\n" + 
				"					\r\n" + 
				"						\r\n" + 
				"							#{value2}\r\n" + 
				"						\r\n" + 
				"					\r\n" + 
				"				\r\n" + 
				"			\r\n" + 
				"		";
	}
	
	/**
	 * 是否使用like查询
	 * @return
	 */
	public static String useLike() {
		return "\r\n" + 
				"			\r\n" + 
				"				AND\r\n" + 
				"			\r\n" + 
				"			\r\n" + 
				"				${field} LIKE #{likeValues[${index}]}\r\n" + 
				"			\r\n" + 
				"		";
	}
	
	/**
	 * 是否使用group by
	 * @return 对应sql片段
	 */
	public static String useGroup() {
		return "\r\n" + 
				"			GROUP BY ${groupBy}\r\n" + 
				"		";
	}
	
	/**
	 * 是否使用 order by
	 * @return 对应sql片段
	 */
	public static String useOrder() {
		return "\r\n" + 
				"			order by \r\n" + 
				"			\r\n" + 
				"				${key} " + 
				"				\r\n" + 
				"					\r\n" + 
				"						DESC \r\n" + 
				"					\r\n" + 
				"					\r\n" + 
				"						ASC\r\n" + 
				"					\r\n" + 
				"				\r\n" + 
				"			\r\n" + 
				"		";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy