`

反射+注释,根据实体类对象生成SQL语句工具类

    博客分类:
  • java
阅读更多

最近在写一个公司内部项目,由于觉得配置Hibernate过于繁琐,索性使用了spring的jdbc,可是又要写很多的sql语句,为了偷偷懒,于是就写个能通过实体类对象生成SQL语句的工具类。

目前只在MySql数据库上实验通过,其他数据库未测试。

本工具类还有很多不足之处,不过好在可以满足自己一些简单的日常使用。

上代码了。

字段类型:

1 package net.tjnwdseip.util;
2    
3 public enum FieldType {
4    
5      STRING,NUMBER,DATE
6 }
字段注释:
01 package net.tjnwdseip.util;
02    
03 import java.lang.annotation.Documented;
04 import java.lang.annotation.ElementType;
05 import java.lang.annotation.Retention;
06 import java.lang.annotation.RetentionPolicy;
07 import java.lang.annotation.Target;
08    
09 @Documented
10 @Retention (RetentionPolicy.RUNTIME)
11 @Target (ElementType.FIELD)
12 public <A class =referer href= "http://my.oschina.net/interface" target=_blank> @interface </A>  FieldAnnotation {
13    
14      String fieldName();
15        
16      FieldType fieldType();
17        
18      boolean pk();
19 }
表名注释:
01 package net.tjnwdseip.util;
02    
03 import java.lang.annotation.Documented;
04 import java.lang.annotation.ElementType;
05 import java.lang.annotation.Retention;
06 import java.lang.annotation.RetentionPolicy;
07 import java.lang.annotation.Target;
08    
09 @Documented
10 @Retention (RetentionPolicy.RUNTIME)
11 @Target (ElementType.TYPE)
12 public <A class =referer href= "http://my.oschina.net/interface" target=_blank> @interface </A>  TableAnnotation {
13    
14      String tableName();
15 }
SQL语句生成工具类:
001 package net.tjnwdseip.util;
002    
003 import java.lang.reflect.Field;
004 import java.lang.reflect.InvocationTargetException;
005 import java.lang.reflect.Method;
006 import java.util.ArrayList;
007 import java.util.HashMap;
008 import java.util.Iterator;
009 import java.util.List;
010    
011 /**
012  
013   * @ClassName: CreateSqlTools
014   * @Description: TODO(根据实体类对象生成SQL语句)
015   * <A class=referer href="http://my.oschina.net/arthor" target=_blank>@author</A>  LiYang
016   * @date 2012-5-4 下午10:07:03
017  
018   */
019 public class CreateSqlTools {
020    
021      /**
022      
023       * @Title: getTableName
024       * @Description: TODO(获取表名)
025       * @param @param obj
026       * @param @return 设定文件
027       * @return String 返回类型
028       * @throws
029       */
030      private static String getTableName(Object obj) {
031          String tableName = null ;
032          if (obj.getClass().isAnnotationPresent(TableAnnotation. class )) {
033              tableName = obj.getClass().getAnnotation(TableAnnotation. class )
034                      .tableName();
035          }
036          return tableName;
037      }
038    
039      /**
040      
041       * @Title: getAnnoFieldList
042       * @Description: TODO(获取所有有注释的字段,支持多重继承)
043       * @param @param obj
044       * @param @return 设定文件
045       * @return List<Field> 返回类型
046       * @throws
047       */
048      @SuppressWarnings ( "rawtypes" )
049      private static List<Field> getAnnoFieldList(Object obj) {
050          List<Field> list = new ArrayList<Field>();
051          Class superClass = obj.getClass().getSuperclass();
052          while ( true ) {
053              if (superClass != null ) {
054                  Field[] superFields = superClass.getDeclaredFields();
055                  if (superFields != null && superFields.length > 0 ) {
056                      for (Field field : superFields) {
057                          if (field.isAnnotationPresent(FieldAnnotation. class )) {
058                              list.add(field);
059                          }
060                      }
061                  }
062                  superClass = superClass.getSuperclass();
063              } else {
064                  break ;
065              }
066          }
067          Field[] objFields = obj.getClass().getDeclaredFields();
068          if (objFields != null && objFields.length > 0 ) {
069              for (Field field : objFields) {
070                  if (field.isAnnotationPresent(FieldAnnotation. class )) {
071                      list.add(field);
072                  }
073              }
074          }
075          return list;
076      }
077    
078      /**
079      
080       * @Title: getFieldValue
081       * @Description: TODO(获取字段的值,支持多重继承)
082       * @param @param obj
083       * @param @param field
084       * @param @return 设定文件
085       * @return String 返回类型
086       * @throws
087       */
088      @SuppressWarnings ({ "rawtypes" })
089      private static String getFieldValue(Object obj, Field field) {
090          String value = null ;
091          String name = field.getName();
092          String methodName = "get" + name.substring( 0 , 1 ).toUpperCase()
093                  + name.substring( 1 );
094          Method method = null ;
095          Object methodValue = null ;
096          try {
097              method = obj.getClass().getMethod(methodName);
098          } catch (NoSuchMethodException | SecurityException e1) {
099              // TODO Auto-generated catch block
100          }
101          if (method != null ) {
102              try {
103                  methodValue = method.invoke(obj);
104              } catch (IllegalAccessException | IllegalArgumentException
105                      | InvocationTargetException e) {
106                  // TODO Auto-generated catch block
107              }
108              if (methodValue != null ) {
109                  value = methodValue.toString();
110              } else {
111                  Class objSuperClass = obj.getClass().getSuperclass();
112                  while ( true ) {
113                      if (objSuperClass != null ) {
114                          try {
115                              methodValue = method.invoke(objSuperClass);
116                          } catch (IllegalAccessException
117                                  | IllegalArgumentException
118                                  | InvocationTargetException e) {
119                              // TODO Auto-generated catch block
120                          }
121                          if (methodValue != null ) {
122                              value = methodValue.toString();
123                              break ;
124                          } else {
125                              objSuperClass = objSuperClass.getSuperclass();
126                          }
127                      } else {
128                          break ;
129                      }
130                  }
131              }
132          }
133          return value;
134      }
135    
136      /**
137      
138       * @Title: getInsertSql
139       * @Description: TODO(根据实体类对象字段的值生成INSERT SQL语句,可选固定参数)
140       * @param @param obj
141       * @param @param fixedParams
142       *        固定参数(如该参数与实体类中有相同的字段,则忽略实体类中的对应字段,HashMap<String
143       *        ,String>,key=指定字段名,value=对应字段的值)
144       * @param @return 设定文件
145       * @return String 返回类型
146       * @throws
147       */
148      public static String getInsertSql(Object obj,
149              HashMap<String, String> fixedParams) {
150          String insertSql = null ;
151          String tableName = getTableName(obj);
152          if (tableName != null ) {
153              StringBuffer sqlStr = new StringBuffer( "INSERT INTO " );
154              StringBuffer valueStr = new StringBuffer( " VALUES (" );
155              List<Field> annoFieldList = getAnnoFieldList(obj);
156              if (annoFieldList != null && annoFieldList.size() > 0 ) {
157                  sqlStr.append(tableName + " (" );
158                  if (fixedParams != null && fixedParams.size() > 0 ) {
159                      Iterator<String> keyNames = fixedParams.keySet().iterator();
160                      while (keyNames.hasNext()) {
161                          String keyName = (String) keyNames.next();
162                          sqlStr.append(keyName + "," );
163                          valueStr.append(fixedParams.get(keyName) + "," );
164                      }
165                  }
166                  for (Field field : annoFieldList) {
167                      FieldAnnotation anno = field
168                              .getAnnotation(FieldAnnotation. class );
169                      if (!anno.pk()) {
170                          Object fieldValue = getFieldValue(obj, field);
171                          if (fieldValue != null ) {
172                              if (fixedParams != null && fixedParams.size() > 0 ) {
173                                  Iterator<String> keyNames = fixedParams
174                                          .keySet().iterator();
175                                  boolean nextFieldFlag = false ;
176                                  while (keyNames.hasNext()) {
177                                      String keyName = (String) keyNames.next();
178                                      if (anno.fieldName().equals(keyName)) {
179                                          nextFieldFlag = true ;
180                                          break ;
181                                      }
182                                  }
183                                  if (nextFieldFlag) {
184                                      break ;
185                                  }
186                              }
187                              sqlStr.append(anno.fieldName() + "," );
188                              switch (anno.fieldType()) {
189                              case NUMBER:
190                                  valueStr.append(fieldValue + "," );
191                                  break ;
192                              default :
193                                  valueStr.append( "'" + fieldValue + "'," );
194                                  break ;
195                              }
196                          }
197                      }
198                  }
199                  insertSql = sqlStr.toString().substring( 0 , sqlStr.length() - 1 )
200                          + ")"
201                          + valueStr.toString().substring( 0 ,
202                                  valueStr.length() - 1 ) + ")" ;
203              }
204          }
205          return insertSql;
206      }
207    
208      /**
209      
210       * @Title: getInsertSql
211       * @Description: TODO(根据实体类对象字段的值生成INSERT SQL语句)
212       * @param @param obj
213       * @param @return 设定文件
214       * @return String 返回类型
215       * @throws
216       */
217      public static String getInsertSql(Object obj) {
218          return getInsertSql(obj, null );
219      }
220    
221      /**
222      
223       * @Title: getUpdateSql
224       * @Description: TODO(根据实体类对象字段的值生成UPDATE SQL语句,可选更新条件为主键,可选固定更新参数)
225       * @param @param obj
226       * @param @param reqPk 是否指定更新条件为主键(true=是,false=否)
227       * @param @param fixedParams
228       *        固定参数(如该参数与实体类中有相同的字段,则忽略实体类中的对应字段,HashMap<String
229       *        ,String>,key=指定字段名,value=对应字段的值)
230       * @param @return 设定文件
231       * @return String 返回类型
232       * @throws
233       */
234      public static String getUpdateSql(Object obj, boolean reqPk,
235              HashMap<String, String> fixedParams) {
236          String updateSql = null ;
237          String tableName = getTableName(obj);
238          if (tableName != null ) {
239              List<Field> annoFieldList = getAnnoFieldList(obj);
240              if (annoFieldList != null && annoFieldList.size() > 0 ) {
241                  StringBuffer sqlStr = new StringBuffer( "UPDATE " + tableName);
242                  StringBuffer valueStr = new StringBuffer( " SET " );
243                  String whereStr = " WHERE " ;
244                  if (fixedParams != null && fixedParams.size() > 0 ) {
245                      Iterator<String> keyNames = fixedParams.keySet().iterator();
246                      while (keyNames.hasNext()) {
247                          String keyName = (String) keyNames.next();
248                          valueStr.append(keyName + "="
249                                  + fixedParams.get(keyName) + "," );
250                      }
251                  }
252                  for (Field field : annoFieldList) {
253                      String fieldValue = getFieldValue(obj, field);
254                      if (fieldValue != null ) {
255                          FieldAnnotation anno = field
256                                  .getAnnotation(FieldAnnotation. class );
257                          if (!anno.pk()) {
258                              if (fixedParams != null && fixedParams.size() > 0 ) {
259                                  boolean nextFieldFlag = false ;
260                                  Iterator<String> keyNames = fixedParams
261                                          .keySet().iterator();
262                                  while (keyNames.hasNext()) {
263                                      String keyName = (String) keyNames.next();
264                                      if (anno.fieldName().equals(keyName)) {
265                                          nextFieldFlag = true ;
266                                          break ;
267                                      }
268                                  }
269                                  if (nextFieldFlag) {
270                                      break ;
271                                  }
272                              }
273                              valueStr.append(anno.fieldName() + "=" );
274                              switch (anno.fieldType()) {
275                              case NUMBER:
276                                  valueStr.append(fieldValue + "," );
277                                  break ;
278                              default :
279                                  valueStr.append( "'" + fieldValue + "'," );
280                                  break ;
281                              }
282                          } else {
283                              if (reqPk) {
284                                  whereStr += anno.fieldName() + "=" + fieldValue;
285                              }
286                          }
287                      }
288                  }
289                  updateSql = sqlStr.toString()
290                          + valueStr.toString().substring( 0 ,
291                                  valueStr.length() - 1 )
292                          + (reqPk ? whereStr : "" );
293              }
294          }
295          return updateSql;
296      }
297    
298      /**
299      
300       * @Title: getUpdateSql
301       * @Description: TODO(根据实体类对象字段的值生成UPDATE SQL语句,无条件)
302       * @param @param obj
303       * @param @return 设定文件
304       * @return String 返回类型
305       * @throws
306       */
307      public static String getUpdateSql(Object obj) {
308          return getUpdateSql(obj, false , null );
309      }
310    
311      /**
312      
313       * @Title: getUpdateSql
314       * @Description: TODO(根据实体类对象字段的值生成UPDATE SQL语句,可选更新条件为主键)
315       * @param @param obj
316       * @param @param reqPk 是否指定更新条件为主键(true=是,false=否)
317       * @param @return 设定文件
318       * @return String 返回类型
319       * @throws
320       */
321      public static String getUpdateSql(Object obj, boolean reqPk) {
322          return getUpdateSql(obj, reqPk, null );
323      }
324    
325      /**
326      
327       * @Title: getDeleteSql
328       * @Description: TODO(根据实体类对象字段的值生成有条件的DELETE
329       *               SQL语句,可选主键为删除条件或使用各个字段的值为条件,多个条件用AND连接)
330       * @param @param obj
331       * @param @param reqPk 是否指定更新条件为主键(true=是,false=否)
332       * @param @return 设定文件
333       * @return String 返回类型
334       * @throws
335       */
336      public static String getDeleteSql(Object obj, boolean reqPk) {
337          String deleteSql = null ;
338          String tableName = getTableName(obj);
339          if (tableName != null ) {
340              StringBuffer delSqlBuffer = new StringBuffer( "DELETE FROM " );
341              List<Field> annoFieldList = getAnnoFieldList(obj);
342              if (annoFieldList != null && annoFieldList.size() > 0 ) {
343                  delSqlBuffer.append(tableName + " WHERE " );
344                  for (Field field : annoFieldList) {
345                      if (reqPk) {
346                          FieldAnnotation anno = field
347                                  .getAnnotation(FieldAnnotation. class );
348                          if (anno.pk()) {
349                              String fieldValue = getFieldValue(obj, field);
350                              delSqlBuffer.append(anno.fieldName() + "=" );
351                              switch (anno.fieldType()) {
352                              case NUMBER:
353                                  delSqlBuffer.append(fieldValue);
354                                  break ;
355                              default :
356                                  delSqlBuffer.append( "'" + fieldValue + "'" );
357                                  break ;
358                              }
359                              break ;
360                          }
361                      } else {
362                          String fieldValue = getFieldValue(obj, field);
363                          if (fieldValue != null ) {
364                              FieldAnnotation anno = field
365                                      .getAnnotation(FieldAnnotation. class );
366                              delSqlBuffer.append(anno.fieldName() + "=" );
367                              switch (anno.fieldType()) {
368                              case NUMBER:
369                                  delSqlBuffer.append(fieldValue + " AND " );
370                                  break ;
371                              default :
372                                  delSqlBuffer
373                                          .append( "'" + fieldValue + "' AND " );
374                                  break ;
375                              }
376                          }
377                      }
378                  }
379                  if (reqPk) {
380                      deleteSql = delSqlBuffer.toString();
381                  } else {
382                      deleteSql = delSqlBuffer.toString().substring( 0 ,
383                              delSqlBuffer.length() - 5 );
384                  }
385              }
386          }
387          return deleteSql;
388      }
389    
390      /**
391      
392       * @Title: getDeleteSql
393       * @Description: TODO(根据实体类对象字段的值生成有条件的DELETE SQL语句,使用各个字段的值为条件,多个条件用AND连接)
394       * @param @param obj
395       * @param @return 设定文件
396       * @return String 返回类型
397       * @throws
398       */
399      public static String getDeleteSql(Object obj) {
400          return getDeleteSql(obj, false );
401      }
402    
403      /**
404      
405       * @Title: getSelectAllSql
406       * @Description: TODO(根据实体类对象字段的值生成SELECT SQL语句,无查询条件)
407       * @param @param obj
408       * @param @return 设定文件
409       * @return String 返回类型
410       * @throws
411       */
412      public static String getSelectAllSql(Object obj) {
413          String selectSql = null ;
414          String tableName = getTableName(obj);
415          if (tableName != null ) {
416              StringBuffer selectBuffer = new StringBuffer( "SELECT " );
417              List<Field> annoFieldList = getAnnoFieldList(obj);
418              if (annoFieldList != null && annoFieldList.size() > 0 ) {
419                  for (Field field : annoFieldList) {
420                      FieldAnnotation anno = field
421                              .getAnnotation(FieldAnnotation. class );
422                      selectBuffer.append(anno.fieldName() + "," );
423                  }
424                  selectSql = selectBuffer.toString().substring( 0 ,
425                          selectBuffer.length() - 1 )
426                          + " FROM " + tableName;
427              }
428          }
429          return selectSql;
430      }
431 }
实体类注释写法:
01 package net.tjnwdseip.entity;
02    
03 import java.sql.Timestamp;
04    
05 import net.tjnwdseip.util.FieldAnnotation;
06 import net.tjnwdseip.util.FieldType;
07    
08 public class BaseEntity {
09    
10      @FieldAnnotation (fieldName= "id" ,fieldType=FieldType.NUMBER,pk= true )
11      private Integer id;
12        
13      @FieldAnnotation (fieldName= "createDate" ,fieldType=FieldType.DATE, pk = false )
14      private Timestamp createDate;
15        
16      @FieldAnnotation (fieldName= "modifyDate" ,fieldType=FieldType.DATE, pk = false )
17      private Timestamp modifyDate;
18    
19      public Integer getId() {
20          return id;
21      }
22    
23      public void setId(Integer id) {
24          this .id = id;
25      }
26    
27      public Timestamp getCreateDate() {
28          return createDate;
29      }
30    
31      public void setCreateDate(Timestamp createDate) {
32          this .createDate = createDate;
33      }
34    
35      public Timestamp getModifyDate() {
36          return modifyDate;
37      }
38    
39      public void setModifyDate(Timestamp modifyDate) {
40          this .modifyDate = modifyDate;
41      }
42    
43      public BaseEntity(Integer id, Timestamp createDate, Timestamp modifyDate) {
44          super ();
45          this .id = id;
46          this .createDate = createDate;
47          this .modifyDate = modifyDate;
48      }
49    
50      public BaseEntity() {
51          super ();
52      }
53 }
01 package net.tjnwdseip.entity;
02    
03 import java.sql.Timestamp;
04    
05 import net.tjnwdseip.util.FieldAnnotation;
06 import net.tjnwdseip.util.FieldType;
07 import net.tjnwdseip.util.TableAnnotation;
08 /**
09  
10   * @ClassName: SysNetProxyCfg 
11   * @Description: TODO(网络代理设置) 
12   * <A class=referer href="http://my.oschina.net/arthor" target=_blank>@author</A>  LiYang 
13   * @date 2012-5-2 下午4:13:08 
14   *
15   */
16 @TableAnnotation (tableName= "sysNetProxyCfg" )
17 public class SysNetProxyCfg extends BaseEntity {
18    
19      @FieldAnnotation (fieldName = "name" , fieldType = FieldType.STRING, pk = false )
20      private String name;
21        
22      @FieldAnnotation (fieldName = "type" , fieldType = FieldType.STRING, pk = false )
23      private String type;
24        
25      @FieldAnnotation (fieldName = "proxyHostIp" , fieldType = FieldType.STRING, pk = false )
26      private String proxyHostIp;
27        
28      @FieldAnnotation (fieldName = "proxyPort" , fieldType = FieldType.NUMBER, pk = false )
29      private Integer proxyPort;
30    
31      public String getName() {
32          return name;
33      }
34    
35      public void setName(String name) {
36          this .name = name;
37      }
38    
39      public String getType() {
40          return type;
41      }
42    
43      public void setType(String type) {
44          this .type = type;
45      }
46    
47      public String getProxyHostIp() {
48          return proxyHostIp;
49      }
50    
51      public void setProxyHostIp(String proxyHostIp) {
52          this .proxyHostIp = proxyHostIp;
53      }
54    
55      public Integer getProxyPort() {
56          return proxyPort;
57      }
58    
59      public void setProxyPort(Integer proxyPort) {
60          this .proxyPort = proxyPort;
61      }
62    
63      public SysNetProxyCfg(Integer id, Timestamp createDate,
64              Timestamp modifyDate, String name, String type, String proxyHostIp,
65              Integer proxyPort) {
66          super (id, createDate, modifyDate);
67          this .name = name;
68          this .type = type;
69          this .proxyHostIp = proxyHostIp;
70          this .proxyPort = proxyPort;
71      }
72    
73      public SysNetProxyCfg() {
74          super ();
75      }
76 }
测试类:
01 package net.tjnwdseip.demo;
02    
03 import java.sql.Timestamp;
04 import java.util.HashMap;
05    
06 import net.tjnwdseip.entity.SysNetProxyCfg;
07 import net.tjnwdseip.util.CreateSqlTools;
08    
09 public class DemoTest {
10    
11        
12      public static void main(String[] args) {
13          // TODO Auto-generated method stub
14          SysNetProxyCfg netProxyCfg = new SysNetProxyCfg( 1 , Timestamp.valueOf( "2012-05-04 14:45:35" ), null , "netProxyCfgName" , "netProxyCfgType" , "000.000.000.000" , 0 );
15          HashMap<String, String> fixedParams= new HashMap<String,String>();
16          fixedParams.put( "createDate" , "NOW()" );
17          fixedParams.put( "modifyDate" , "NOW()" );
18          System.out.println(CreateSqlTools.getDeleteSql(netProxyCfg));
19          System.out.println(CreateSqlTools.getDeleteSql(netProxyCfg, true ));
20          System.out.println(CreateSqlTools.getInsertSql(netProxyCfg));
21          System.out.println(CreateSqlTools.getInsertSql(netProxyCfg, fixedParams));
22          System.out.println(CreateSqlTools.getSelectAllSql(netProxyCfg));
23          System.out.println(CreateSqlTools.getUpdateSql(netProxyCfg));
24          System.out.println(CreateSqlTools.getUpdateSql(netProxyCfg, true ));
25          System.out.println(CreateSqlTools.getUpdateSql(netProxyCfg, true , fixedParams));
26      }
27    
28 }
测试结果:
1 DELETE FROM sysNetProxyCfg WHERE id=1 AND createDate= '2012-05-04 14:45:35.0' AND name = 'netProxyCfgName' AND type= 'netProxyCfgType' AND proxyHostIp= '000.000.000.000' AND proxyPort=0
2 DELETE FROM sysNetProxyCfg WHERE id=1
3 INSERT INTO sysNetProxyCfg (createDate, name ,type,proxyHostIp,proxyPort) VALUES ( '2012-05-04 14:45:35.0' , 'netProxyCfgName' , 'netProxyCfgType' , '000.000.000.000' ,0)
4 INSERT INTO sysNetProxyCfg (modifyDate,createDate) VALUES (NOW(),NOW())
5 SELECT id,createDate,modifyDate, name ,type,proxyHostIp,proxyPort FROM sysNetProxyCfg
6 UPDATE sysNetProxyCfg SET createDate= '2012-05-04 14:45:35.0' , name = 'netProxyCfgName' ,type= 'netProxyCfgType' ,proxyHostIp= '000.000.000.000' ,proxyPort=0
7 UPDATE sysNetProxyCfg SET createDate= '2012-05-04 14:45:35.0' , name = 'netProxyCfgName' ,type= 'netProxyCfgType' ,proxyHostIp= '000.000.000.000' ,proxyPort=0 WHERE id=1
8 UPDATE sysNetProxyCfg SET modifyDate=NOW(),createDate=NOW() WHERE id=1
分享到:
评论

相关推荐

    实体类SQL语句生成器

    实体类SQL语句生成器是一种高效工具,它能够自动化地根据数据库结构自动生成对应的C#实体类和SQL操作语句。这种工具极大地提高了开发效率,减少了手动编写代码的工作量,尤其是在处理大型数据库时,它的价值更为明显...

    实体+SQL语句生成器

    4. 生成代码:工具将自动分析数据库结构,生成对应的实体类代码和SQL语句,可以直接复制到项目中使用。 "ModelGenerate.exe"可能是这个生成器的执行文件,用户只需运行这个程序,按照界面提示操作,就能完成代码...

    一个自动生成实体类和SQL语句的工具 1.2.1版

    为了解决这个问题,存在许多自动化工具,其中一个便是“一个自动生成实体类和SQL语句的工具 1.2.1版”。这个工具的主要目的是提高开发效率,减少手动编写代码的工作量,确保代码的一致性和准确性。 首先,我们来...

    mybatis根据数据库表自动生成SQL、实体类、mapper文件工具

    "mybatis根据数据库表自动生成SQL、实体类、mapper文件工具"就是这样一个解决方案,它基于Eclipse集成开发环境,特别适用于使用SSM(Spring、SpringMVC、MyBatis)框架的项目。 首先,MyBatis是一个优秀的持久层...

    一个自动生成实体类和SQL语句的工具 1.1版

    【标题】:“一个自动生成实体类和SQL语句的工具 1.1版”是一个针对软件开发中的数据库操作优化的实用工具。它旨在提高开发效率,通过自动化的方式生成与数据库表结构对应的实体类代码,同时还能自动生成相应的SQL...

    根据SQLServer数据表生成C#实体类。生成数据库模型.zip

    本压缩包"根据SQLServer数据表生成C#实体类"提供了相关的工具和源码,旨在帮助开发者快速创建与数据库表结构相对应的C#类。SQLHelper是一个常见的辅助类,用于简化SQL操作,避免了大量的硬编码SQL语句,使得数据库...

    实体类代码生成器

    实体类代码生成器是一种开发工具,它主要用于自动化创建C#编程语言中的实体类代码。实体类在软件开发中扮演着重要角色,它们是业务逻辑层和数据访问层之间的桥梁,通常用于封装数据库表或API响应的数据结构。使用...

    C# .net数据库表实体类生成,一键生成数据库所有表的实体类

    在.NET开发环境中,Entity Framework(简称EF)是一个强大的对象关系映射(ORM)框架,它允许开发者使用C#或VB.NET等高级语言来操作数据库,而无需直接编写SQL语句。然而,在.NET Core中,虽然EF Core提供了模型构建...

    动软实体类自动生成工具

    通过自动生成的实体类,开发者可以直接操作对象属性,而无需关心底层的SQL语句,提高了开发效率和代码的可读性。 压缩包中的"实体类生成工具.exe"文件应该是这个工具的可执行程序,下载并运行它,你就可以开始体验...

    c#实体类生成工具

    为了解决这个问题,"C#实体类生成工具"应运而生,它能够根据数据库中的数据表自动生成对应的C#实体类文件,极大地提高了开发效率。 实体类是对象-关系映射(ORM)的基础,它将数据库中的表映射为程序中的类,每个...

    Maven插件源码:根据库表生成实体类&根据实体类生成库表

    总结来说,"Maven插件源码:根据库表生成实体类&根据实体类生成库表"是一个高效且实用的开发工具,它整合了数据库与Java代码的自动化生成,提高了开发效率,降低了错误的可能性。对于大型项目或频繁迭代的系统,这样...

    实体类生成工具源代码

    通过实体类,开发者可以以面向对象的方式来操作数据库,无需直接编写SQL语句,使得代码更加简洁、易于维护。 该工具的工作原理大致如下: 1. **连接数据库**:首先,工具需要连接到SQL Server数据库,这通常需要...

    mybatis反向生成工具+注释.zip

    在开发过程中,通过MyBatis的反向生成工具,我们可以快速地根据数据库表结构自动生成对应的Java实体类、Mapper接口及XML配置文件,极大地提高了开发效率。本压缩包“mybatis反向生成工具+注释.zip”提供了这样一个...

    java从数据库表反射出实体类,自动生成实体类

    根据提供的文件信息,我们可以深入探讨如何使用Java编程语言来实现从数据库表中自动反射并生成实体类的功能。这种技术在实际开发中非常有用,尤其是在快速搭建项目基础结构时,能够大大减少手动编码的工作量。 ### ...

    实体类生成工具

    3. **定制化选项**:高质量的实体类生成工具通常会提供一定的定制选项,允许用户根据项目需求调整生成的代码风格,比如是否生成注释、是否启用Lombok库进行无参构造函数、equals()、hashCode()等方法的生成。...

    mybatis逆向生成实体类工具

    5. **整合到项目**:将生成的文件导入到你的项目中,然后就可以在MyBatis的Mapper接口中使用这些实体类和XML映射文件来执行SQL语句。 标签 "generatorConfig" 指出这是关于配置文件的讨论,"mybatis" 明确了是...

    generator-mysql根据mysql数据库生成实体类并“生成注释”

    这个工具的亮点在于它不仅生成实体类,还能够生成字段的注释,这对于理解和维护代码非常有帮助。 `generator-mybatis`是一个强大的代码生成器,它遵循MyBatis的配置方式,允许开发者自定义生成规则。`generator-...

    mybatis实体类反向生成

    "mybatis实体类反向生成"是指利用特定工具,根据数据库中的表结构自动生成对应的Java实体类以及MyBatis的映射文件(XML配置文件),这一过程极大地提高了开发效率,减少了手动编写这些基础代码的工作量。 1. **...

    SQL Server实体类生成器

    标题中的“SQL Server实体类生成器”是一个工具,主要用于帮助开发者自动从SQL Server数据库中的表结构生成对应的C#实体类。这种工具极大地提高了开发效率,因为它省去了手动编写这些类的繁琐过程。实体类在对象关系...

    数据库表一键生成实体类豪华版工具.rar

    实体类是ORM(对象关系映射)框架的基础,如Hibernate或Entity Framework,它们允许开发者用对象的方式来操作数据库,而无需直接编写SQL语句。 该“豪华版20180308”工具可能包含了以下功能: 1. **多数据库支持**...

Global site tag (gtag.js) - Google Analytics