0.0.2 注释

Signed-off-by: markma <750975972@qq.com>
master
markma 3 years ago
parent b161fcb07c
commit 4210eaaed8

@ -1,8 +1,6 @@
package controller;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import javax.servlet.ServletException;
@ -15,6 +13,16 @@ import utils.*;
/**
* Servlet implementation class SelectServlet
*/
/**
* service(
* dao
* entity
* utils
* ->controller->dao->controller->
* @author markma
* @date :202184 9:01:56
*/
public class SelectServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@ -39,26 +47,43 @@ public class SelectServlet extends HttpServlet {
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/**
* 1.UTF-8
*/
String undName = new String(request.getParameter("Name").getBytes("iso-8859-1"), "utf-8");
String undPro = new String(request.getParameter("Pro").getBytes("iso-8859-1"), "utf-8");
if(undName != null || undPro != null)
{
/**
* 2.NameProperties
*/
NameProDivider divNamePro = new NameProDivider(undName,undPro);
divNamePro.divideName();
divNamePro.dividePro();
/**
* 3.Namehero
*/
HeroDao hd = new HeroDao();
List<Hero> heroList = hd.find(divNamePro.getDividedName());
/**
* 4.hero,properties
*/
PropertiesDao pd = new PropertiesDao();
String[] printHeroInfo = pd.find(heroList, divNamePro.getDividedProperties());
/**
* 5.
*/
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
ReturnWriter returnwriter = new ReturnWriter();
returnwriter.write(printHeroInfo);
/**
* 6.
*/
request.getRequestDispatcher("return.jsp").forward(request, response);
}

@ -4,13 +4,29 @@ import java.util.List;
import org.apache.ibatis.session.SqlSession;
import entity.*;
import utils.*;
/**
*
*
* @author markma
* @date :202184 9:13:16
*/
public class HeroDao
{
public List<Hero> find(String[] dividedName)
{
/**
* 1.
*/
List<Hero> heroList = new ArrayList<Hero>();
/**
* 2.
*/
SqlSession session = DBUtils.getConnection();
HeroMapper mapper = session.getMapper(HeroMapper.class);
/**
* 3.
*/
for(String name:dividedName)
{
if(name.equals("-a"))
@ -26,6 +42,9 @@ public class HeroDao
}
}
}
/**
* 4.
*/
session.commit();
return heroList;
}

@ -2,12 +2,24 @@ package dao;
import java.util.List;
import entity.Hero;
/**
*
*
* @author markma
* @date :202184 9:15:23
*/
public class PropertiesDao
{
public String[] find(List<Hero> heroList,String[] dividedPro)
{
/**
* 1.
*/
String pro = dividedPro[0];
String[] findPro = new String[heroList.size()];
/**
* 2.
*/
int j = 0;
if(pro.equals("-a"))
{
@ -25,6 +37,9 @@ public class PropertiesDao
j++;
}
}
/**
* 3.
*/
return findPro;
}
}

@ -7,7 +7,11 @@ import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
//controller层调用 service层 service层在调用dao层dao层处理完数据返回 service层 service层在返回controller层controller层最终返回前端。
/**
*
* @author markma
* @date :202184 9:18:44
*/
public class DBUtils
{
public static SqlSession getConnection()
@ -15,15 +19,18 @@ public class DBUtils
SqlSession session = null;
try
{
/**
* 1.
*/
SqlSessionFactory factory = new SqlSessionFactoryBuilder()
.build(Resources.getResourceAsReader("utils/config.xml"));
// 一次会话
// Connection
/**
* 2.
*
* mybatis
*/
session = factory.openSession();
// 获得了接口的一个具体实现(实例)
// mybatis 根据注解创建了接口的实例
}
catch (IOException e)

@ -1,6 +1,6 @@
package utils;
/**
* Args
*
*
* :,->dividedName[0]="刘备",dividedName[1]="曹操"
* :ID,attackValue->dividedProperties[0]="ID",dividedName[1]="attackValue"

@ -1,16 +1,23 @@
package utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* html
*
* @author markma
* @date :202184 9:20:27
*/
public class ReturnWriter
{
public void write(String [] out) throws IOException
{
FileWriter fileWriterClear = new FileWriter("D:\\eclipse-workspace\\Hero-Select-Online\\src\\main\\webapp\\return.jsp");
File file = new File("D:\\eclipse-workspace\\Hero-Select-Online\\src\\main\\webapp\\return.jsp");
FileWriter fileWriterClear = new FileWriter(file);
fileWriterClear.close();
FileWriter fileWriter = new FileWriter("D:\\eclipse-workspace\\Hero-Select-Online\\src\\main\\webapp\\return.jsp",true);
FileWriter fileWriter = new FileWriter(file,true);
fileWriter.write("<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>\n"
+"<html>\n<body>\n");
for(String s:out)

@ -2,6 +2,7 @@
<html>
<body>
<p>Hero [name=刘备,ID=1]</p>
<p>共找到1条结果</p>
<p>Hero [name=曹操,ID=2]</p>
<p>共找到2条结果</p>
</body>
</html>

Loading…
Cancel
Save