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

Java 发表评论

 

 

 

 

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

 自动生成代码源码  下载  http://download.csdn.net/detail/knight_black_bob/8412661

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

 

 

 

 spring MVC 框架 完整 内容

 

 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	version="3.0">
	<display-name></display-name>
	 
	<servlet>
		<servlet-name>test</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	 
	<servlet-mapping>
		<servlet-name>test</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

	 
</web-app>

  

 

 test-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans   
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
           http://www.springframework.org/schema/context   
           http://www.springframework.org/schema/context/spring-context-3.0.xsd"
	default-autowire="byName">
	<!-- 自动扫描controller bean,把作了注解的类转换为bean -->
	<context:component-scan base-package="cn.com.baoy" />
	<!-- 数据源 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName">
			<value>com.mysql.jdbc.Driver</value>
		</property>
		<property name="url">
			<value>jdbc:mysql://localhost:3306/database?useUnicode=true&amp;characterEncoding=utf8</value>
		</property>
		<property name="username">
			<value>root</value>
		</property>
		<property name="password">
			<value>root</value>
		</property>
	</bean>
	<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
	<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="" p:suffix=".jsp">
		<property name="order" value="0" />
	</bean>
	
	 <!-- 创建SqlSessionFactory,同时指定数据源 -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath*:cn/com/baoy/mapper/*.xml" />
    </bean>  
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.com.baoy.dao" />
    </bean>
</beans>  

 

 

 

 

 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<User> 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<User> 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

<?xml version="1.0" encoding="UTF-8"?>    
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >    
<mapper namespace="cn.com.baoy.dao.UserDao">   

    <select id="allUser" resultType="cn.com.baoy.bean.User">   
    	select * from t_user   
    </select>   

    <delete id="delUser" parameterType="int">   
    	delete from t_user where userId = #{ userId}   
    </delete>   
    <insert id="addUser" parameterType="cn.com.baoy.bean.User">   
		INSERT INTO t_user   
		(userId,userName,password,tel,sex,description)   
		VALUE (null,#{userName},#{password},#{tel},#{sex},#{description})   
	</insert>   

	<select id="user" resultType="cn.com.baoy.bean.User">   
    	select * from t_user where  userId = #{ userId}   
    </select>   

	 <update id="updateUser" parameterType="cn.com.baoy.bean.User" >   
		update t_user
		 <set>   
			<if test="userName != null ">userName = #{userName},</if>   
			<if test="password != null ">password = #{password},</if>   
			<if test="tel != null ">tel = #{tel},</if>   
			<if test="sex != null ">sex = #{sex},</if>   
			<if test="description != null ">description = #{description},</if>   
		</set>   
		where   userId = #{ userId}   
	</update>	   

</mapper>   

 

 

 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;

@Controller
public class UserController {

      @Autowired
      UserService service;

      @RequestMapping(value = "/userView.do")
      public String userView(ModelMap modelMap,String pageNo, String choice, HttpSession session){
            List<User> 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+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>user详细界面</title>
    <style type="text/css">
    .td2 { border-bottom: #9999FF solid 1px; }
    .td3 { border-bottom: #9999FF solid 1px;  border-right: #9999FF solid 1px; }
    </style>
    <script language="javascript">	
    function  del(obj){
    			var k = window.confirm("are you sure to delete this item?");
      			if(k){
                     location.href="userDel"+obj+".do";
        			 return true;   
      	 		  }else{
         		 	return false;    
     			  }
     }
      function update(obj){
           location.href="userGoUpdate"+obj+".do";
      }
      function add(){
        location.href="userGoAdd.do";
      }
      </script>
  </head>
  <body>
 <table border="1" rules="none" bordercolor="#969696" style="empty-cells: show"    
 	width="650" cellpadding="2" cellspacing="0">                                     
 	<tr bgcolor="#CCFFFF">                                                           
 		<td colspan="100" class="td2">                                               
 			<font color="0000FF">usershow</font>                                  
 		</td>                          
 	</tr>  
 	<tr align="center" bgcolor="#99CCFF">            
	            <td class="td3">
	              <font color="#0000FF">userId</font>
	            </td>
	            <td class="td3">
	              <font color="#0000FF">userName</font>
	            </td>
	            <td class="td3">
	              <font color="#0000FF">password</font>
	            </td>
	            <td class="td3">
	              <font color="#0000FF">tel</font>
	            </td>
 		<TD class="td2">            
 			<font color="#0000FF">operation</font>           
 		</TD>           
 	</tr>           
 	<c:forEach items="${userList}" var="userList">           
 		<tr align="center">           
				<td width="20%" class="td3">
	              ${userList.userId}
	            </td>
				<td width="20%" class="td3">
	              ${userList.userName}
	            </td>
				<td width="20%" class="td3">
	              ${userList.password}
	            </td>
				<td width="20%" class="td3">
	              ${userList.tel}
	            </td>
 			<td class="td2">           
 				<a             
 					onclick="update(${userList.userId});">goupdate</a>           
 				<a           
 					onclick="del(${userList.userId});" >delete</a>           
 			</td>            
 		</tr>            
 	</c:forEach>            
 	<tr height="50" align="right">            
 		<td colspan="100%" bgcolor="#CCFFFF">            
 			<input type="button"           
 				onclick="add()" value="goadd"            
 				style="background: #CCFFFF" />          
 		</td>            
 	</tr>           
 </table>            
  </body>
</html>

 

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+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>创建user</title>
    <script language="javascript">
    function add(){
	   var userName=document.getElementsByName("userName")[0];
	   if(userName.value ==null || userName.value  == ""){
	       alert("userName不能为空……");
	       userName.value ="";
	       userName.focus();
	       return false;
	    }
	   var password=document.getElementsByName("password")[0];
	   if(password.value ==null || password.value  == ""){
	       alert("password不能为空……");
	       password.value ="";
	       password.focus();
	       return false;
	    }
	   var tel=document.getElementsByName("tel")[0];
	   if(tel.value ==null || tel.value  == ""){
	       alert("tel不能为空……");
	       tel.value ="";
	       tel.focus();
	       return false;
	    }
	   var sex=document.getElementsByName("sex")[0];
	   if(sex.value ==null || sex.value  == ""){
	       alert("sex不能为空……");
	       sex.value ="";
	       sex.focus();
	       return false;
	    }
	   var description=document.getElementsByName("description")[0];
	   if(description.value ==null || description.value  == ""){
	       alert("description不能为空……");
	       description.value ="";
	       description.focus();
	       return false;
	    }
	   document.forms[0].submit();
	}
    function goback(){
       location.href="userView.do";
    }
   </script>
  </head>
  <body>
  <form action="userAdd.do" method="post">  
  <table bgcolor="#CCFFFF" border ="0" bordercolor="#969696"  width="500" cellpadding="3" cellspacing="0">
	<tr bgcolor="#99CCFF"><td colspan="100%">userAdd</td></tr>
    <tr><td colspan="100%"><hr size="1" color="#9999FF"></hr></td></tr>
	 <tr><td>userName:
	 <input type="text" name="userName"></td></tr>
	 <tr><td>password:
	 <input type="text" name="password"></td></tr>
	 <tr><td>tel:
	 <input type="text" name="tel"></td></tr>
	 <tr><td>sex:
	 <input type="text" name="sex"></td></tr>
	 <tr><td>description:
	 <input type="text" name="description"></td></tr>
	 <tr><td colspan="100%"><hr size="1" color="#9999FF"></hr></td></tr>
	 <tr height="50">
	<td colspan="100%" align="right">
	<input type="button" onclick="add()" value="add" style="background:#CCFFFF"/>&nbsp;&nbsp;&nbsp;
    <input type="button" onclick="goback()" value="goback" style="background:#CCFFFF"/>&nbsp;&nbsp;&nbsp;&nbsp;
	</td></tr>
 </table>
  </form>
  </body>
</html>

 

 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+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>修改user</title>
    <script language="javascript">
    function update(){
	   var userName=document.getElementsByName("userName")[0];
	   if(userName.value ==null || userName.value  == ""){
	       alert("userName不能为空……");
	       userName.value ="";
	       userName.focus();
	       return false;
	    }
	   var password=document.getElementsByName("password")[0];
	   if(password.value ==null || password.value  == ""){
	       alert("password不能为空……");
	       password.value ="";
	       password.focus();
	       return false;
	    }
	   var tel=document.getElementsByName("tel")[0];
	   if(tel.value ==null || tel.value  == ""){
	       alert("tel不能为空……");
	       tel.value ="";
	       tel.focus();
	       return false;
	    }
	   var sex=document.getElementsByName("sex")[0];
	   if(sex.value ==null || sex.value  == ""){
	       alert("sex不能为空……");
	       sex.value ="";
	       sex.focus();
	       return false;
	    }
	   var description=document.getElementsByName("description")[0];
	   if(description.value ==null || description.value  == ""){
	       alert("description不能为空……");
	       description.value ="";
	       description.focus();
	       return false;
	    }
	   document.forms[0].submit();
	}
    function goback(){
       location.href="userView.do";
    }
   </script>
  </head>
  <body>
  <form action="userUpdate.do" method="post">  
  <table bgcolor="#CCFFFF" border ="0" bordercolor="#969696"  width="500" cellpadding="3" cellspacing="0">
	<tr bgcolor="#99CCFF"><td colspan="100%">userUpdate</td></tr>
    <tr><td colspan="100%"><hr size="1" color="#9999FF"></hr></td></tr>
	 <tr><td>userId:
	 <input type="text" readonly  name="userId" value="${user.userId}"></td></tr>
	 <tr><td>userName:
	 <input type="text"  name="userName" value="${user.userName}"></td></tr>
	 <tr><td>password:
	 <input type="text"  name="password" value="${user.password}"></td></tr>
	 <tr><td>tel:
	 <input type="text"  name="tel" value="${user.tel}"></td></tr>
	 <tr><td>sex:
	 <input type="text"  name="sex" value="${user.sex}"></td></tr>
	 <tr><td>description:
	 <input type="text"  name="description" value="${user.description}"></td></tr>
	 <tr><td colspan="100%"><hr size="1" color="#9999FF"></hr></td></tr>
	 <tr height="50">
	<td colspan="100%" align="right">
	<input type="button" onclick="update()" value="update" style="background:#CCFFFF"/>&nbsp;&nbsp;&nbsp;
    <input type="button" onclick="goback()" value="goback" style="background:#CCFFFF"/>&nbsp;&nbsp;&nbsp;&nbsp;
	</td></tr>
 </table>
  </form>
  </body>
</html>

 

 

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+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>leftFrame</title>
  </head>
  <body>
  <TABLE height="100%" cellSpacing="0" cellPadding="0" width="170" background="<%=path %>/login_images/menu_bg.jpg" border=0>
    <TR>
     <TD vAlign=top align="center">
    <TABLE cellSpacing="0" cellPadding="0" width="150" border="0">
       <TR>
        <TD height="10"></TD></TR>
          <TR height="22">
    <TD style="PADDING-LEFT: 15px" background="<%=path %>/login_images/menu_bt.jpg"><A 
          class=menuParent 
          href="/www.baoy.com/userView.do" target=main>userManager</A></TD></TR>

          <TR height=22>
   	 <TD style="PADDING-LEFT: 15px">
    	</TD></TR>  	
     </TABLE>
    </TD>
    </TR></TABLE>
  </body>

</html>

 

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+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>mainFrame</title>
  </head>
  <frameset border="0" framespacing="0" rows="60, *" frameborder="0">
  <FRAME name=header src="<%=basePath %>back/jsp/header.jsp" frameBorder="0" noResize scrolling=no>
  <FRAMESET cols="210, *">
  <FRAME name=menu src="<%=basePath %>back/jsp/left.jsp" frameBorder="0" noResize>
  <FRAME name=main src="<%=basePath %>back/jsp/right.jsp" frameBorder="0" noResize scrolling=yes>
  </FRAMESET>
  </frameset>
  <noframes>
  </noframes>

</html>

 

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+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>rightFrame</title>
  </head>
  <body>
     welcome <br/>
  </body>

</html>

 

 

操作 步骤: 


 

 

 

 

 

 

 

 

 

 

 

 

  http://download.csdn.net/detail/knight_black_bob/8412661

  以下 为自动生成 代码 :

   下载 http://download.csdn.net/detail/knight_black_bob/8412661

 

 

自动生成 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 = "			<if test=\""+array[i]+" != null \">"+array[i]+" = #{"+array[i]+"}</if>   " + rn ;
					}else{
					     updateset = "			<if test=\""+array[i]+" != null \">"+array[i]+" = #{"+array[i]+"},</if>   " + rn ;
					}
					sbupdateset.append(updateset);
				}
				String src = 
				"<?xml version=\"1.0\" encoding=\"UTF-8\"?>    " + rn +
				"<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\" >    " + rn +
				"<mapper namespace=\""+currentBao+".dao."+TestUtil.upperFirstChar(tableName)+"Dao\">   " + rn +
				rn +
				"    <select id=\"all"+TestUtil.upperFirstChar(tableName)+"\" resultType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\">   " + rn +
				"    	select * from t_"+tableName+"   " + rn +
				"    </select>   " + rn +
				rn +     
				"    <delete id=\"del"+TestUtil.upperFirstChar(tableName)+"\" parameterType=\"int\">   " + rn +
				"    	delete from t_"+tableName+" where "+array[0]+" = #{ "+array[0]+"}   " + rn +
				"    </delete>   " + rn +
				    
				"    <insert id=\"add"+TestUtil.upperFirstChar(tableName)+"\" parameterType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\">   " + rn +
				"		INSERT INTO t_"+tableName+"   " + rn +
				"		("+
				sbname.substring(0,sbname.length()-1)+
				")   " + rn +
				"		VALUE ("+
				sbvalue.substring(0,sbvalue.length()-1)+
				")   " + rn +
				"	</insert>   " + rn +
				rn +	
				"	<select id=\""+tableName+"\" resultType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\">   " + rn +
				"    	select * from t_"+tableName+" where  "+array[0]+" = #{ "+array[0]+"}   " + rn +
				"    </select>   " + rn +
				rn +	
				"	 <update id=\"update"+TestUtil.upperFirstChar(tableName)+"\" parameterType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\" >   " + rn +
				"		update t_"+tableName  + rn +
				"		 <set>   " + rn +
				sbupdateset +
				"		</set>   " + rn +
				"		where   "+array[0]+" = #{ "+array[0]+"}   " + rn +
				"	</update>	   " + rn +
				rn +	
				"</mapper>   " + 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 = "			<if test=\""+array[i]+" != null \">"+array[i]+" = #{"+array[i]+"}</if>   " + rn ;
			}else{
			     updateset = "			<if test=\""+array[i]+" != null \">"+array[i]+" = #{"+array[i]+"},</if>   " + rn ;
			}
			sbupdateset.append(updateset);
		}
		String src = 
		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>    " + rn +
		"<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\" >    " + rn +
		"<mapper namespace=\""+currentBao+".dao."+TestUtil.upperFirstChar(tableName)+"Dao\">   " + rn +
		rn +
		"    <select id=\"all"+TestUtil.upperFirstChar(tableName)+"\" parameterType=\"int\" resultType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\">   " + rn +
		"    	select * from t_"+tableName+"  where "+firstTable+"Id =#{ "+firstTable+"Id}  " + rn +
		"    </select>   " + rn +
		rn +     
		"    <delete id=\"del"+TestUtil.upperFirstChar(tableName)+"\" parameterType=\"int\">   " + rn +
		"    	delete from t_"+tableName+" where "+array[0]+" = #{ "+array[0]+"}   " + rn +
		"    </delete>   " + rn +
		    
		"    <insert id=\"add"+TestUtil.upperFirstChar(tableName)+"\" parameterType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\">   " + rn +
		"		INSERT INTO t_"+tableName+"   " + rn +
		"		("+
		sbname.substring(0,sbname.length()-1)+
		")   " + rn +
		"		VALUE ("+
		sbvalue.substring(0,sbvalue.length()-1)+
		")   " + rn +
		"	</insert>   " + rn +
		rn +	
		"	<select id=\""+tableName+"\" resultType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\">   " + rn +
		"    	select * from t_"+tableName+" where  "+array[0]+" = #{ "+array[0]+"}   " + rn +
		"    </select>   " + rn +
		rn +	
		"	 <update id=\"update"+TestUtil.upperFirstChar(tableName)+"\" parameterType=\""+currentBao+".bean."+TestUtil.upperFirstChar(tableName)+"\" >   " + rn +
		"		update t_"+tableName  + rn +
		"		 <set>   " + rn +
		sbupdateset +
		"		</set>   " + rn +
		"		where   "+array[0]+" = #{ "+array[0]+"}   " + rn +
		"	</update>	   " + rn +
		rn +	
		"</mapper>   " + 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 = 
			"       <TR>" + rn + 
			"        <TD height=\"10\"></TD></TR>" + rn + 
			"          <TR height=\"22\">" + rn + 
			"    <TD style=\"PADDING-LEFT: 15px\" background=\"<%=path %>/login_images/menu_bt.jpg\"><A " + rn + 
			"          class=menuParent " + rn + 
			"          href=\"/"+programName+"/"+array[i]+"View.do\" target=main>"+array[i]+"Manager</A></TD></TR>" + 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 + 

		"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + rn + 
		"<html>" + rn + 
		"  <head>" + rn + 
		"    <base href=\"<%=basePath%>\">" + rn + 
		    
		"    <title>leftFrame</title>" + rn + 
		"  </head>" + rn + 
		"  <body>" + rn + 


		
		"  <TABLE height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" width=\"170\" background=\"<%=path %>/login_images/menu_bg.jpg\" border=0>" + rn + 
		"    <TR>" + rn + 
		"     <TD vAlign=top align=\"center\">" + rn + 
		"    <TABLE cellSpacing=\"0\" cellPadding=\"0\" width=\"150\" border=\"0\">" + rn + 
	        
		sbtrtd +
	            
		"          <TR height=22>" + rn + 
		"   	 <TD style=\"PADDING-LEFT: 15px\">" + rn + 
		"    	</TD></TR>  	" + rn + 
	            
		"     </TABLE>" + rn + 

	          
		"    </TD>" + rn + 
		"    </TR></TABLE>" + rn + 
		
		
		
		
		
		
		
		
		
		
		
		"  </body>" + rn + 
		rn + 
		"</html>" + 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 + 

			"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + rn + 
			"<html>" + rn + 
			"  <head>" + rn + 
			"    <base href=\"<%=basePath%>\">" + rn + 
			    
			"    <title>mainFrame</title>" + rn + 
			"  </head>" + rn + 

			"  <frameset border=\"0\" framespacing=\"0\" rows=\"60, *\" frameborder=\"0\">" + rn + 
			"  <FRAME name=header src=\"<%=basePath %>back/jsp/header.jsp\" frameBorder=\"0\" noResize scrolling=no>" + rn + 
			"  <FRAMESET cols=\"210, *\">" + rn + 
			"  <FRAME name=menu src=\"<%=basePath %>back/jsp/left.jsp\" frameBorder=\"0\" noResize>" + rn + 
			"  <FRAME name=main src=\"<%=basePath %>back/jsp/right.jsp\" frameBorder=\"0\" noResize scrolling=yes>" + rn + 
			"  </FRAMESET>" + rn + 
			"  </frameset>" + rn + 
			"  <noframes>" + rn + 
			"  </noframes>" + rn + 
			rn + 
			"</html>" + 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 + 

		"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + rn + 
		"<html>" + rn + 
		"  <head>" + rn + 
		"    <base href=\"<%=basePath%>\">" + rn + 
		    
		"    <title>rightFrame</title>" + rn + 
		"  </head>" + rn + 

		"  <body>" + rn + 
		"     welcome <br/>" + rn + 
		"  </body>" + rn + 
		
		rn + 
		"</html>" + 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 = 
					"	 <tr><td>"+ array[i]+":" + rn + 
					"	 <input type=\"text\" name=\""+ array[i]+"\"></td></tr>" + 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 + 

			"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + rn + 
			"<html>" + rn + 
			"  <head>" + rn + 
			"    <base href=\"<%=basePath%>\">" + rn + 
			    
			"    <title>创建"+tableName+"</title>" + rn + 
			"    <script language=\"javascript\">" + rn + 
			
			"    function add(){" + rn + 
			sbcheck +
			"	   document.forms[0].submit();" + rn + 
			"	}" + rn + 
				
			"    function goback(){" + rn + 
			"       location.href=\""+tableName+"View.do\";" + rn + 
			"    }" + rn + 
			     
			"   </script>" + rn + 
			"  </head>" + rn + 
			"  <body>" + rn + 
			"  <form action=\""+tableName+"Add.do\" method=\"post\">  " + rn + 
			"  <table bgcolor=\"#CCFFFF\" border =\"0\" bordercolor=\"#969696\"  width=\"500\" cellpadding=\"3\" cellspacing=\"0\">" + rn + 
			"	<tr bgcolor=\"#99CCFF\"><td colspan=\"100%\">"+tableName+"Add</td></tr>" + rn + 
			"    <tr><td colspan=\"100%\"><hr size=\"1\" color=\"#9999FF\"></hr></td></tr>" + rn + 
			
			sb +
			
			"	 <tr><td colspan=\"100%\"><hr size=\"1\" color=\"#9999FF\"></hr></td></tr>" + rn + 
			"	 <tr height=\"50\">" + rn + 
			"	<td colspan=\"100%\" align=\"right\">" + rn + 
			"	<input type=\"button\" onclick=\"add()\" value=\"add\" style=\"background:#CCFFFF\"/>&nbsp;&nbsp;&nbsp;" + rn + 
			"    <input type=\"button\" onclick=\"goback()\" value=\"goback\" style=\"background:#CCFFFF\"/>&nbsp;&nbsp;&nbsp;&nbsp;" + rn + 
			"	</td></tr>" + rn + 
			" </table>" + rn + 
			"  </form>" + rn + 
			"  </body>" + rn + 
			"</html>" + 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 =
				"	 <tr><td>"+ array[0]+":" + rn + 
				"	 <input type=\"text\" readonly  name=\""+ array[0]+"\" value=\"${"+tableName+"."+ array[0]+"}\"></td></tr>" + rn ;
			}else{
			  bean = 
				"	 <tr><td>"+ array[i]+":" + rn + 
				"	 <input type=\"text\"  name=\""+ array[i]+"\" value=\"${"+tableName+"."+ array[i]+"}\"></td></tr>" + 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 + 

		"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + rn + 
		"<html>" + rn + 
		"  <head>" + rn + 
		"    <base href=\"<%=basePath%>\">" + rn + 
		    
		"    <title>修改"+tableName+"</title>" + rn + 
		"    <script language=\"javascript\">" + rn + 
		
		"    function update(){" + rn + 
		sbcheck +
		"	   document.forms[0].submit();" + rn + 
		"	}" + rn + 
			
		"    function goback(){" + rn + 
		"       location.href=\""+tableName+"View.do\";" + rn + 
		"    }" + rn + 
		     
		"   </script>" + rn + 
		"  </head>" + rn + 
		"  <body>" + rn + 
		"  <form action=\""+tableName+"Update.do\" method=\"post\">  " + rn + 
		"  <table bgcolor=\"#CCFFFF\" border =\"0\" bordercolor=\"#969696\"  width=\"500\" cellpadding=\"3\" cellspacing=\"0\">" + rn + 
		"	<tr bgcolor=\"#99CCFF\"><td colspan=\"100%\">"+tableName+"Update</td></tr>" + rn + 
		"    <tr><td colspan=\"100%\"><hr size=\"1\" color=\"#9999FF\"></hr></td></tr>" + rn + 
		
		sb +
		
		"	 <tr><td colspan=\"100%\"><hr size=\"1\" color=\"#9999FF\"></hr></td></tr>" + rn + 
		"	 <tr height=\"50\">" + rn + 
		"	<td colspan=\"100%\" align=\"right\">" + rn + 
		"	<input type=\"button\" onclick=\"update()\" value=\"update\" style=\"background:#CCFFFF\"/>&nbsp;&nbsp;&nbsp;" + rn + 
		"    <input type=\"button\" onclick=\"goback()\" value=\"goback\" style=\"background:#CCFFFF\"/>&nbsp;&nbsp;&nbsp;&nbsp;" + rn + 
		"	</td></tr>" + rn + 
		" </table>" + rn + 
		"  </form>" + rn + 
		"  </body>" + rn + 
		"</html>" + 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 = 
				"	            <td class=\"td3\">" + rn + 
				"	              <font color=\"#0000FF\">"+array[i]+"</font>" + rn + 
				"	            </td>" + rn ;
			sbname.append(bean);
		}
		StringBuilder sbvalue = new StringBuilder();
		for (int i = 0; i < (array.length > 4 ? 4: array.length ); i++) {
			String value = 
				"				<td width=\"20%\" class=\"td3\">" + rn + 
				"	              ${"+tableName+"List."+array[i]+"}" + rn + 
				"	            </td>" + 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 + 

		"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + rn + 
		"<html>" + rn + 
		"  <head>" + rn + 
		"    <base href=\"<%=basePath%>\">" + rn + 
		    
		"    <title>"+tableName+"详细界面</title>" + rn + 
		"    <style type=\"text/css\">" + rn + 
		"    .td2 { border-bottom: #9999FF solid 1px; }" + rn + 
		"    .td3 { border-bottom: #9999FF solid 1px;  border-right: #9999FF solid 1px; }" + rn + 
		"    </style>" + rn + 
		"    <script language=\"javascript\">	" + rn + 
		"    function  del(obj){" + rn + 
		"    			var k = window.confirm(\"are you sure to delete this item?\");" + rn + 
		"      			if(k){" + rn + 
		"                     location.href=\""+tableName+"Del\"+obj+\".do\";" + rn + 
		"        			 return true;   " + rn +          
		"      	 		  }else{" + rn + 
		"         		 	return false;    " + rn +  
		"     			  }" + rn + 
		"     }" + rn + 
		"      function update(obj){" + rn + 
		"           location.href=\""+tableName+"GoUpdate\"+obj+\".do\";" + rn + 
		"      }" + rn + 
		"      function add(){" + rn + 
		"        location.href=\""+tableName+"GoAdd.do\";" + rn + 
		"      }" + rn + 
		"      </script>" + rn + 
		
		"  </head>" + rn + 
		"  <body>" + rn + 

		
		
		
		
		" <table border=\"1\" rules=\"none\" bordercolor=\"#969696\" style=\"empty-cells: show\"    " + rn + 
		" 	width=\"650\" cellpadding=\"2\" cellspacing=\"0\">                                     " + rn + 
		" 	<tr bgcolor=\"#CCFFFF\">                                                           " + rn +     
		" 		<td colspan=\"100\" class=\"td2\">                                               " + rn + 
		" 			<font color=\"0000FF\">"+tableName+"show</font>                                  " + rn + 
		" 		</td>                          " + rn + 
		" 	</tr>  " + rn + 
		" 	<tr align=\"center\" bgcolor=\"#99CCFF\">            " + rn + 
		sbname + 		
		" 		<TD class=\"td2\">            " + rn + 
		" 			<font color=\"#0000FF\">operation</font>           " + rn +   
		" 		</TD>           " + rn + 
		" 	</tr>           " + rn + 
		" 	<c:forEach items=\"${"+tableName+"List}\" var=\""+tableName+"List\">           " + rn +  
		" 		<tr align=\"center\">           " + rn + 
		sbvalue +			
		" 			<td class=\"td2\">           " + rn +  
		" 				<a             " + rn + 
		" 					onclick=\"update(${"+tableName+"List."+array[0]+"});\">goupdate</a>           " + rn +  
		" 				<a           " + rn +  
		" 					onclick=\"del(${"+tableName+"List."+array[0]+"});\" >delete</a>           " + rn +    
		" 			</td>            " + rn +   
		" 		</tr>            " + rn + 
		" 	</c:forEach>            " + rn + 

		" 	<tr height=\"50\" align=\"right\">            " + rn + 
		" 		<td colspan=\"100%\" bgcolor=\"#CCFFFF\">            " + rn +  
		" 			<input type=\"button\"           " + rn +   
		" 				onclick=\"add()\" value=\"goadd\"            " + rn +  
		" 				style=\"background: #CCFFFF\" />          " + rn + 
		" 		</td>            " + rn +   
		" 	</tr>           " + rn +   

		" </table>            " + rn +  
		
		
		
		
		
		
		"  </body>" + rn + 
		"</html>" + 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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
	<%
		String path = request.getContextPath();
	%>
	<HEAD>
		<META http-equiv=Content-Type content="text/html; charset=UTF-8">
		<link href="<%=path%>/css/global.css" rel="stylesheet" type="text/css" />
		<title>Insert title here</title>
<script language="javascript">
function suReturn(){
		var a=document.getElementsByName("turl")[0].value;
		window.location=a;		
	}

</script>

</head>
<body>
<center>
<input type="hidden" name="turl" value="<%=path%>/${url}"></input>
<br><br>

<table width="650" border="0">
				<tr><td height="35" valign="bottom"><b>=>信息提示</b></td></tr>
				<tr><td height="30" valign="top"><hr/></td></tr>
			</table>
<table  bgcolor="" width="400"  border="0" cellspacing="0" cellpadding="0">  
  <tr><td><br/></td></tr><tr><td><br/></td></tr><tr><td><br/></td></tr><tr><td><br/></td></tr>
  <tr><td>${message1}<br/></td></tr>
   <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;${message2}<br/></td></tr>
    <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${message3}<br/></td></tr>
  
  <tr><td colspan="3" align="right" height="40"  style="padding-right:65px; padding-bottom:12px;"><input type="button" class="btn-20" onClick="suReturn()" value='返回'/></td></tr>
</table>
</center>
</body>
</html>
</center>
</body>
</html>

 

 

 

 

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

 自动生成代码源码 下载 http://download.csdn.net/detail/knight_black_bob/8412661

 

 

运行 程序的时候

 

如 学生信息表 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://knight-black-bob.iteye.com/


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

发表评论

电子邮件地址不会被公开。 必填项已用*标注

昵称 *