第一步,在“解決方案JavaGenerate”中添加類庫,用於存放控制層的模版及相應文件,我們命名這個類庫為JavaControllers。注意框架選擇。
第二步,增加t4空模版,在解決方案管理器中,選擇JavaRequertModels項目,點擊右鍵,選擇“添加
”--〉“新建項”,選擇"Blank T4 Template",輸入名稱“JavaControllers.tt",然後點擊"添加".
第三步,修改JavaControllers.tt模版,我直接貼代碼
[csharp] <#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE"#>
<#@ output extension=".cs"#><#
CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this);
string inputFile = @"..\EDMX\dblxh.edmx";//EDMX項目中dblxh.edmx的路徑
MetadataWorkspace metadataWorkspace = null;
bool allMetadataLoaded =loader.TryLoadAllMetadata(inputFile, out metadataWorkspace);
EdmItemCollection ItemCollection = (EdmItemCollection)metadataWorkspace.GetItemCollection(DataSpace.CSpace);
EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
// 發出文件
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{
string filePascialName=getModelsPascialName(entity.Name);//Pascial風格的類名稱
string fileCamelName=getModelsCamelName(entity.Name);//Camel風格的類名稱
fileManager.StartNewFile(filePascialName+ "Controller.java");//輸出的類文件名稱,及開始輸出文件
#>
package com.jiahe.rest.demo2.controller;
/*********************************************************************************
* Copyright (c) XXXXX LIMITED 2012 All Rights Reserved
* 系統名稱:
* 程序模塊文件名稱:<#=filePascialName+ "Controller.java"#>
* 摘要:
*********************************************************************************/
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jiahe.rest.demo2.models.<#=filePascialName#>;
import com.jiahe.rest.demo2.requestmodels.<#=filePascialName#>Request;
import com.jiahe.rest.demo2.responseModels.ResultData;
import com.jiahe.rest.demo2.service.<#=filePascialName#>Service;
/*********************************************************************************
*
* <pre>
* [版本說明]
* 1.0 2012/08/30 初版
* </pre>
* @version 1.0 2013/5/16
* @author lxh
*********************************************************************************/
@Controller
@RequestMapping("/<#=filePascialName.ToLower()#>")
public class <#=filePascialName#>Controller {
@Autowired
private <#=filePascialName#>Service <#=fileCamelName#>Service;
/**
* add 增加一個<#=filePascialName#>
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/add
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> add(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.insert(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("添加成功");
} else {
resultData.setMessage("添加失敗");
}
} catch (Exception e) {
resultData.setMessage("添加失敗:"+e.getMessage());
}
}
return resultData;
}
/**
* update 修改一個<#=filePascialName#>
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/update
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> update(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.update(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("修改成功");
} else {
resultData.setMessage("修改失敗");
}
} catch (Exception e) {
resultData.setMessage("修改失敗:"+e.getMessage());
}
}
return resultData;
}
/**
* deleteByID 刪除一個<#=filePascialName#>
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/deletebyid
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/deletebyid", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> deleteByID(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.deleteByID(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("刪除成功");
} else {
resultData.setMessage("刪除失敗");
}
} catch (Exception e) {
resultData.setMessage("刪除失敗:"+e.getMessage());
}
}
return resultData;
}
@RequestMapping(value = "/deletebycondition", method = RequestMethod.POST)
@ResponseBody
public ResultData<Dishe<#=filePascialName#>> deleteByCondition(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.deleteByCondition(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("刪除成功");
} else {
resultData.setMessage("刪除失敗");
}
} catch (Exception e) {
resultData.setMessage("刪除失敗:"+e.getMessage());
}
}
return resultData;
}
@RequestMapping(value = "/findbyid", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> findByID(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
<#=filePascialName#> <#=fileCamelName#> =<#=fileCamelName#>Service.findByID(requestData.get<#=filePascialName#>());
resultData.setStatus(1);
resultData.setData(<#=fileCamelName#>);
} catch (Exception e) {
resultData.setMessage("查詢失敗:"+e.getMessage());
}
}
return resultData;
}
/**
* findByCondition 條件查詢
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/update
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/findbycondition", method = RequestMethod.POST)
@ResponseBody
public ResultData<List<<#=filePascialName#>>> findByCondition(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<List<<#=filePascialName#>>> resultData =new ResultData<List<<#=filePascialName#>>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
List<<#=filePascialName#>> <#=fileCamelName#>List =<#=fileCamelName#>Service.findByCondition(requestData.get<#=filePascialName#>());
resultData.setStatus(1);
resultData.setData(<#=fileCamelName#>List);
} catch (Exception e) {
resultData.setMessage("查詢失敗:"+e.getMessage());
}
}
return resultData;
}
@RequestMapping(value = "/findcountbycondition", method = RequestMethod.POST)
@ResponseBody
public ResultData<Long> findCountByCondition(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<Long> resultData =new ResultData<Long>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
Long l =<#=fileCamelName#>Service.findCountByCondition(requestData.get<#=filePascialName#>());
resultData.setStatus(1);
resultData.setData(l);
} catch (Exception e) {
resultData.setMessage("查詢失敗:"+e.getMessage());
}
}
return resultData;
}
}
<#
}
fileManager.Process();
#>
<#+
//得到類的Pascial風格名稱
string getModelsPascialName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
string result=string.Empty;
for(int i=1;i<s.Length;i++)
{
result=string.Concat(result,s[i]);
}
return result;
}
#>
<#+
//得到類的Camel風格名稱
string getModelsCamelName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
string result=string.Empty;
for(int i=1;i<s.Length;i++)
{
result=string.Concat(result,s[i]);
}
string s11=result.Substring(0,1).ToLower();
string s12=result.Substring(1);
return string.Concat(s11,s12);
}
#>
<#+
//得到屬性的Pascial風格名稱
string getPropertyPascialName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
return string.Concat(s);
}
//得到屬性的Camel風格名稱
string getPropertyCamelName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
string result=string.Concat(s);
string s11=result.Substring(0,1).ToLower();
string s12=result.Substring(1);
return string.Concat(s11,s12);
}
//數據類型轉換
string getPropertyType(string source)
{
string result=string.Empty;
if (source=="int") result="Integer";
if (source=="integer") result="Integer";
if (source=="Integer") result="Integer";
if (source=="byte") result="Integer";
if (source=="sbyte") result="Integer";
if (source=="bool") result="Integer";
if (source=="Int16") result="Integer";
if (source=="short") result="Integer";
if (source=="Int32") result="Integer";
if (source=="Nullable<int>") result="Integer";
if (source=="Nullable<integer>") result="Integer";
if (source=="Nullable<Integer>") result="Integer";
if (source=="Nullable<byte>") result="Integer";
if (source=="Nullable<sbyte>") result="Integer";
if (source=="Nullable<bool>") result="Integer";
if (source=="Nullable<boolean>") result="Integer";
if (source=="Nullable<Int16>") result="Integer";
if (source=="Nullable<short>") result="Integer";
if (source=="Nullable<Int32>") result="Integer";
if (source=="Int64") result="Long";
if (source=="long") result="Long";
if (source=="Long") result="Long";
if (source=="Nullable<Int64>") result="Long";
if (source=="Nullable<long>") result="Long";
if (source=="Nullable<Long>") result="Long";
if (source=="float") result="Double";
if (source=="Float") result="Double";
if (source=="decimal") result="Double";
if (source=="Decimal") result="Double";
if (source=="Nullable<float>") result="Double";
if (source=="Nullable<Float>") result="Double";
if (source=="Nullable<decimal>") result="Double";
if (source=="Nullable<Decimal>") result="Double";
if (source=="byte[]") result="byte[]";
if (source=="string") result="String";
if (source=="String") result="String";
if (source=="System.Date") result="String";
if (source=="System.Time") result="String";
if (source=="System.DateTime") result="String";
if (source=="Nullable<System.Date>") result="String";
if (source=="Nullable<System.Time>") result="String";
if (source=="Nullable<System.DateTime>") result="String";
return result;
}
#>
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE"#>
<#@ output extension=".cs"#><#
CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this);
string inputFile = @"..\EDMX\dblxh.edmx";//EDMX項目中dblxh.edmx的路徑
MetadataWorkspace metadataWorkspace = null;
bool allMetadataLoaded =loader.TryLoadAllMetadata(inputFile, out metadataWorkspace);
EdmItemCollection ItemCollection = (EdmItemCollection)metadataWorkspace.GetItemCollection(DataSpace.CSpace);
EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
// 發出文件
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{
string filePascialName=getModelsPascialName(entity.Name);//Pascial風格的類名稱
string fileCamelName=getModelsCamelName(entity.Name);//Camel風格的類名稱
fileManager.StartNewFile(filePascialName+ "Controller.java");//輸出的類文件名稱,及開始輸出文件
#>
package com.jiahe.rest.demo2.controller;
/*********************************************************************************
* Copyright (c) XXXXX LIMITED 2012 All Rights Reserved
* 系統名稱:
* 程序模塊文件名稱:<#=filePascialName+ "Controller.java"#>
* 摘要:
*********************************************************************************/
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jiahe.rest.demo2.models.<#=filePascialName#>;
import com.jiahe.rest.demo2.requestmodels.<#=filePascialName#>Request;
import com.jiahe.rest.demo2.responseModels.ResultData;
import com.jiahe.rest.demo2.service.<#=filePascialName#>Service;
/*********************************************************************************
*
* <pre>
* [版本說明]
* 1.0 2012/08/30 初版
* </pre>
* @version 1.0 2013/5/16
* @author lxh
*********************************************************************************/
@Controller
@RequestMapping("/<#=filePascialName.ToLower()#>")
public class <#=filePascialName#>Controller {
@Autowired
private <#=filePascialName#>Service <#=fileCamelName#>Service;
/**
* add 增加一個<#=filePascialName#>
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/add
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> add(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.insert(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("添加成功");
} else {
resultData.setMessage("添加失敗");
}
} catch (Exception e) {
resultData.setMessage("添加失敗:"+e.getMessage());
}
}
return resultData;
}
/**
* update 修改一個<#=filePascialName#>
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/update
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> update(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.update(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("修改成功");
} else {
resultData.setMessage("修改失敗");
}
} catch (Exception e) {
resultData.setMessage("修改失敗:"+e.getMessage());
}
}
return resultData;
}
/**
* deleteByID 刪除一個<#=filePascialName#>
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/deletebyid
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/deletebyid", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> deleteByID(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.deleteByID(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("刪除成功");
} else {
resultData.setMessage("刪除失敗");
}
} catch (Exception e) {
resultData.setMessage("刪除失敗:"+e.getMessage());
}
}
return resultData;
}
@RequestMapping(value = "/deletebycondition", method = RequestMethod.POST)
@ResponseBody
public ResultData<Dishe<#=filePascialName#>> deleteByCondition(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
int i=<#=fileCamelName#>Service.deleteByCondition(requestData.get<#=filePascialName#>());
if (i==1){
resultData.setStatus(1);
resultData.setMessage("刪除成功");
} else {
resultData.setMessage("刪除失敗");
}
} catch (Exception e) {
resultData.setMessage("刪除失敗:"+e.getMessage());
}
}
return resultData;
}
@RequestMapping(value = "/findbyid", method = RequestMethod.POST)
@ResponseBody
public ResultData<<#=filePascialName#>> findByID(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<<#=filePascialName#>> resultData =new ResultData<<#=filePascialName#>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
<#=filePascialName#> <#=fileCamelName#> =<#=fileCamelName#>Service.findByID(requestData.get<#=filePascialName#>());
resultData.setStatus(1);
resultData.setData(<#=fileCamelName#>);
} catch (Exception e) {
resultData.setMessage("查詢失敗:"+e.getMessage());
}
}
return resultData;
}
/**
* findByCondition 條件查詢
* http://localhost:8080/demo2/<#=filePascialName.ToLower()#>/update
* @param requestData
* @param mode
* @param response
* @return
* @throws IOException
*/
@RequestMapping(value = "/findbycondition", method = RequestMethod.POST)
@ResponseBody
public ResultData<List<<#=filePascialName#>>> findByCondition(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<List<<#=filePascialName#>>> resultData =new ResultData<List<<#=filePascialName#>>>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
List<<#=filePascialName#>> <#=fileCamelName#>List =<#=fileCamelName#>Service.findByCondition(requestData.get<#=filePascialName#>());
resultData.setStatus(1);
resultData.setData(<#=fileCamelName#>List);
} catch (Exception e) {
resultData.setMessage("查詢失敗:"+e.getMessage());
}
}
return resultData;
}
@RequestMapping(value = "/findcountbycondition", method = RequestMethod.POST)
@ResponseBody
public ResultData<Long> findCountByCondition(@RequestBody <#=filePascialName#>Request requestData,
Model mode, HttpServletResponse response) throws IOException {
ResultData<Long> resultData =new ResultData<Long>();
resultData.setStatus(0);
resultData.setData(null);
if (requestData==null) {
resultData.setMessage("參數錯誤:沒有傳入參數");
} else {
//身份驗證處理
try {
Long l =<#=fileCamelName#>Service.findCountByCondition(requestData.get<#=filePascialName#>());
resultData.setStatus(1);
resultData.setData(l);
} catch (Exception e) {
resultData.setMessage("查詢失敗:"+e.getMessage());
}
}
return resultData;
}
}
<#
}
fileManager.Process();
#>
<#+
//得到類的Pascial風格名稱
string getModelsPascialName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
string result=string.Empty;
for(int i=1;i<s.Length;i++)
{
result=string.Concat(result,s[i]);
}
return result;
}
#>
<#+
//得到類的Camel風格名稱
string getModelsCamelName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
string result=string.Empty;
for(int i=1;i<s.Length;i++)
{
result=string.Concat(result,s[i]);
}
string s11=result.Substring(0,1).ToLower();
string s12=result.Substring(1);
return string.Concat(s11,s12);
}
#>
<#+
//得到屬性的Pascial風格名稱
string getPropertyPascialName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
return string.Concat(s);
}
//得到屬性的Camel風格名稱
string getPropertyCamelName(string source)
{
string[] s=source.Split('_');
for(int i=0;i<s.Length;i++)
{
string s1=s[i].Substring(0,1).ToUpper();
string s2=s[i].Substring(1);
s[i]=string.Concat(s1,s2);
}
string result=string.Concat(s);
string s11=result.Substring(0,1).ToLower();
string s12=result.Substring(1);
return string.Concat(s11,s12);
}
//數據類型轉換
string getPropertyType(string source)
{
string result=string.Empty;
if (source=="int") result="Integer";
if (source=="integer") result="Integer";
if (source=="Integer") result="Integer";
if (source=="byte") result="Integer";
if (source=="sbyte") result="Integer";
if (source=="bool") result="Integer";
if (source=="Int16") result="Integer";
if (source=="short") result="Integer";
if (source=="Int32") result="Integer";
if (source=="Nullable<int>") result="Integer";
if (source=="Nullable<integer>") result="Integer";
if (source=="Nullable<Integer>") result="Integer";
if (source=="Nullable<byte>") result="Integer";
if (source=="Nullable<sbyte>") result="Integer";
if (source=="Nullable<bool>") result="Integer";
if (source=="Nullable<boolean>") result="Integer";
if (source=="Nullable<Int16>") result="Integer";
if (source=="Nullable<short>") result="Integer";
if (source=="Nullable<Int32>") result="Integer";
if (source=="Int64") result="Long";
if (source=="long") result="Long";
if (source=="Long") result="Long";
if (source=="Nullable<Int64>") result="Long";
if (source=="Nullable<long>") result="Long";
if (source=="Nullable<Long>") result="Long";
if (source=="float") result="Double";
if (source=="Float") result="Double";
if (source=="decimal") result="Double";
if (source=="Decimal") result="Double";
if (source=="Nullable<float>") result="Double";
if (source=="Nullable<Float>") result="Double";
if (source=="Nullable<decimal>") result="Double";
if (source=="Nullable<Decimal>") result="Double";
if (source=="byte[]") result="byte[]";
if (source=="string") result="String";
if (source=="String") result="String";
if (source=="System.Date") result="String";
if (source=="System.Time") result="String";
if (source=="System.DateTime") result="String";
if (source=="Nullable<System.Date>") result="String";
if (source=="Nullable<System.Time>") result="String";
if (source=="Nullable<System.DateTime>") result="String";
return result;
}
#>