Commit 0e69ee74 by bianpeng

2.0.0

parent 434266a5
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.github</groupId> <groupId>com.github.flying-cattle</groupId>
<artifactId>mybatis-dsc-generator</artifactId> <artifactId>mybatis-dsc-generator</artifactId>
<version>1.1.6.RELEASE</version> <version>2.0.0.RELEASE</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>mybatis-dsc-generator</name> <name>mybatis-dsc-generator</name>
......
...@@ -51,6 +51,10 @@ public class BasisInfo implements Serializable{ ...@@ -51,6 +51,10 @@ public class BasisInfo implements Serializable{
private String controllerUrl; private String controllerUrl;
private String idType;
private String idJdbcType;
private List<PropertyInfo> cis; private List<PropertyInfo> cis;
public BasisInfo(String project, String author, String version, String dbUrl, String dbName, String dbPassword, public BasisInfo(String project, String author, String version, String dbUrl, String dbName, String dbPassword,
......
...@@ -10,27 +10,27 @@ import com.github.mybatis.util.MySqlToJavaUtil; ...@@ -10,27 +10,27 @@ import com.github.mybatis.util.MySqlToJavaUtil;
public class TestMain { public class TestMain {
//基础信息 //基础信息
public static final String PROJECT="deal-center"; public static final String PROJECT="qixingbao-show";
public static final String AUTHOR="BianP"; public static final String AUTHOR="BianP";
public static final String VERSION="V1.0"; public static final String VERSION="V1.0";
//数据库连接信息 //数据库连接信息
public static final String URL="jdbc:mysql://127.0.0.1:3306/xin?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=true"; public static final String URL="jdbc:mysql://127.0.0.1:3306/qixingbao?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=true";
public static final String NAME="root"; public static final String NAME="root";
public static final String PASSWORD="123456"; public static final String PASSWORD="123456";
public static final String DATABASE="xin"; public static final String DATABASE="qixingbao";
//类信息 //类信息
public static final String TABLE="user"; public static final String TABLE="product";
public static final String CLASSNAME="User"; public static final String CLASSNAME="Product";
public static final String CLASSCOMMENT="用户信息"; public static final String CLASSCOMMENT="产品";
public static final String TIME="2018年6月30日"; public static final String TIME="2018年7月5日";
public static final String AGILE=new Date().getTime()+""; public static final String AGILE=new Date().getTime()+"";
//路径信息 //路径信息
public static final String ENTITY_URL="com.xin.dealcenter.entity"; public static final String ENTITY_URL="com.qixingbao.show.entity";
public static final String DAO_URL="com.xin.dealcenter.dao"; public static final String DAO_URL="com.qixingbao.show.dao";
public static final String XML_URL="com.xin.dealcenter.dao.impl"; public static final String XML_URL="com.qixingbao.show.dao.impl";
public static final String SERVICE_URL="com.xin.dealcenter.service"; public static final String SERVICE_URL="com.qixingbao.show.service";
public static final String SERVICE_IMPL_URL="com.xin.dealcenter.service.impl"; public static final String SERVICE_IMPL_URL="com.qixingbao.show.service.impl";
public static final String CONTROLLER_URL="com.xin.dealcenter.webApi"; public static final String CONTROLLER_URL="com.qixingbao.show.webApi";
public static void main(String[] args) { public static void main(String[] args) {
...@@ -41,19 +41,19 @@ public class TestMain { ...@@ -41,19 +41,19 @@ public class TestMain {
bi.setEntityComment(CLASSCOMMENT); bi.setEntityComment(CLASSCOMMENT);
try { try {
bi=EntityInfoUtil.getInfo(bi); bi=EntityInfoUtil.getInfo(bi);
String aa1=Generator.createEntity("E:\\test_workspace\\mybatis-generator\\src\\main\\java\\", bi).toString(); String aa1=Generator.createEntity("E:\\A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show\\src\\main\\java\\", bi).toString();
/*String aa2=Generator.createDao("E:\\test_workspace\\mybatis-generator\\src\\main\\java\\", bi).toString(); String aa2=Generator.createDao("E:\\A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show\\src\\main\\java\\", bi).toString();
String aa3=Generator.createDaoImpl("E:\\test_workspace\\mybatis-generator\\src\\main\\java\\", bi).toString(); String aa3=Generator.createDaoImpl("E:\\A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show\\src\\main\\java\\", bi).toString();
String aa4=Generator.createService("E:\\test_workspace\\mybatis-generator\\src\\main\\java\\", bi).toString(); String aa4=Generator.createService("E:\\A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show\\src\\main\\java\\", bi).toString();
String aa5=Generator.createServiceImpl("E:\\test_workspace\\mybatis-generator\\src\\main\\java\\", bi).toString(); String aa5=Generator.createServiceImpl("E:\\A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show\\src\\main\\java\\", bi).toString();
String aa6=Generator.createController("E:\\test_workspace\\mybatis-generator\\src\\main\\java\\", bi).toString();*/ String aa6=Generator.createController("E:\\A-ZM-work\\work_qxb2\\qxbplatform\\qixingbao-show\\src\\main\\java\\", bi).toString();
System.out.println(aa1); System.out.println(aa1);
/*System.out.println(aa2); System.out.println(aa2);
System.out.println(aa3); System.out.println(aa3);
System.out.println(aa4); System.out.println(aa4);
System.out.println(aa5); System.out.println(aa5);
System.out.println(aa6);*/ System.out.println(aa6);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -29,19 +29,27 @@ public class EntityInfoUtil { ...@@ -29,19 +29,27 @@ public class EntityInfoUtil {
String comment = executeQuery.getString(3); String comment = executeQuery.getString(3);
PropertyInfo ci=new PropertyInfo(); PropertyInfo ci=new PropertyInfo();
ci.setColumn(column); ci.setColumn(column);
if (jdbcType.equals("int")) { if (jdbcType.equalsIgnoreCase("int")) {
ci.setJdbcType("Integer"); ci.setJdbcType("Integer");
}else if (jdbcType.equalsIgnoreCase("datetime")) {
ci.setJdbcType("timestamp");
}else { }else {
ci.setJdbcType(jdbcType); ci.setJdbcType(jdbcType);
} }
ci.setComment(comment); ci.setComment(comment);
ci.setProperty(MySqlToJavaUtil.changeToJavaFiled(column)); ci.setProperty(MySqlToJavaUtil.changeToJavaFiled(column));
ci.setJavaType(MySqlToJavaUtil.jdbcTypeToJavaType(jdbcType)); ci.setJavaType(MySqlToJavaUtil.jdbcTypeToJavaType(jdbcType));
//设置注解类型
if (column.equalsIgnoreCase("id")) {
bi.setIdType(ci.getJavaType());
bi.setIdJdbcType(ci.getJdbcType());
}
columns.add(ci); columns.add(ci);
} }
bi.setCis(columns); bi.setCis(columns);
return bi; return bi;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("自动生成实体类错误:"+e.getMessage()); throw new RuntimeException("自动生成实体类错误:"+e.getMessage());
} finally { } finally {
pstemt.close(); pstemt.close();
......
...@@ -55,8 +55,8 @@ public class ${entityName}Controller { ...@@ -55,8 +55,8 @@ public class ${entityName}Controller {
*/ */
@GetMapping("/get${entityName}ById/{id}") @GetMapping("/get${entityName}ById/{id}")
@ApiOperation(value = "获取${entityComment}信息", notes = "获取${entityComment}信息[${objectName}],作者:${author}") @ApiOperation(value = "获取${entityComment}信息", notes = "获取${entityComment}信息[${objectName}],作者:${author}")
@ApiImplicitParam(paramType="path", name = "id", value = "${entityComment}id", required = true, dataType = "Long") @ApiImplicitParam(paramType="path", name = "id", value = "${entityComment}id", required = true, dataType = "${idType}")
public JsonResult<${entityName}> get${entityName}ById(@PathVariable("id")Long id){ public JsonResult<${entityName}> get${entityName}ById(@PathVariable("id")${idType} id){
JsonResult<${entityName}> result=new JsonResult<${entityName}>(); JsonResult<${entityName}> result=new JsonResult<${entityName}>();
try { try {
${entityName} ${objectName}=${objectName}ServiceImpl.selectByPrimaryKey(id); ${entityName} ${objectName}=${objectName}ServiceImpl.selectByPrimaryKey(id);
...@@ -116,9 +116,9 @@ public class ${entityName}Controller { ...@@ -116,9 +116,9 @@ public class ${entityName}Controller {
*/ */
@PostMapping("/deleteByPrimaryKey") @PostMapping("/deleteByPrimaryKey")
@ApiOperation(value = "删除${entityComment}", notes = "删除${entityComment},作者:${author}") @ApiOperation(value = "删除${entityComment}", notes = "删除${entityComment},作者:${author}")
@ApiImplicitParam(paramType="query", name = "id", value = "${entityComment}id", required = true, dataType = "Long") @ApiImplicitParam(paramType="query", name = "id", value = "${entityComment}id", required = true, dataType = "${idType}")
public JsonResult deleteByPrimaryKey(Long id){ public JsonResult<Object> deleteByPrimaryKey(${idType} id){
JsonResult result=new JsonResult(); JsonResult<Object> result=new JsonResult<Object>();
try { try {
int reg=${objectName}ServiceImpl.deleteByPrimaryKey(id); int reg=${objectName}ServiceImpl.deleteByPrimaryKey(id);
if (reg>0) { if (reg>0) {
...@@ -177,8 +177,8 @@ public class ${entityName}Controller { ...@@ -177,8 +177,8 @@ public class ${entityName}Controller {
*/ */
@ApiOperation(value = "条件查询${entityComment}", notes = "条件查询[${objectName}],作者:${author}") @ApiOperation(value = "条件查询${entityComment}", notes = "条件查询[${objectName}],作者:${author}")
@PostMapping("/query${entityName}List") @PostMapping("/query${entityName}List")
public JsonResult<${entityName}> query${entityName}List(${entityName} ${objectName}){ public JsonResult<List<${entityName}>> query${entityName}List(${entityName} ${objectName}){
JsonResult<${entityName}> result=new JsonResult<${entityName}>(); JsonResult<List<${entityName}>> result=new JsonResult<List<${entityName}>>();
try { try {
List<${entityName}> list = ${objectName}ServiceImpl.query${entityName}List(${objectName}); List<${entityName}> list = ${objectName}ServiceImpl.query${entityName}List(${objectName});
result.setCode(1); result.setCode(1);
...@@ -205,8 +205,8 @@ public class ${entityName}Controller { ...@@ -205,8 +205,8 @@ public class ${entityName}Controller {
@ApiImplicitParam(paramType="query", name = "pageNum", value = "当前页", required = true, dataType = "int"), @ApiImplicitParam(paramType="query", name = "pageNum", value = "当前页", required = true, dataType = "int"),
@ApiImplicitParam(paramType="query", name = "pageSize", value = "页行数", required = true, dataType = "int") @ApiImplicitParam(paramType="query", name = "pageSize", value = "页行数", required = true, dataType = "int")
}) })
public JsonResult<${entityName}> get${entityName}BySearch(Integer pageNum,Integer pageSize){ public JsonResult<PageInfo<${entityName}>> get${entityName}BySearch(Integer pageNum,Integer pageSize){
JsonResult<${entityName}> result=new JsonResult<${entityName}>(); JsonResult<PageInfo<${entityName}>> result=new JsonResult<PageInfo<${entityName}>>();
AppPage<${entityName}> page =new AppPage<${entityName}>(); AppPage<${entityName}> page =new AppPage<${entityName}>();
page.setPageNum(pageNum); page.setPageNum(pageNum);
page.setPageSize(pageSize); page.setPageSize(pageSize);
......
...@@ -21,9 +21,9 @@ import ${entityUrl}.${entityName}; ...@@ -21,9 +21,9 @@ import ${entityUrl}.${entityName};
@Mapper @Mapper
public interface ${entityName}Dao { public interface ${entityName}Dao {
public ${entityName} selectByPrimaryKey(Long id); public ${entityName} selectByPrimaryKey(${idType} id);
public int deleteByPrimaryKey(Long id); public int deleteByPrimaryKey(${idType} id);
public int insertSelective(${entityName} ${objectName}); public int insertSelective(${entityName} ${objectName});
......
...@@ -10,21 +10,21 @@ ...@@ -10,21 +10,21 @@
${agile} ${agile}
</sql> </sql>
<!-- 查询 --> <!-- 查询 -->
<select id="selectByPrimaryKey" parameterType="java.lang.Long" <select id="selectByPrimaryKey" parameterType="java.lang.${idType}"
resultMap="BaseResultMap"> resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from ${table} from ${table}
where id = ${r'#{id,jdbcType=BIGINT}'} where id = ${r'#{'}id,jdbcType=${idJdbcType?upper_case}}
</select> </select>
<!-- 删除 --> <!-- 删除 -->
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> <delete id="deleteByPrimaryKey" parameterType="java.lang.${idType}">
delete from ${table} delete from ${table}
where id = ${r'#{id,jdbcType=BIGINT}'} where id = ${r'#{'}id,jdbcType=${idJdbcType?upper_case}}
</delete> </delete>
<!-- 选择添加 --> <!-- 选择添加 -->
<insert id="insertSelective" parameterType="${entityUrl}.${entityName}"> <insert id="insertSelective" parameterType="${entityUrl}.${entityName}">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.${idType}">
SELECT SELECT
LAST_INSERT_ID() LAST_INSERT_ID()
</selectKey> </selectKey>
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</if> </if>
</#list> </#list>
</set> </set>
where id = ${r'#{id,jdbcType=BIGINT}'} where id = ${r'#{'}id,jdbcType=${idJdbcType}}
</update> </update>
<!-- 组合条件查询 --> <!-- 组合条件查询 -->
<select id="query${entityName}List" parameterType="${entityUrl}.${entityName}" <select id="query${entityName}List" parameterType="${entityUrl}.${entityName}"
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
from ${table} from ${table}
<where> <where>
<if test="id != null"> <if test="id != null">
id = ${r'#{'}id,jdbcType=BIGINT} id = ${r'#{'}id,jdbcType=${idJdbcType?upper_case}}
</if> </if>
<#list cis as ci> <#list cis as ci>
<#if ci.column!="id"> <#if ci.column!="id">
......
...@@ -27,7 +27,7 @@ public interface ${entityName}Service { ...@@ -27,7 +27,7 @@ public interface ${entityName}Service {
* @return ${entityName} * @return ${entityName}
* @author ${author} * @author ${author}
*/ */
public ${entityName} selectByPrimaryKey(Long id); public ${entityName} selectByPrimaryKey(${idType} id);
/** /**
* @explain 删除${entityComment}对象 * @explain 删除${entityComment}对象
...@@ -35,7 +35,7 @@ public interface ${entityName}Service { ...@@ -35,7 +35,7 @@ public interface ${entityName}Service {
* @return int * @return int
* @author ${author} * @author ${author}
*/ */
public int deleteByPrimaryKey(Long id); public int deleteByPrimaryKey(${idType} id);
/** /**
* @explain 添加${entityComment}对象 * @explain 添加${entityComment}对象
......
...@@ -34,13 +34,13 @@ public class ${entityName}ServiceImpl implements ${entityName}Service { ...@@ -34,13 +34,13 @@ public class ${entityName}ServiceImpl implements ${entityName}Service {
//查询对象 //查询对象
@Override @Override
public ${entityName} selectByPrimaryKey(Long id) { public ${entityName} selectByPrimaryKey(${idType} id) {
return ${objectName}Dao.selectByPrimaryKey(id); return ${objectName}Dao.selectByPrimaryKey(id);
} }
//删除对象 //删除对象
@Override @Override
public int deleteByPrimaryKey(Long id) { public int deleteByPrimaryKey(${idType} id) {
return ${objectName}Dao.deleteByPrimaryKey(id); return ${objectName}Dao.deleteByPrimaryKey(id);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment