工具-》模板-》展开Java
选中Java类-》在编辑器中打开
修改如下:
<#if package?? && package != "">
package ${package}; </#if>
/**
* @author ${user}
* @date ${date} ${time}
*/
public class ${name} { }
(1)Java类
<#if package?? && package != "">
package ${package}; </#if>
/**
* @author ${user}
* @date ${date} ${time}
* @version V1.0
* @desc
*/
public class ${name} { }
(2)接口
<#if package?? && package != "">
package ${package}; </#if>
/**
* @author ${user}
* @date ${date} ${time}
* @version V1.0
* @desc
*/
public interface ${name} { }
(3)枚举
<#if package?? && package != "">
package ${package}; </#if>
/**
* @author ${user}
* @date ${date} ${time}
* @version V1.0
* @desc
*/
public enum ${name} { }
(4)Servlet
<#if package?? && package != "">
package ${package};
</#if> import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
<#if classAnnotation??>
import javax.servlet.annotation.WebServlet;
</#if>
<#if includeInitParams??>
import javax.servlet.annotation.WebInitParam;
</#if>
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* @author ${user}
* @date ${date} ${time}
* @version V1.0
* @desc
*/
<#if classAnnotation??>
${classAnnotation}
</#if>
public class ${name} extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
<#if java17style?? && java17style>
try (PrintWriter out = response.getWriter()) {
<#else>
PrintWriter out = response.getWriter();
try {
</#if>
out.println("${doctype?j_string}");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet ${name}</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet ${name} at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
<#if !java17style?? || !java17style>
} finally {
out.close();
</#if>
}
} <#if java15style??>
@Override
</#if>
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
} <#if java15style??>
@Override
</#if>
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}