本文主要是介绍cloth项目1增加环节,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
cloth项目——增加环节
配置文件
建包建类controller,jopo,mapper,service,util
cloth数据库的设置
:基本数据类型,Ingeter,长度,空值,主键,自动递增
detail数据库设置
:基本数据类型,长度,空值,主键,自动递增,外键设置
外键设置
com.bjsxt.util.BaseServlet
package com.bjsxt.util;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;public class BaseServlet extends HttpServlet {@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req.setCharacterEncoding("UTF-8");resp.setCharacterEncoding("UTF-8");resp.setContentType("text/html;charset=UTF-8");String method = req.getParameter("method");Class clazz = this.getClass();// 谁调用了当前方法 谁就是thistry {Method declaredMethod = clazz.getDeclaredMethod(method, HttpServletRequest.class, HttpServletResponse.class);declaredMethod.setAccessible(true);declaredMethod.invoke(this,req,resp);} catch (Exception e) {e.printStackTrace();}}
}
com.bjsxt.util.MybatisUtil/需要配置文件和jar包,js包,否则报错
package com.bjsxt.util;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.InputStream;public class MybatisUtil {private static SqlSessionFactory factory = null;private static ThreadLocal<SqlSession> th = new ThreadLocal<>();static {try {InputStream inputStream = Resources.getResourceAsStream("mybatis.xml");factory = new SqlSessionFactoryBuilder().build(inputStream);} catch (Exception e) {e.printStackTrace();}}//获得session对象public static SqlSession getSession() {SqlSession sqlSession = th.get();if (sqlSession == null) {sqlSession = factory.openSession();th.set(sqlSession);}return th.get();}//关闭session的操作public static void closed() {SqlSession sqlSession = th.get();if (sqlSession != null) {sqlSession.close();}th
这篇关于cloth项目1增加环节的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!