当前位置:   article > 正文

SSM框架(七)Sping框架之SQL【Generator代码生成器】原理_ssm代码生成器

ssm代码生成器

前面SSM(四)模仿sping-mvc自定义一个框架中:
最后讲到:Sping框架通用SQLGenerator.java

一、Generator代码生成器有什么用?

条件:1、我们需要对两张 表做增删查改操作 2、如果需要对无数张 表进行增删查改操作;
思考:我们是不是要针对不同表在代码里一条一条写出查询语句?

@param o->UserInfo(id,name)
@return select * from user_info where user_id = ? and user_name = ?;
@param o->StudentInfo(id,name,number)
@return select * from t_student where t_stuid = ? and t_stuname = ? and t_stunumber = ?
  • 1
  • 2
  • 3
  • 4

由上述sql语句我们可以总结出:

SELECT column_name,column_name
FROM table_name
WHERE some_column=some_value;;
  • 1
  • 2
  • 3

于是,我们采用Generator代码生成器,自动生成sql语句,不需要我们每次写出完整的增删查改

二、SQLGenerator.java示例

(1) 目录结构

下面用一个demo示例演示以上三种功能:
在这里插入图片描述

(2)实体+注解

(注解标签使用方法参考:SSM框架(四)-注解部分

ColumnTable两个接口里定义了2类注解:

  • @Retention : 元注解 --生命周期在运行时
  • @Target :注解可以用在类/接口,方法、字段上
    在这里插入图片描述在这里插入图片描述

-》 定义一个UserInfo类和一个student类,写main函数测试结果如下:
(运行时类引用了Table接口、每个元素与(数据库)这里我们与Column相联系)在这里插入图片描述在这里插入图片描述
UserInfo:

package com.cungudafa.annotation.demo;

@Table("user_info")
public class UserInfo {//user_info表
	
	@Column("user_id")
	private Integer userId;//user_id字段
	
	@Column("user_name")
	private String userName;//user_name字段

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

StudentInfo:

package com.cungudafa.annotation.demo;

@Table("t_student")
public class StudentInfo {
	@Column("t_stuid")
	private Integer id;
	@Column("t_stuname")
	private String studentName;
	@Column("t_stunumber")
	private String studentNumber;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getStudentName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public String getStudentNumber() {
		return studentNumber;
	}
	public void setStudentNumber(String studentNumber) {
		this.studentNumber = studentNumber;
	}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

(3)Generator代码生成器

定义SQLGenerator.java

  • 模拟数据库请求操作时,对sql语句变量的控制
    例:select * from user_info where 1=1 and user_name = 'zhangsan' and user_id = 10001
    select * from 表名 where 直接写入条件 and 查询关键词1 = '字符串' and 查询关键词2 = 数字
    package com.cungudafa.annotation.demo;
    
    import java.lang.reflect.Field;
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * 生成SQL
     * @author Administrator
     *
     */
    public class SQLGenerator {
    	
    	public static String createInsertSql(Object o){
    		return null;//待补充
    	}
    	
    	public static String createDeleteSql(Object o){
    		return null;
    	}
    	
    	public static String createUpdateSql(Object o){
    		return null;
    	}
    	
    	/**
    	 * 
    	 * @param o->UserInfo(id,name)
    	 * @return select * from user_info where user_id = ? and user_name = ?;
    	 * @throws InvocationTargetException 
    	 * @throws IllegalArgumentException 
    	 * @throws IllegalAccessException 
    	 * @throws SecurityException 
    	 * @throws NoSuchFieldException 
    	 */
    	public static String createSelectSql(Object o) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException, SecurityException{
    		
    		//获取传入对象的运行时类
    		Class c = o.getClass();
    		//判断该类是否有@Table注解
    		if(c.isAnnotationPresent(Table.class)){
    			String sql = "select * from ";
    			Table t = (Table) c.getAnnotation(Table.class);
    			String tableName = t.value();
    			sql = sql + tableName + " where 1=1 ";
    			//获取所有的get方法
    			Method[] methods = c.getDeclaredMethods();
    			List<Method> getMethods = new ArrayList<>();
    			for(Method method : methods){
    				if(method.getName().startsWith("get")){
    					getMethods.add(method);
    				}
    			}
    			
    			//遍历get方法
    			for(Method method : getMethods){
    				Object value = method.invoke(o);
    				if(value != null){
    					String methodName = method.getName();//getUserId/getUserName
    					System.out.println("methodName = " + methodName);
    					//getUserId-->userId
    					String fieldName = methodName.replaceAll("get", "");//UserId
    					fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);//UserId->userId
    					System.out.println("fieldName = " + fieldName);
    					//获得字段
    					Field field = c.getDeclaredField(fieldName);
    					System.out.println("field = " + field);
    					//判断字段上是否有Column注解
    					if(field.isAnnotationPresent(Column.class)){
    						//获得字段上的Column注解
    						Column col = field.getAnnotation(Column.class);
    						//获得注解的value值,作为列名
    						String columnName = col.value();
    						if(value instanceof Integer){//区分id学号String转int(数据库为int)
    							sql = sql + "and " + columnName + " = " + String.valueOf(value) + " ";
    						}else{
    							sql = sql + "and " + columnName + " = '" + String.valueOf(value) + "' ";
    						}
    					}
    				}
    			}
    			return sql;
    		}else{
    			return null;
    		}
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89

-》 测试结果:(两张表都可以通用SQLGenerator框架)

sql = select * from user_info where 1=1 and user_name = ‘zhangsan’ and user_id = 10001
sql = select * from t_student where 1=1 and t_stuid = 10002 and t_stuname = ‘李四’ and t_stunumber = ‘102001203103’

在这里插入图片描述

三、完整SQLGenerator.java

自定义SQLGenerator:

package com.cungudafa.annotation.demo;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * 生成SQL
 * @author Administrator
 *
 */
public class SQLGenerator {
	/**
	 * 插入
	 * @param o->UserInfo(id,name)
	 * @return insert into t_student vlaues (?, ?, ?) 
	 * @throws InvocationTargetException 
	 * @throws IllegalArgumentException 
	 * @throws IllegalAccessException 
	 * @throws SecurityException 
	 * @throws NoSuchFieldException 
	 */
	public static String createInsertSql(Object o) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException, SecurityException{
		//获取传入对象的运行时类
		Class c = o.getClass();
		//判断该类是否有@Table注解
		if(c.isAnnotationPresent(Table.class)){
			String sql = "insert into ";
			Table t = (Table) c.getAnnotation(Table.class);
			String tableName = t.value();
			sql = sql + tableName + " vlaues (";
			//获取所有的get方法
			Method[] methods = c.getDeclaredMethods();
			List<Method> getMethods = new ArrayList<>();
			for(Method method : methods){
				if(method.getName().startsWith("get")){
					getMethods.add(method);
				}
			}
			//遍历get方法
			for(Method method : getMethods){
				Object value = method.invoke(o);
				if(value != null){
					String methodName = method.getName();//getUserId/getUserName
					//System.out.println("methodName = " + methodName);
					//getUserId-->userId
					String fieldName = methodName.replaceAll("get", "");//UserId
					fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);//UserId->userId
					//System.out.println("fieldName = " + fieldName);
					//获得字段
					Field field = c.getDeclaredField(fieldName);
					//System.out.println("field = " + field);
					//判断字段上是否有Column注解
					if(field.isAnnotationPresent(Column.class)){
						//获得字段上的Column注解
						Column col = field.getAnnotation(Column.class);
						//获得注解的value值,作为列名
						String columnName = col.value();					
						if(value instanceof Integer){//区分id学号String转int(数据库为int)
							sql = sql + String.valueOf(value) + ",";
						}else{
							sql = sql +" '" + String.valueOf(value) + "',";
						}
					}
				}
			}
			sql = sql.substring(0,sql.length()-1) + ")";//删去sql句末多余的“,”
			return sql;
		}else{
			return null;
		}
	}
	/**
	 * 删除
	 * @param o->UserInfo(id,name)
	 * @return DELETE FROM t_student where and t_stuid = ?
	 * @throws InvocationTargetException 
	 * @throws IllegalArgumentException 
	 * @throws IllegalAccessException 
	 * @throws SecurityException 
	 * @throws NoSuchFieldException 
	 */
	public static String createDeleteSql(Object o) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException, SecurityException{

		//获取传入对象的运行时类
		Class c = o.getClass();
		//判断该类是否有@Table注解
		if(c.isAnnotationPresent(Table.class)){
			String sql = "DELETE FROM ";
			Table t = (Table) c.getAnnotation(Table.class);
			String tableName = t.value();
			sql = sql + tableName + " where ";
			//获取所有的get方法
			Method[] methods = c.getDeclaredMethods();
			List<Method> getMethods = new ArrayList<>();
			for(Method method : methods){
				if(method.getName().startsWith("get")){
					getMethods.add(method);
				}
			}
			
			//遍历get方法
			for(Method method : getMethods){
				Object value = method.invoke(o);
				if(value != null){
					String methodName = method.getName();//getUserId/getUserName
					//System.out.println("methodName = " + methodName);
					//getUserId-->userId
					String fieldName = methodName.replaceAll("get", "");//UserId
					fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);//UserId->userId
					//System.out.println("fieldName = " + fieldName);
					//获得字段
					Field field = c.getDeclaredField(fieldName);
					//System.out.println("field = " + field);
					//判断字段上是否有Column注解
					if(field.isAnnotationPresent(Column.class)){
						//获得字段上的Column注解
						Column col = field.getAnnotation(Column.class);
						//获得注解的value值,作为列名
						String columnName = col.value();
						if(value instanceof Integer){//区分id学号String转int(数据库为int)
							sql = sql + columnName + " = " + String.valueOf(value) + " and ";
						}else{
							sql = sql + columnName + " = '" + String.valueOf(value) + "' and ";
						}
					}
				}
			}
			sql=sql.substring(0,sql.length()-4);//删去sql句末多余的“and ”
			return sql;
		}else{
			return null;
		}
	}
	

	/**
	 * 更新
	 * @param o->UserInfo(id,name)
	 * @return UPDATE table_name
				SET column1=value1,column2=value2,...
				WHERE some_column=some_value;
	 * @throws InvocationTargetException 
	 * @throws IllegalArgumentException 
	 * @throws IllegalAccessException 
	 * @throws SecurityException 
	 * @throws NoSuchFieldException 
	 */
	public static String createUpdateSql(Object o,Object o1) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException, SecurityException{
		//获取传入对象的运行时类
		Class c = o.getClass();
		Class c1 = o1.getClass();
		//判断该类是否有@Table注解
		if(c.isAnnotationPresent(Table.class)){
			String sql = "update ";
			Table t = (Table) c.getAnnotation(Table.class);
			String tableName = t.value();
			sql = sql + tableName + " set ";
			//获取所有的get方法
			Method[] methods = c.getDeclaredMethods();
			List<Method> getMethods = new ArrayList<>();
			for(Method method : methods){
				if(method.getName().startsWith("get")){
					getMethods.add(method);
				}
			}
			//遍历get方法
			for(Method method : getMethods){
				Object value = method.invoke(o1);
				if(value != null){
					String methodName = method.getName();//getUserId/getUserName
					//System.out.println("methodName = " + methodName);
					//getUserId-->userId
					String fieldName = methodName.replaceAll("get", "");//UserId
					fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);//UserId->userId大写转小写
					//System.out.println("fieldName = " + fieldName);
					//获得字段
					Field field = c.getDeclaredField(fieldName);
					//System.out.println("field = " + field);
					//判断字段上是否有Column注解
					if(field.isAnnotationPresent(Column.class)){
						//获得字段上的Column注解
						Column col = field.getAnnotation(Column.class);
						//获得注解的value值,作为列名
						String columnName = col.value();
						if(value instanceof Integer){//区分id学号String转int(数据库为int)
							sql = sql + columnName + " = " + String.valueOf(value) + " and ";
						}else{
							sql = sql + columnName + " = '" + String.valueOf(value) + "' and ";
						}
					}
				}
			}
			sql = sql.substring(0,sql.length()-4)+"where ";//删去sql句末多余的“and ”
			//获取所有的get方法
			methods = c.getDeclaredMethods();
			getMethods = new ArrayList<>();
			for(Method method : methods){
				if(method.getName().startsWith("get")){
					getMethods.add(method);
				}
			}
			
			//遍历get方法
			for(Method method : getMethods){
				Object value = method.invoke(o);
				if(value != null){
					String methodName = method.getName();//getUserId/getUserName
					//System.out.println("methodName = " + methodName);
					//getUserId-->userId
					String fieldName = methodName.replaceAll("get", "");//UserId
					fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);//UserId->userId
					//System.out.println("fieldName = " + fieldName);
					//获得字段
					Field field = c.getDeclaredField(fieldName);
					//System.out.println("field = " + field);
					//判断字段上是否有Column注解
					if(field.isAnnotationPresent(Column.class)){
						//获得字段上的Column注解
						Column col = field.getAnnotation(Column.class);
						//获得注解的value值,作为列名
						String columnName = col.value();
						if(value instanceof Integer){//区分id学号String转int(数据库为int)
							sql = sql + columnName + " = " + String.valueOf(value) + " and ";
						}else{
							sql = sql + columnName + " = '" + String.valueOf(value) + "' and ";
						}
					}
				}
			}
			sql = sql.substring(0,sql.length()-4);
			return sql;
		}else{
			return null;
		}
	}
	

	
	/**
	 * 查询
	 * @param o->UserInfo(id,name)
	 * @return select * from user_info where user_id = ? and user_name = ?;
	 * @throws InvocationTargetException 
	 * @throws IllegalArgumentException 
	 * @throws IllegalAccessException 
	 * @throws SecurityException 
	 * @throws NoSuchFieldException 
	 */
	public static String createSelectSql(Object o) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException, SecurityException{
		
		//获取传入对象的运行时类
		Class c = o.getClass();
		//判断该类是否有@Table注解
		if(c.isAnnotationPresent(Table.class)){
			String sql = "select * from ";
			Table t = (Table) c.getAnnotation(Table.class);
			String tableName = t.value();
			sql = sql + tableName + " where 1=1 ";
			//获取所有的get方法
			Method[] methods = c.getDeclaredMethods();
			List<Method> getMethods = new ArrayList<>();
			for(Method method : methods){
				if(method.getName().startsWith("get")){
					getMethods.add(method);
				}
			}
			
			//遍历get方法
			for(Method method : getMethods){
				Object value = method.invoke(o);
				if(value != null){
					String methodName = method.getName();//getUserId/getUserName
					System.out.println("methodName = " + methodName);
					//getUserId-->userId
					String fieldName = methodName.replaceAll("get", "");//UserId
					fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);//UserId->userId
					System.out.println("fieldName = " + fieldName);
					//获得字段
					Field field = c.getDeclaredField(fieldName);
					System.out.println("field = " + field);
					//判断字段上是否有Column注解
					if(field.isAnnotationPresent(Column.class)){
						//获得字段上的Column注解
						Column col = field.getAnnotation(Column.class);
						//获得注解的value值,作为列名
						String columnName = col.value();
						if(value instanceof Integer){//区分id学号String转int(数据库为int)
							sql = sql + "and " + columnName + " = " + String.valueOf(value) + " ";
						}else{
							sql = sql + "and " + columnName + " = '" + String.valueOf(value) + "' ";
						}
					}
				}
			}
			return sql;
		}else{
			return null;
		}
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 测试main函数:
    TestCase:
package com.cungudafa.annotation.demo;

import java.lang.reflect.InvocationTargetException;

public class TestCase {
	public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException, SecurityException {
		UserInfo userInfo = new UserInfo();
		userInfo.setUserId(10001);
		userInfo.setUserName("zhangsan");
		String sql = SQLGenerator.createSelectSql(userInfo);
		System.out.println("sql = " + sql);
		
		System.out.println("--------查询-----------");
		StudentInfo s = new StudentInfo();
		s.setId(10002);
		s.setStudentName("李四");
		s.setStudentNumber("102001203103");
		sql = SQLGenerator.createSelectSql(s);
		System.out.println("--------查询-----------");
		System.out.println("sql = " + sql);
		
		System.out.println("--------插入-----------");
		StudentInfo s1 = new StudentInfo();
		s1.setId(10002);//插入内容
		s1.setStudentName("李四");
		s1.setStudentNumber("102001203103");
		sql = SQLGenerator.createInsertSql(s1);
		System.out.println("sql = " + sql);
		
		System.out.println("--------删除-----------");
		StudentInfo s2 = new StudentInfo();
		s2.setId(10002);//删除条件任取
		s2.setStudentName("李四");
		s2.setStudentNumber("102001203103");
		sql = SQLGenerator.createDeleteSql(s2);
		System.out.println("sql = " + sql);
		
		System.out.println("--------更新studentinfo-----------");
		StudentInfo s3 = new StudentInfo();
		s3.setId(10002);//默认s3内容
		s3.setStudentName("李四");
		s3.setStudentNumber("102001203103");
		//修改内容
		StudentInfo s3_update = new StudentInfo();
		//s3_update.setId(s3.getId());//获得原始id,id唯一不可更改
		s3_update.setStudentName("张三");
		s3_update.setStudentNumber("0123456789");
		sql = SQLGenerator.createUpdateSql(s3,s3_update);
		System.out.println("sql = " + sql);
		
		System.out.println("\n--------userinfo表:-----------");
		UserInfo userInfo1 = new UserInfo();
		userInfo1.setUserId(1001);
		userInfo1.setUserName("user001");
		sql = SQLGenerator.createSelectSql(userInfo1);
		System.out.println("\nSelectsql = " + sql);//查	
		sql = SQLGenerator.createInsertSql(userInfo1);
		System.out.println("\nInsertsql = " + sql);//增
		userInfo1.setUserName("user123");//修改姓名
		sql = SQLGenerator.createUpdateSql(userInfo,userInfo1);//user001->user123
		System.out.println("\nUpdatesql = " + sql);//改
		sql = SQLGenerator.createDeleteSql(userInfo1);
		System.out.println("\nDeletesql = " + sql);//删
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 结果:
    在这里插入图片描述
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/394802
推荐阅读
相关标签
  

闽ICP备14008679号