博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springMvc 入门学习(自动生成 springmvc 单表 两关联表 生成 及显示)
阅读量:6116 次
发布时间:2019-06-21

本文共 56953 字,大约阅读时间需要 189 分钟。

 

 

 

 

springMvc 入门学习 (自动生成 springmvc 单表 两关联表 生成 及显示)

 自动生成代码源码  下载  

 以下为 自动生成代码程序生成的 代码 ( 自动生成代码  源码在底部)

 

 

 

 spring MVC 框架 完整 内容

 

 web.xml

test
org.springframework.web.servlet.DispatcherServlet
1
test
*.do

  

 

 test-servlet.xml

com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8
root
root

 

 

 

 

 bean.User.java

 

package cn.com.baoy.bean;public class User{     //属性:  userId---     int userId;     public int getUserId() {	       return userId;     }     public void setUserId(int  userId) {	       this. userId = userId;     }     //属性:  userName---     String userName;     public String getUserName() {	      return userName;     }     public void setUserName(String  userName) {	      this. userName = userName;     }     //属性:  password---     String password;     public String getPassword() {	      return password;     }     public void setPassword(String  password) {	      this. password = password;     }     //属性:  tel---     String tel;     public String getTel() {	      return tel;     }     public void setTel(String  tel) {	      this. tel = tel;     }     //属性:  sex---     String sex;     public String getSex() {	      return sex;     }     public void setSex(String  sex) {	      this. sex = sex;     }     //属性:  description---     String description;     public String getDescription() {	      return description;     }     public void setDescription(String  description) {	      this. description = description;     }}

 

 dao.UserDao.java

package cn.com.baoy.dao;import java.util.List;import cn.com.baoy.bean.User;public interface UserDao {	 //查所有	 public List
allUser(); //删除 public void delUser(int userId); //获取一个form public User user(int userId); //修改 public void updateUser(User user); //添加 public void addUser(User user);}

 

service.UserDao.java

package cn.com.baoy.service;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import cn.com.baoy.bean.User;import  cn.com.baoy.dao.UserDao;@Service public class UserService {   @Autowired   UserDao dao;   public List
allUser(){ return dao.allUser(); } public void delUser(int userId){ dao.delUser(userId); } public User user(int userId){ return dao.user(userId); } public void updateUser(User user){ dao.updateUser(user); } public void addUser(User user){ dao.addUser(user); }}

 

mapper.UserMapper.xml

delete from t_user where userId = #{ userId}
INSERT INTO t_user (userId,userName,password,tel,sex,description) VALUE (null,#{userName},#{password},#{tel},#{sex},#{description})
update t_user
userName = #{userName},
password = #{password},
tel = #{tel},
sex = #{sex},
description = #{description},
where userId = #{ userId}

 

 

 controller.UserController.java

package cn.com.baoy.controller;import java.util.List;import javax.servlet.http.HttpSession;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import cn.com.baoy.bean.User;import cn.com.baoy.service.UserService;@Controllerpublic class UserController {      @Autowired      UserService service;      @RequestMapping(value = "/userView.do")      public String userView(ModelMap modelMap,String pageNo, String choice, HttpSession session){            List
userList = service.allUser(); modelMap.put("userList", userList); return "back/jsp/user/userView"; } @RequestMapping(value = "/userDel{userId}.do") public String userDel(@PathVariable("userId")int userId ,ModelMap modelMap,String pageNo, String choice, HttpSession session){ service.delUser(userId); String message1="删除成功"; String message2="请返回……"; String url="userView.do"; modelMap.put("message1", message1); modelMap.put("message2", message2); modelMap.put("url", url); return "infomationShow"; } @RequestMapping(value ="/userGoAdd.do") public String userGoAdd(ModelMap modelMap,String pageNo, String choice, HttpSession session){ return "back/jsp/user/userAdd"; } @RequestMapping(value = "/userAdd.do",method=RequestMethod.POST) public String userAdd(User form,ModelMap modelMap,String pageNo, String choice, HttpSession session){ service.addUser(form); String message1="添加成功"; String message2="请返回……"; String url="userView.do"; modelMap.put("message1", message1); modelMap.put("message2", message2); modelMap.put("url", url); return "infomationShow"; } @RequestMapping(value = "/userGoUpdate{userId}.do") public String userGoUpdate(@PathVariable("userId")int userId ,ModelMap modelMap,String pageNo, String choice, HttpSession session){ User user = service.user(userId); modelMap.put("user", user); return "back/jsp/user/userUpdate"; } @RequestMapping(value = "/userUpdate.do",method=RequestMethod.POST) public String userUpdate(User form,ModelMap modelMap,String pageNo, String choice, HttpSession session){ service.updateUser(form); String message1="修改成功"; String message2="请返回……"; String url="userView.do"; modelMap.put("message1", message1); modelMap.put("message2", message2); modelMap.put("url", url); return "infomationShow"; }}

 

 

back/jsp/user/userView.jsp

<%@ page language="java"  import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>          user详细界面             
usershow
userId userName password tel operation
${userList.userId} ${userList.userName} ${userList.password} ${userList.tel} goupdate delete

 

back/jsp/user/userAdd.jsp

<%@ page language="java"  import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>          创建user          
userAdd

userName:
password:
tel:
sex:
description:

        

 

 back/jsp/user/userUpdate.jsp

<%@ page language="java"  import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>          修改user          
userUpdate

userId:
userName:
password:
tel:
sex:
description:

        

 

 

back/jsp/main.jsp

<%@ page language="java"  import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>          leftFrame      
userManager

 

back/jsp/left.jsp

<%@ page language="java"  import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>          mainFrame                  
<div></div>

 

back/jsp/right.jsp

<%@ page language="java"  import="java.util.*" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>          rightFrame         welcome 

 

 

操作 步骤: 

 
 
 
 
 
 
 
 

 

 

 

 

 

  以下 为自动生成 代码 :

   下载

 

 

自动生成 bean 的 代码 

package Test.code;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class BeanTest  {	  public static void beanTest(String tableName,String tableBean,String currentBao) throws  Exception{		String rn = "\r\n";		String []array = TestUtil.stringToArray(tableBean);		StringBuilder sb = new StringBuilder();		for (int i = 0; i < array.length; i++) {			String bean="";			if(i == 0){				bean=					 rn +					"     //属性:  "+ array[0] + "---" + rn +					"     int " + array[0] + ";" + rn +					rn +					"     public int get" + TestUtil.upperFirstChar(array[0]) + "() {" + rn +					"	       return " + array[0] + ";" + rn +					"     }" + rn +					 rn +					"     public void set" + TestUtil.upperFirstChar(array[0]) + "(int  " + array[0] + ") {" + rn +					"	       this. " + array[0] + " = " + array[0] + ";" + rn +					"     }" + rn;			}			else{				bean=					 rn +					"     //属性:  "+ array[i] + "---" + rn +					"     String " + array[i] + ";" + rn +					rn +					"     public String get" + TestUtil.upperFirstChar(array[i]) + "() {" + rn +					"	      return " + array[i] + ";" + rn +					"     }" + rn +					 rn +					"     public void set" + TestUtil.upperFirstChar(array[i]) + "(String  " + array[i] + ") {" + rn +					"	      this. " + array[i] + " = " + array[i] + ";" + rn +					"     }" + rn ;			}			sb.append(bean);		}		String src =  		"package " + currentBao + ".bean;" + rn +		rn +		"public class " + TestUtil.upperFirstChar(tableName) +"{"  + rn +		 sb.toString() + rn +		"}";						String path  = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/bean/";		File fpath = new File(path);		if (!fpath.exists()) {		   fpath.mkdirs();	    }		String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/bean/"+TestUtil.upperFirstChar(tableName)+".java";		File f = new File(fileName);		FileWriter fw = new FileWriter(f);		fw.write(src);		fw.flush();		fw.close();	}	}

 

 

自动生成 controller的 代码  

package Test.code;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class ControllerTest {	public static void controllerTest(String tableName,String tableBean,String currentBao) throws Exception{		 String rn = "\r\n";		 String []array = TestUtil.stringToArray(tableBean);		 String src = 			 			 "package " + currentBao + ".controller;"+ rn+			 rn +		     "import java.util.List;"+ rn+		     "import javax.servlet.http.HttpSession;"+ rn+		     "import org.springframework.beans.factory.annotation.Autowired;"+ rn+		     "import org.springframework.stereotype.Controller;"+ rn+		     "import org.springframework.ui.ModelMap;"+ rn+		     "import org.springframework.web.bind.annotation.PathVariable;"+ rn+		     "import org.springframework.web.bind.annotation.RequestMapping;"+ rn+		     "import org.springframework.web.bind.annotation.RequestMethod;"+ rn+		     rn +		     "import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+ ";"+ rn+		     "import " + currentBao + ".service."+TestUtil.upperFirstChar(tableName)+ "Service;"+ rn+		     rn +		     "@Controller"+ rn+		     "public class "+TestUtil.upperFirstChar(tableName)+ "Controller {"+ rn+		          rn +		 	 "      @Autowired"+ rn+		 	 "      "+TestUtil.upperFirstChar(tableName)+ "Service service;"+ rn+		 	      rn +		 	 "      @RequestMapping(value = \"/"+tableName+"View.do\")"+ rn+		 	 "      public String "+tableName+"View(ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "            List<"+TestUtil.upperFirstChar(tableName)+"> "+tableName+"List = service.all"+TestUtil.upperFirstChar(tableName)+"();"+ rn+		 	 "           modelMap.put(\""+tableName+"List\", "+tableName+"List);"+ rn+		 	 "           return \"back/jsp/"+tableName+"/"+tableName+"View\";"+ rn+		 	 "     }"+ rn+		 	      rn +		 	 "      @RequestMapping(value = \"/"+tableName+"Del{"+array[0]+"}.do\")"+ rn+		 	 "      public String "+tableName+"Del(@PathVariable(\""+array[0]+"\")int "+array[0]+" ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "             service.del"+TestUtil.upperFirstChar(tableName)+"("+array[0]+");"+ rn+		 	 "             String message1=\"删除成功\";"+ rn+		 	 "             String message2=\"请返回……\";"+ rn+		 	 "             String  url=\""+tableName+"View.do\";"+ rn+		 	 "             modelMap.put(\"message1\", message1);"+ rn+		 	 "             modelMap.put(\"message2\", message2);"+ rn+		 	 "             modelMap.put(\"url\", url);"+ rn+		 	 "            return \"infomationShow\";"+ rn+		 	 "      }"+ rn+		 	      rn +		 	 "      @RequestMapping(value =\"/"+tableName+"GoAdd.do\")"+ rn+		 	 "             public String "+tableName+"GoAdd(ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "             return \"back/jsp/"+tableName+"/"+tableName+"Add\";"+ rn+		 	 "      }"+ rn+		 	      rn +		     "      @RequestMapping(value = \"/"+tableName+"Add.do\",method=RequestMethod.POST)"+ rn+		     "      public String "+tableName+"Add("+TestUtil.upperFirstChar(tableName)+" form,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		     "             service.add"+TestUtil.upperFirstChar(tableName)+"(form);"+ rn+		     "             String message1=\"添加成功\";"+ rn+		     "             String message2=\"请返回……\";"+ rn+		     "             String  url=\""+tableName+"View.do\";"+ rn+		     "             modelMap.put(\"message1\", message1);"+ rn+		     "             modelMap.put(\"message2\", message2);"+ rn+		     "            modelMap.put(\"url\", url);"+ rn+		     "             return \"infomationShow\";"+ rn+		     "      }"+ rn+		 	      rn +		 	 "      @RequestMapping(value = \"/"+tableName+"GoUpdate{"+array[0]+"}.do\")"+ rn+		 	 "      public String "+tableName+"GoUpdate(@PathVariable(\""+array[0]+"\")int "+array[0]+" ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "            "+TestUtil.upperFirstChar(tableName)+" "+tableName+" = service."+tableName+"("+array[0]+");"+ rn+		 	 "           modelMap.put(\""+tableName+"\", "+tableName+");"+ rn+		 	 "           return \"back/jsp/"+tableName+"/"+tableName+"Update\";"+ rn+		 	 "      }"+ rn+		 	      rn+		 	 "      @RequestMapping(value = \"/"+tableName+"Update.do\",method=RequestMethod.POST)"+ rn+		 	 "      public String "+tableName+"Update("+TestUtil.upperFirstChar(tableName)+" form,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "             service.update"+TestUtil.upperFirstChar(tableName)+"(form);"+ rn+		 	 "             String message1=\"修改成功\";"+ rn+		 	 "             String message2=\"请返回……\";"+ rn+		 	 "             String  url=\""+tableName+"View.do\";"+ rn+		 	 "             modelMap.put(\"message1\", message1);"+ rn+		 	 "             modelMap.put(\"message2\", message2);"+ rn+		 	 "             modelMap.put(\"url\", url);"+ rn+		 	 "             return \"infomationShow\";"+ rn+		 	 "      }"+ rn+		 	      rn +			 "}"+ rn ;								    String path  = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/controller/";			File fpath = new File(path);			if (!fpath.exists()) {			   fpath.mkdirs();		    }			String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/controller/"+TestUtil.upperFirstChar(tableName)+"Controller.java";			File f = new File(fileName);			FileWriter fw = new FileWriter(f);			fw.write(src);			fw.flush();			fw.close();	 }	public static void controllerTest_(String tableName,String firstTable,String tableBean,String currentBao) throws Exception{		 String rn = "\r\n";		 String []array = TestUtil.stringToArray(tableBean);		 String src = 			 			 "package " + currentBao + ".controller;"+ rn+			 rn +		     "import java.util.List;"+ rn+		     "import javax.servlet.http.HttpSession;"+ rn+		     "import org.springframework.beans.factory.annotation.Autowired;"+ rn+		     "import org.springframework.stereotype.Controller;"+ rn+		     "import org.springframework.ui.ModelMap;"+ rn+		     "import org.springframework.web.bind.annotation.PathVariable;"+ rn+		     "import org.springframework.web.bind.annotation.RequestMapping;"+ rn+		     "import org.springframework.web.bind.annotation.RequestMethod;"+ rn+		     rn +		     "import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+ ";"+ rn+		     "import " + currentBao + ".service."+TestUtil.upperFirstChar(tableName)+ "Service;"+ rn+		     rn +		     "@Controller"+ rn+		     "public class "+TestUtil.upperFirstChar(tableName)+ "Controller {"+ rn+		          rn +		 	 "      @Autowired"+ rn+		 	 "      "+TestUtil.upperFirstChar(tableName)+ "Service service;"+ rn+		 	      rn +		 	 "      @RequestMapping(value = \"/"+tableName+"View{"+firstTable+"Id}.do\")"+ rn+		 	 "      public String "+tableName+"View(@PathVariable(\""+firstTable+"Id\")String "+firstTable+"Id ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "            List<"+TestUtil.upperFirstChar(tableName)+"> "+tableName+"List = service.all"+TestUtil.upperFirstChar(tableName)+"("+firstTable+"Id);"+ rn+		 	 "             "+TestUtil.upperFirstChar(tableName)+"  "+tableName+" = new  "+TestUtil.upperFirstChar(tableName)+"(); "+ rn+		 	 "             "+tableName+".set"+TestUtil.upperFirstChar(firstTable)+"Id("+firstTable+"Id);"+ rn+		 	 "             modelMap.put(\""+tableName+"\",  "+tableName+");"+ rn+		 	 "           modelMap.put(\""+tableName+"List\", "+tableName+"List);"+ rn+		 	 "           return \"back/jsp/"+tableName+"/"+tableName+"View\";"+ rn+		 	 "     }"+ rn+		 	      rn +		 	 "      @RequestMapping(value = \"/"+tableName+"Del{"+array[0]+"}.do\")"+ rn+		 	 "      public String "+tableName+"Del(@PathVariable(\""+array[0]+"\")int "+array[0]+" ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "            "+TestUtil.upperFirstChar(tableName)+" "+tableName+" = service."+tableName+"("+array[0]+");"+ rn+		 	 "             service.del"+TestUtil.upperFirstChar(tableName)+"("+array[0]+");"+ rn+		 	 "             String message1=\"删除成功\";"+ rn+		 	 "             String message2=\"请返回……\";"+ rn+		 	 "             String  url=\""+tableName+"View\"+"+tableName+".get"+TestUtil.upperFirstChar(firstTable)+"Id()+\".do\";"+ rn+		 	 "             modelMap.put(\"message1\", message1);"+ rn+		 	 "             modelMap.put(\"message2\", message2);"+ rn+		 	 "             modelMap.put(\"url\", url);"+ rn+		 	 "            return \"infomationShow\";"+ rn+		 	 "      }"+ rn+		 	      rn +		 	 "      @RequestMapping(value =\"/"+tableName+"GoAdd{"+firstTable+"Id}.do\")"+ rn+		 	 "             public String "+tableName+"GoAdd(@PathVariable(\""+firstTable+"Id\")String "+firstTable+"Id ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "             "+TestUtil.upperFirstChar(tableName)+"  "+tableName+" = new  "+TestUtil.upperFirstChar(tableName)+"(); "+ rn+		 	 "             "+tableName+".set"+TestUtil.upperFirstChar(firstTable)+"Id("+firstTable+"Id);"+ rn+		 	 "             modelMap.put(\""+tableName+"\",  "+tableName+");"+ rn+		 	 "             return \"back/jsp/"+tableName+"/"+tableName+"Add\";"+ rn+		 	 "      }"+ rn+		 	      rn +		     "      @RequestMapping(value = \"/"+tableName+"Add.do\",method=RequestMethod.POST)"+ rn+		     "      public String "+tableName+"Add("+TestUtil.upperFirstChar(tableName)+" form,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		     "             service.add"+TestUtil.upperFirstChar(tableName)+"(form);"+ rn+		     "             String message1=\"添加成功\";"+ rn+		     "             String message2=\"请返回……\";"+ rn+		     "             String  url=\""+tableName+"View\"+form.get"+TestUtil.upperFirstChar(firstTable)+"Id()+\".do\";"+ rn+		     "             modelMap.put(\"message1\", message1);"+ rn+		     "             modelMap.put(\"message2\", message2);"+ rn+		     "            modelMap.put(\"url\", url);"+ rn+		     "             return \"infomationShow\";"+ rn+		     "      }"+ rn+		 	      rn +		 	 "      @RequestMapping(value = \"/"+tableName+"GoUpdate{"+array[0]+"}.do\")"+ rn+		 	 "      public String "+tableName+"GoUpdate(@PathVariable(\""+array[0]+"\")int "+array[0]+" ,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "            "+TestUtil.upperFirstChar(tableName)+" "+tableName+" = service."+tableName+"("+array[0]+");"+ rn+		 	 "           modelMap.put(\""+tableName+"\", "+tableName+");"+ rn+		 	 "           return \"back/jsp/"+tableName+"/"+tableName+"Update\";"+ rn+		 	 "      }"+ rn+		 	      rn+		 	 "      @RequestMapping(value = \"/"+tableName+"Update.do\",method=RequestMethod.POST)"+ rn+		 	 "      public String "+tableName+"Update("+TestUtil.upperFirstChar(tableName)+" form,ModelMap modelMap,String pageNo, String choice, HttpSession session){"+ rn+		 	 "             service.update"+TestUtil.upperFirstChar(tableName)+"(form);"+ rn+		 	 "             String message1=\"修改成功\";"+ rn+		 	 "             String message2=\"请返回……\";"+ rn+		 	 "             String  url=\""+tableName+"View\"+form.get"+TestUtil.upperFirstChar(firstTable)+"Id()+\".do\";"+ rn+		 	 "             modelMap.put(\"message1\", message1);"+ rn+		 	 "             modelMap.put(\"message2\", message2);"+ rn+		 	 "             modelMap.put(\"url\", url);"+ rn+		 	 "             return \"infomationShow\";"+ rn+		 	 "      }"+ rn+		 	      rn +			 "}"+ rn ;								    String path  = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/controller/";			File fpath = new File(path);			if (!fpath.exists()) {			   fpath.mkdirs();		    }			String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/controller/"+TestUtil.upperFirstChar(tableName)+"Controller.java";			File f = new File(fileName);			FileWriter fw = new FileWriter(f);			fw.write(src);			fw.flush();			fw.close();	 }		}

 

自动生成 dao 的 代码  

package Test.code;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class DaoTest {	public static void daoTest(String tableName,String tableBean,String currentBao) throws Exception{		 String rn = "\r\n";		 String []array = TestUtil.stringToArray(tableBean);		 String src = 			"package " + currentBao + ".dao;" + rn +			"import java.util.List;" + rn +			"import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+";" + rn +			 rn +			 rn +			 "public interface "+TestUtil.upperFirstChar(tableName)+"Dao {" + rn +			 rn +			 "	 //查所有"+ rn +			 "	 public List<"+TestUtil.upperFirstChar(tableName)+"> all"+TestUtil.upperFirstChar(tableName)+"();"+ rn +			 rn +			 "	 //删除"+ rn +			 "	 public void del"+TestUtil.upperFirstChar(tableName)+"(int " +array[0]+ ");"+ rn +			 rn +			 "	 //获取一个form"+ rn +			 "	 public  "+TestUtil.upperFirstChar(tableName)+ "  "+tableName+"(int  " +array[0]+ ");"+ rn +			 rn +			 "	 //修改"+ rn +			 "	 public void update"+TestUtil.upperFirstChar(tableName)+ "("+TestUtil.upperFirstChar(tableName)+ "  "+tableName+");"+ rn +			 rn +			 "	 //添加"+ rn +			 "	 public void add"+TestUtil.upperFirstChar(tableName)+ "("+TestUtil.upperFirstChar(tableName)+"  "+tableName+");"+ rn +			 rn +							"}"+ rn ;								    String path  = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/dao/";			File fpath = new File(path);			if (!fpath.exists()) {			   fpath.mkdirs();		    }			String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/dao/"+TestUtil.upperFirstChar(tableName)+"Dao.java";			File f = new File(fileName);			FileWriter fw = new FileWriter(f);			fw.write(src);			fw.flush();			fw.close();	 }	public static void daoTest_(String tableName,String firstTable,String tableBean,String currentBao) throws Exception{		 String rn = "\r\n";		 String []array = TestUtil.stringToArray(tableBean);		 String src = 			"package " + currentBao + ".dao;" + rn +			"import java.util.List;" + rn +			"import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+";" + rn +			 rn +			 rn +			 "public interface "+TestUtil.upperFirstChar(tableName)+"Dao {" + rn +			 rn +			 "	 //查所有"+ rn +			 "	 public List<"+TestUtil.upperFirstChar(tableName)+"> all"+TestUtil.upperFirstChar(tableName)+"(String "+firstTable+"Id);"+ rn +			 rn +			 "	 //删除"+ rn +			 "	 public void del"+TestUtil.upperFirstChar(tableName)+"(int " +array[0]+ ");"+ rn +			 rn +			 "	 //获取一个form"+ rn +			 "	 public  "+TestUtil.upperFirstChar(tableName)+ "  "+tableName+"(int  " +array[0]+ ");"+ rn +			 rn +			 "	 //修改"+ rn +			 "	 public void update"+TestUtil.upperFirstChar(tableName)+ "("+TestUtil.upperFirstChar(tableName)+ "  "+tableName+");"+ rn +			 rn +			 "	 //添加"+ rn +			 "	 public void add"+TestUtil.upperFirstChar(tableName)+ "("+TestUtil.upperFirstChar(tableName)+"  "+tableName+");"+ rn +			 rn +							"}"+ rn ;								    String path  = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/dao/";			File fpath = new File(path);			if (!fpath.exists()) {			   fpath.mkdirs();		    }			String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/dao/"+TestUtil.upperFirstChar(tableName)+"Dao.java";			File f = new File(fileName);			FileWriter fw = new FileWriter(f);			fw.write(src);			fw.flush();			fw.close();	 }}

 

自动生成 mapper.xml 的 代码  

package Test.code;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class MapperTest {	public static void mapperTest(String tableName,String tableBean,String currentBao) throws  Exception{				String rn = "\r\n";				String []array = TestUtil.stringToArray(tableBean);				StringBuilder sbname = new StringBuilder();				for (int i = 0; i < array.length ; i++) {					String bean = 						array[i]+",";					sbname.append(bean);				}				StringBuilder sbvalue = new StringBuilder();				for (int i = 0; i < array.length ; i++) {					String value = "";					if(i == 0){						value ="null,";					}else{					 value = "#{"+							array[i]+"},";				     }					sbvalue.append(value);				}				StringBuilder sbupdateset = new StringBuilder();				for (int i = 1; i < array.length ; i++) {					String updateset = "";					if(i == array.length){						 updateset = "			
"+array[i]+" = #{"+array[i]+"}
" + rn ; }else{ updateset = "
"+array[i]+" = #{"+array[i]+"},
" + rn ; } sbupdateset.append(updateset); } String src = "
" + rn + " " + rn + "
" + rn + rn + "
" + rn + rn + "
" + rn + " delete from t_"+tableName+" where "+array[0]+" = #{ "+array[0]+"} " + rn + "
" + rn + "
" + rn + " INSERT INTO t_"+tableName+" " + rn + " ("+ sbname.substring(0,sbname.length()-1)+ ") " + rn + " VALUE ("+ sbvalue.substring(0,sbvalue.length()-1)+ ") " + rn + "
" + rn + rn + "
" + rn + rn + "
" + rn + " update t_"+tableName + rn + "
" + rn + sbupdateset + "
" + rn + " where "+array[0]+" = #{ "+array[0]+"} " + rn + "
" + rn + rn + "
" + rn ; String path = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/mapper/"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/mapper/"+TestUtil.upperFirstChar(tableName)+"Mapper.xml"; File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close(); } public static void mapperTest_(String tableName,String firstTable,String tableBean,String currentBao) throws Exception{ String rn = "\r\n"; String []array = TestUtil.stringToArray(tableBean); StringBuilder sbname = new StringBuilder(); for (int i = 0; i < array.length ; i++) { String bean = array[i]+","; sbname.append(bean); } StringBuilder sbvalue = new StringBuilder(); for (int i = 0; i < array.length ; i++) { String value = ""; if(i == 0){ value ="null,"; }else{ value = "#{"+ array[i]+"},"; } sbvalue.append(value); } StringBuilder sbupdateset = new StringBuilder(); for (int i = 1; i < array.length ; i++) { String updateset = ""; if(i == array.length){ updateset = "
"+array[i]+" = #{"+array[i]+"}
" + rn ; }else{ updateset = "
"+array[i]+" = #{"+array[i]+"},
" + rn ; } sbupdateset.append(updateset); } String src = "
" + rn + " " + rn + "
" + rn + rn + "
" + rn + rn + "
" + rn + " delete from t_"+tableName+" where "+array[0]+" = #{ "+array[0]+"} " + rn + "
" + rn + "
" + rn + " INSERT INTO t_"+tableName+" " + rn + " ("+ sbname.substring(0,sbname.length()-1)+ ") " + rn + " VALUE ("+ sbvalue.substring(0,sbvalue.length()-1)+ ") " + rn + "
" + rn + rn + "
" + rn + rn + "
" + rn + " update t_"+tableName + rn + "
" + rn + sbupdateset + "
" + rn + " where "+array[0]+" = #{ "+array[0]+"} " + rn + "
" + rn + rn + "
" + rn ; String path = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/mapper/"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/mapper/"+TestUtil.upperFirstChar(tableName)+"Mapper.xml"; File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close();} }

 

 

自动生成 service 的 代码  

package Test.code;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class ServiceTest {	public static void serviceTest(String tableName,String tableBean,String currentBao) throws Exception{		 String rn = "\r\n";		 String []array = TestUtil.stringToArray(tableBean);		 String src = 			 			 "package " + currentBao + ".service;" + rn +			 rn +		     "import java.util.List;" + rn +		     "import org.springframework.beans.factory.annotation.Autowired;" + rn +		     "import org.springframework.stereotype.Service;" + rn +		     "import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+ ";" + rn +		     "import  " + currentBao + ".dao."+TestUtil.upperFirstChar(tableName)+ "Dao;" + rn +		     rn +		     "@Service" + rn +		     " public class "+TestUtil.upperFirstChar(tableName)+"Service {" + rn +		     rn + 		     rn + 		     "   @Autowired" + rn +			 "   "+TestUtil.upperFirstChar(tableName)+"Dao dao;" + rn +			 rn + 			 rn + 			"   public List<"+TestUtil.upperFirstChar(tableName)+"> all"+TestUtil.upperFirstChar(tableName)+"(){" + rn +			"	     return dao.all"+TestUtil.upperFirstChar(tableName)+"();" + rn +			"   }" + rn +			rn + 			"   public void del"+TestUtil.upperFirstChar(tableName)+"(int "+array[0]+"){" + rn +			"	   dao.del"+TestUtil.upperFirstChar(tableName)+"("+array[0]+");" + rn +			"   }" + rn +			rn + 			"   public "+TestUtil.upperFirstChar(tableName)+" "+tableName+"(int "+array[0]+"){" + rn +			"	   return dao."+tableName+"("+array[0]+");" + rn +			"   }" + rn +			rn +			"   public void update"+TestUtil.upperFirstChar(tableName)+"("+TestUtil.upperFirstChar(tableName)+" "+tableName+"){" + rn +			"	   dao.update"+TestUtil.upperFirstChar(tableName)+"("+tableName+");" + rn +			"   }" + rn +			rn +			"   public void add"+TestUtil.upperFirstChar(tableName)+"("+TestUtil.upperFirstChar(tableName)+" "+tableName+"){" + rn +			"   	dao.add"+TestUtil.upperFirstChar(tableName)+"("+tableName+");" + rn +			"   }" + rn +			rn +				"}"+ rn ;								    String path  = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/service/";			File fpath = new File(path);			if (!fpath.exists()) {			   fpath.mkdirs();		    }			String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/service/"+TestUtil.upperFirstChar(tableName)+"Service.java";			File f = new File(fileName);			FileWriter fw = new FileWriter(f);			fw.write(src);			fw.flush();			fw.close();	 }	public static void serviceTest_(String tableName,String firstTable , String tableBean,String currentBao) throws Exception{		 String rn = "\r\n";		 String []array = TestUtil.stringToArray(tableBean);		 String src = 			 			 "package " + currentBao + ".service;" + rn +			 rn +		     "import java.util.List;" + rn +		     "import org.springframework.beans.factory.annotation.Autowired;" + rn +		     "import org.springframework.stereotype.Service;" + rn +		     "import " + currentBao + ".bean."+TestUtil.upperFirstChar(tableName)+ ";" + rn +		     "import  " + currentBao + ".dao."+TestUtil.upperFirstChar(tableName)+ "Dao;" + rn +		     rn +		     "@Service" + rn +		     " public class "+TestUtil.upperFirstChar(tableName)+"Service {" + rn +		     rn + 		     rn + 		     "   @Autowired" + rn +			 "   "+TestUtil.upperFirstChar(tableName)+"Dao dao;" + rn +			 rn + 			 rn + 			"   public List<"+TestUtil.upperFirstChar(tableName)+"> all"+TestUtil.upperFirstChar(tableName)+"(String "+firstTable+"Id){" + rn +			"	     return dao.all"+TestUtil.upperFirstChar(tableName)+"("+firstTable+"Id);" + rn +			"   }" + rn +			rn + 			"   public void del"+TestUtil.upperFirstChar(tableName)+"(int "+array[0]+"){" + rn +			"	   dao.del"+TestUtil.upperFirstChar(tableName)+"("+array[0]+");" + rn +			"   }" + rn +			rn + 			"   public "+TestUtil.upperFirstChar(tableName)+" "+tableName+"(int "+array[0]+"){" + rn +			"	   return dao."+tableName+"("+array[0]+");" + rn +			"   }" + rn +			rn +			"   public void update"+TestUtil.upperFirstChar(tableName)+"("+TestUtil.upperFirstChar(tableName)+" "+tableName+"){" + rn +			"	   dao.update"+TestUtil.upperFirstChar(tableName)+"("+tableName+");" + rn +			"   }" + rn +			rn +			"   public void add"+TestUtil.upperFirstChar(tableName)+"("+TestUtil.upperFirstChar(tableName)+" "+tableName+"){" + rn +			"   	dao.add"+TestUtil.upperFirstChar(tableName)+"("+tableName+");" + rn +			"   }" + rn +			rn +				"}"+ rn ;								    String path  = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/service/";			File fpath = new File(path);			if (!fpath.exists()) {			   fpath.mkdirs();		    }			String fileName = System.getProperty("user.dir")+"/src/"+TestUtil.docToBackslash(currentBao)+"/service/"+TestUtil.upperFirstChar(tableName)+"Service.java";			File f = new File(fileName);			FileWriter fw = new FileWriter(f);			fw.write(src);			fw.flush();			fw.close();	 }		}

 

 

自动生成 frame 左边  的 代码  

package Test.jsp.common;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class JSPLeftTest {	public static void jSPLeftTest(String programName,String tableString) throws  Exception{		String rn = "\r\n";	    String tablestr = tableString.substring(0,tableString.length()-1);		String []array = TestUtil.stringToArray(tablestr);		StringBuilder sbtrtd = new StringBuilder();		for (int i = 0; i < array.length ; i++) {			String trtd = 			"       " + rn + 			"        " + rn + 			"          " + rn + 			"    /login_images/menu_bt.jpg\">"+array[i]+"Manager" + rn + 			 rn ;			sbtrtd.append(trtd);		}		String src = 						"<%@ page language=\"java\"  import=\"java.util.*\" pageEncoding=\"UTF-8\"%>" + rn + 		"<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + rn + 		"<%" + rn + 		"String path = request.getContextPath();" + rn + 		"String basePath = request.getScheme()+\"://\"+request.getServerName()+\":\"+request.getServerPort()+path+\"/\";" + rn + 		"%>" + rn + 		"" + rn + 		"" + rn + 		"  " + rn + 		"    \">" + rn + 		    		"    leftFrame" + rn + 		"  " + rn + 		"  " + rn + 				"  
/login_images/menu_bg.jpg\" border=0>" + rn + "
" + rn + "
" + rn + "
" + rn + "
" + rn + sbtrtd + "
" + rn + "
" + rn + "
" + rn + "
" + rn + "
" + rn + " " + rn + rn + "" + rn + rn; String path = System.getProperty("user.dir")+"/WebRoot/back/jsp/"; String fileName = System.getProperty("user.dir")+"/WebRoot/back/jsp/left.jsp"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close(); } }

 

 

自动生成 frame main 的 代码  

package Test.jsp.common;import java.io.File;import java.io.FileWriter;public class JSPMainTest {	public  static void jSPMainTest() throws  Exception{			String rn = "\r\n";						String src = 									"<%@ page language=\"java\"  import=\"java.util.*\" pageEncoding=\"UTF-8\"%>" + rn + 			"<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + rn + 			"<%" + rn + 			"String path = request.getContextPath();" + rn + 			"String basePath = request.getScheme()+\"://\"+request.getServerName()+\":\"+request.getServerPort()+path+\"/\";" + rn + 			"%>" + rn + 			"" + rn + 			"" + rn + 			"  " + rn + 			"    \">" + rn + 			    			"    mainFrame" + rn + 			"  " + rn + 			"  " + rn + 			"  back/jsp/header.jsp\" frameBorder=\"0\" noResize scrolling=no>" + rn + 			"  " + rn + 			"  back/jsp/left.jsp\" frameBorder=\"0\" noResize>" + rn + 			"  back/jsp/right.jsp\" frameBorder=\"0\" noResize scrolling=yes>" + rn + 			"  " + rn + 			"  " + rn + 			"  
<div></div> " + rn + " <div></div> " + rn + rn + "" + rn + rn; String path = System.getProperty("user.dir")+"/WebRoot/back/jsp/"; String fileName = System.getProperty("user.dir")+"/WebRoot/back/jsp/main.jsp"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close(); } }

 

 

自动生成  frame right 的 代码  

package Test.jsp.common;import java.io.File;import java.io.FileWriter;public class JSPRightTest {	public static void jSPRightTest() throws  Exception{		String rn = "\r\n";				String src = 						"<%@ page language=\"java\"  import=\"java.util.*\" pageEncoding=\"UTF-8\"%>" + rn + 		"<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + rn + 		"<%" + rn + 		"String path = request.getContextPath();" + rn + 		"String basePath = request.getScheme()+\"://\"+request.getServerName()+\":\"+request.getServerPort()+path+\"/\";" + rn + 		"%>" + rn + 		"" + rn + 		"" + rn + 		"  " + rn + 		"    \">" + rn + 		    		"    rightFrame" + rn + 		"  " + rn + 		"  " + rn + 		"     welcome 
" + rn + " " + rn + rn + "" + rn + rn; String path = System.getProperty("user.dir")+"/WebRoot/back/jsp/"; String fileName = System.getProperty("user.dir")+"/WebRoot/back/jsp/right.jsp"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close(); } }

 

 

 

自动生成  一张表 add jsp 的 代码  

package Test.jsp.noconn;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class JSPAddTest {	public static void jSPAddTest(String tableName,String tableBean,String currentBao) throws  Exception{			String rn = "\r\n";			String []array = TestUtil.stringToArray(tableBean);			StringBuilder sb = new StringBuilder();			for (int i = 1; i < array.length; i++) {				String bean = 					"	 "+ array[i]+":" + rn + 					"	 " + rn ;				sb.append(bean);			}						StringBuilder sbcheck = new StringBuilder();			for (int i = 1; i < array.length; i++) {				String beancheck = 					"	   var "+array[i]+"=document.getElementsByName(\""+array[i]+"\")[0];" + rn + 					"	   if("+array[i]+".value ==null || "+array[i]+".value  == \"\"){" + rn + 					"	       alert(\""+array[i]+"不能为空……\");" + rn + 					"	       "+array[i]+".value =\"\";" + rn + 					"	       "+array[i]+".focus();" + rn + 					"	       return false;" + rn +				    "	    }" + rn;				sbcheck.append(beancheck);			}						String src = 									"<%@ page language=\"java\"  import=\"java.util.*\" pageEncoding=\"UTF-8\"%>" + rn + 			"<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + rn + 			"<%" + rn + 			"String path = request.getContextPath();" + rn + 			"String basePath = request.getScheme()+\"://\"+request.getServerName()+\":\"+request.getServerPort()+path+\"/\";" + rn + 			"%>" + rn + 			"" + rn + 			"" + rn + 			"  " + rn + 			"    \">" + rn + 			    			"    创建"+tableName+"" + rn + 			"    " + rn + 			"  " + rn + 			"  " + rn + 			"  
" + rn + "
" + rn + "
" + rn + "
" + rn + sb + "
" + rn + "
" + rn + "
" + rn + "
"+tableName+"Add


" + rn + "    " + rn + "     " + rn + "
" + rn + "
" + rn + " " + rn + "" + rn + rn; String path = System.getProperty("user.dir")+"/WebRoot/back/jsp/"+tableName+"/"; String fileName = System.getProperty("user.dir")+"/WebRoot/back/jsp/"+tableName+"/"+tableName+"Add.jsp"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close(); } }

 

 

自动生成 一张表 updates jsp 的 代码

package Test.jsp.noconn;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class JSPUpdateTest {	public static void jSPUpdateTest(String tableName,String tableBean,String currentBao) throws  Exception{		String rn = "\r\n";		String []array = TestUtil.stringToArray(tableBean);		StringBuilder sb = new StringBuilder();		for (int i = 0; i < array.length; i++) {			 String bean = "";			if(i == 0){				 bean =				"	 "+ array[0]+":" + rn + 				"	 " + rn ;			}else{			  bean = 				"	 "+ array[i]+":" + rn + 				"	 " + rn ;		    }			 sb.append(bean);		}				StringBuilder sbcheck = new StringBuilder();		for (int i = 1; i < array.length; i++) {			String beancheck = 				"	   var "+array[i]+"=document.getElementsByName(\""+array[i]+"\")[0];" + rn + 				"	   if("+array[i]+".value ==null || "+array[i]+".value  == \"\"){" + rn + 				"	       alert(\""+array[i]+"不能为空……\");" + rn + 				"	       "+array[i]+".value =\"\";" + rn + 				"	       "+array[i]+".focus();" + rn + 				"	       return false;" + rn +			    "	    }" + rn;			sbcheck.append(beancheck);		}				String src = 						"<%@ page language=\"java\"  import=\"java.util.*\" pageEncoding=\"UTF-8\"%>" + rn + 		"<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + rn + 		"<%" + rn + 		"String path = request.getContextPath();" + rn + 		"String basePath = request.getScheme()+\"://\"+request.getServerName()+\":\"+request.getServerPort()+path+\"/\";" + rn + 		"%>" + rn + 		"" + rn + 		"" + rn + 		"  " + rn + 		"    \">" + rn + 		    		"    修改"+tableName+"" + rn + 		"    " + rn + 		"  " + rn + 		"  " + rn + 		"  
" + rn + "
" + rn + "
" + rn + "
" + rn + sb + "
" + rn + "
" + rn + "
" + rn + "
"+tableName+"Update


" + rn + "    " + rn + "     " + rn + "
" + rn + "
" + rn + " " + rn + "" + rn + rn; String path = System.getProperty("user.dir")+"/WebRoot/back/jsp/"+tableName+"/"; String fileName = System.getProperty("user.dir")+"/WebRoot/back/jsp/"+tableName+"/"+tableName+"Update.jsp"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close(); } }

 

 

自动生成 一张表 list jsp 的 代码  

package Test.jsp.noconn;import java.io.File;import java.io.FileWriter;import Test.TestUtil;public class JSPViewTest {	public static void jSPViewTest(String tableName,String tableBean,String currentBao) throws  Exception{		String rn = "\r\n";		String []array = TestUtil.stringToArray(tableBean);		StringBuilder sbname = new StringBuilder();		for (int i = 0; i < (array.length > 4 ? 4: array.length ); i++) {			String bean = 				"	            " + rn + 				"	              "+array[i]+"" + rn + 				"	            " + rn ;			sbname.append(bean);		}		StringBuilder sbvalue = new StringBuilder();		for (int i = 0; i < (array.length > 4 ? 4: array.length ); i++) {			String value = 				"				" + rn + 				"	              ${"+tableName+"List."+array[i]+"}" + rn + 				"	            " + rn ;			sbvalue.append(value);		}		String src = 		"<%@ page language=\"java\"  import=\"java.util.*\" pageEncoding=\"UTF-8\"%>" + rn + 		"<%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + rn + 		"<%" + rn + 		"String path = request.getContextPath();" + rn + 		"String basePath = request.getScheme()+\"://\"+request.getServerName()+\":\"+request.getServerPort()+path+\"/\";" + rn + 		"%>" + rn + 		"" + rn + 		"" + rn + 		"  " + rn + 		"    \">" + rn + 		    		"    "+tableName+"详细界面" + rn + 		"    " + rn + 		"    " + rn + 				"  " + rn + 		"  " + rn + 										" 
" + rn + "
" + rn + "
" + rn + "
" + rn + "
" + rn + "
" + rn + sbname + "
" + rn + "
" + rn + "
" + rn + sbvalue + "
" + rn + "
" + rn + " " + rn + "
" + rn + "
" + rn + "
" + rn + "
" + rn + " "+tableName+"show " + rn + "
" + rn + " operation " + rn + "
" + rn + " goupdate " + rn + " delete " + rn + "
" + rn + " " + rn + "
" + rn + " " + rn + "" + rn + rn; String path = System.getProperty("user.dir")+"/WebRoot/back/jsp/"+tableName+"/"; String fileName = System.getProperty("user.dir")+"/WebRoot/back/jsp/"+tableName+"/"+tableName+"View.jsp"; File fpath = new File(path); if (!fpath.exists()) { fpath.mkdirs(); } File f = new File(fileName); FileWriter fw = new FileWriter(f); fw.write(src); fw.flush(); fw.close(); } }

 

 

 

java 代码  配置文件  用途 是 需要添加 什么表当 什么 属性 , 用于执行后生成 改文件的 配置

package Test;public class TestConfig {	   static String currentBao = "cn.com.baoy";   static String programName = "www.baoy.com";   	 static String tb[][]={	   {"user","userId,userName,password,tel,sex,description"}	};   //   static String tb[][]={//	   {"product","productId,productName,productOldPrice,productNowPrice,productPhoto,productInfo"}//   };//   //   static String tbconn[][]={//	   {"applationFirstSort","applationFirstSortId,applationFirstName,position"},//	   {"applationSecondSort","applationSecondSortId,applationSecondName,position,applationFirstSortId,href"}//   };}

 

 

 

 java 代码 ,一些 工具类

package Test;public class TestUtil {	//点转换为反斜杠	public static String docToBackslash(String currentBao){		String baoName = currentBao.replace(".", "/");		return baoName;	}		//字符串首字母大写	public static String upperFirstChar(String str){//		String first = fldName.substring(0, 1).toUpperCase();//		String rest = fldName.substring(1, fldName.length());//		String newStr = new StringBuffer(first).append(rest).toString();		StringBuilder sb = new StringBuilder(str);		sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));		str = sb.toString();		return str;	} 		//字符串拆分为数组	public static String[] stringToArray(String str){		String []array = str.split(",");		return array;	} 		//获取到的	}

 

 

java 代码 : 主函数 用于 执行 生成 代码

package Test;import Test.code.BeanTest;import Test.code.ControllerTest;import Test.code.DaoTest;import Test.code.MapperTest;import Test.code.ServiceTest;import Test.jsp.common.JSPLeftTest;import Test.jsp.common.JSPMainTest;import Test.jsp.common.JSPRightTest;import Test.jsp.hasconn.containsecond.FJAdd;import Test.jsp.hasconn.containsecond.FJUpdate;import Test.jsp.hasconn.containsecond.FJView;import Test.jsp.hasconn.containsecond.SJAdd;import Test.jsp.hasconn.containsecond.SJUpdate;import Test.jsp.hasconn.containsecond.SJView;import Test.jsp.noconn.JSPAddTest;import Test.jsp.noconn.JSPUpdateTest;import Test.jsp.noconn.JSPViewTest;/*    *  全局变量 : 输入的table名   输入的table属性名 小table名  输入属性的个数  *   1.bean文件:根据输入的table名 ,以及table名 的属性 *     a>根据输入的table名 ,自动首字母大写生成.java文件放在cn.com.baoy.bean中 *     b>根据 输入的 table名 的属性,属性是以逗号隔开的,先用分割方法获取array数组,以及数组大小 *     c>写入set get 方法 *   2.dao文件 :   *    */public class AutoTest {			public static void main(String[] args) throws Exception {		String currentBao = TestConfig.currentBao;		String programName = TestConfig.programName;		String tableString = "" ;        String tb[][] = TestConfig.tb;      //  String tbconn[][] = TestConfig.tbconn;		//0.准备工作 获取table名和属性        for (int i = 0; i < tb.length; i++) {        	String tableName = tb[i][0];    		String tableBean = tb[i][1];						tableString += (tableName+",");				// ---------				// 1.创建 bean				  BeanTest.beanTest(tableName, tableBean, currentBao);				// 2.创建dao				 DaoTest.daoTest(tableName, tableBean, currentBao);				// 3.创建daoimpl				// 4.创建service				  ServiceTest.serviceTest(tableName, tableBean, currentBao);				// 5.创建serviceImpl								// 6.创建 controller				  ControllerTest.controllerTest(tableName, tableBean, currentBao);				// 7.创建 jsp				// a> view.jsp				  JSPViewTest.jSPViewTest(tableName, tableBean, currentBao);				// b> add.jsp				  JSPAddTest.jSPAddTest(tableName, tableBean, currentBao);				// c> update.jsp				 JSPUpdateTest.jSPUpdateTest(tableName, tableBean, currentBao);				// 8.mapper				 MapperTest.mapperTest(tableName, tableBean, currentBao);				// 9.导入				 				 				// --------- 			 					}//        for (int i = 0; i < tbconn.length; i++) {//        	String tableName = tbconn[i][0];//    		String tableBean = tbconn[i][1];//		//				//				// ---------//				// 1.创建 bean//				  BeanTest.beanTest(tableName, tableBean, currentBao);//				// 2.创建dao//				 DaoTest.daoTest(tableName, tableBean, currentBao);//				  ServiceTest.serviceTest(tableName, tableBean, currentBao);//				// 5.创建serviceImpl//				//				// 6.创建 controller//				 //				// 7.创建 jsp//				if(i == 1){//			        	FJAdd.fJAdd(tbconn[0][0], tbconn[0][1], currentBao);//			        	FJUpdate.fJUpdate(tbconn[0][0], tbconn[0][1], currentBao);//			        	FJView.fJView(tbconn[0][0], tbconn[1][0], tbconn[0][1], currentBao);//			        	SJAdd.sJAdd(tbconn[1][0], tbconn[0][0], tbconn[1][1], currentBao);//			        	SJUpdate.sJUpdate(tbconn[1][0], tbconn[0][0], tbconn[1][1], currentBao);//			        	SJView.sJView(tbconn[1][0], tbconn[0][0], tbconn[1][1], currentBao);//			        	//			        	tableString += tbconn[0][0]+",";//			        	//				}//				// 8.mapper//				if(i==0){//					 DaoTest.daoTest(tableName, tableBean, currentBao);//					  ServiceTest.serviceTest(tableName, tableBean, currentBao);//				 ControllerTest.controllerTest(tableName, tableBean, currentBao);//				 MapperTest.mapperTest(tableName, tableBean, currentBao);//				 }else{//					 DaoTest.daoTest_(tableName,tbconn[0][0], tableBean, currentBao);//					  ServiceTest.serviceTest_(tableName,tbconn[0][0], tableBean, currentBao);//				 ControllerTest.controllerTest_(tableName,tbconn[0][0], tableBean, currentBao);//				 MapperTest.mapperTest_(tableName,tbconn[0][0], tableBean, currentBao); //				 }//				// 9.导入//				 //				  //				// --------- //			 //			//		}                                		System.out.println("----------------"+tableString);		  		//主界面编辑		JSPMainTest.jSPMainTest();		//左边栏		JSPLeftTest.jSPLeftTest(programName, tableString);		//右边栏		JSPRightTest.jSPRightTest();			}		}

 

 

infomationShow.jsp  增删改 之后的 提示信息 界面

<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>	<%		String path = request.getContextPath();	%>			
Insert title here
=>信息提示

${message1}
    ${message2}
        ${message3}

 

 

 

 

 两张表 之间有关联 的生成方式 ,在 源码中 有 ,就不贴出来了 ,原理是 一样的

 自动生成代码源码 下载

 

 

运行 程序的时候

 

如 学生信息表 t_sudent (id,name,sex ,tel,phone)

在 TestConfig 中 String tb[][]= {"student","id,name,sex ,tel,phone"};

注释掉tbcon[][] 即可 ,tbconn[][]是 用来 写入 多表连接的 ,

运行 AutoTest java代码后 就会生成 页面 和代码 ,

然后 启动 tomcat ,访问 localhost:8080/www.baoyou.com 就行了 。

tbconn[][] 多表的 增删查改 ,tbconn[][]={

{"clazz","id,name,shortname"},{"student","id,clazzid,name,sex ,tel,phone"}} 数据建表的时候 加上 t_clazz t_student 即可

 

顶部 有 运行出来的  实例代码

 

 

 

这是 我刚学习 Java  springMVC 的时候写出来的 代码,,大家 可以参考 ,想学习 springMVC 的可以 很快上手。

 

 

 

 

 

 

 

 

 

 

 

--------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

 
 
 谢谢您的赞助,我会做的更好!

转载地址:http://fdjka.baihongyu.com/

你可能感兴趣的文章
[leetcode-661-Image Smoother]
查看>>
VS2008 ACtivex 制作CAB带 Vcredist_x86.exe 方案
查看>>
CentOS6.5安装宝塔
查看>>
Unity3D研究院之使用 C#合成解析XML与JSON
查看>>
【OCP-12c】CUUG最新考试原题整理及答案(071-9)
查看>>
MYSQL Query Cache 浅谈
查看>>
FatMouse and Cheese 动态化搜索
查看>>
Naive Website Crawl using Python
查看>>
POJ 3660 Cow Contest 传递闭包+Floyd
查看>>
leetcode-263-Ugly Number
查看>>
2012-06-25创建数据库函数的基本语法
查看>>
详解CSS3属性前缀(转)
查看>>
xutils工具上传日志文件--使用https并且带进度条显示
查看>>
JS-高程3(更新中...)
查看>>
Unity编译Android的原理解析和apk打包分析
查看>>
计算几何 点线的综合题, 精度+ 线段相交+ 求交点 + 求面积 poj 2826 An Easy Problem?! (推荐)...
查看>>
iOS开发中如何将后台返回的时间转换为常见字串
查看>>
iOS开发如何把项目打包为ipa文件
查看>>
微软老将Philip Su的离职信:回首12年职场生涯的心得和随笔
查看>>
shiro 角色与权限的解读
查看>>