代码提取地址: https://pan.baidu.com/s/1s3LVtwRzRaC1xCqMB-GRhg 提取码:ex6j 扩展:目前扩展了自动处理sql脚本【注意这时对应的serverlet不能懒加载】,处理main.jsp记录展示当前用户相关信息,使用echarts代替了flash插件
代码提取路径:https://pan.baidu.com/s/166CJN920M6E3MawaYPjaVQ 提取码:izia 说明:项目利用了status2、hibernate、jsp技术, 以及使用 bootstap进行前端布局;
我关注点:Hibernate缓存包括两大类:一级缓存和二级缓存
Hibernate一级缓存又被称为“Session的缓存”。Session缓存是内置的,不能被卸载,是事务范围的缓存,在一级缓存中,持久化类的每个实例都具有唯一的OID。 Hibernate二级缓存又称为“SessionFactory的缓存”,由于SessionFactory对象的生命周期和应用程序的整个过程对应,因此Hibernate二级缓存是进程范围或者集群范围的缓存,有可能出现并发问题,因此需要采用适当的并发访问策略,该策略为被缓存的数据提供了事务隔离级别,第二级缓存是可选的,是一个可配置的插件,默认下SessionFactory不会启用这个插件。
public class Hibernate { private static Configuration config = new Configuration().configure(); //Hibernate二级缓存又称为“SessionFactory的缓存” private static SessionFactory session_factory = config.buildSessionFactory(); //Hibernate一级缓存又被称为“Session的缓存” public static Session session = session_factory.openSession(); public static Transaction t; public static void close() { session_factory.close(); } } Test //事务开始标记 Hibernate.t = Hibernate.session.beginTransaction(); User user1 = (User) Hibernate.session.get(User.class, user.getUser_id()); //事务提交 Hibernate.t.commit();
代码提取: https://pan.baidu.com/s/1vgCeqCOnKPrPQOxmY0aXUA 提取码:5yvm 说明:项目利用了servlet、c3p0数据库连接池技术[中间使用了itcast的工具包]、jsp技术, 以及使用 easyUI进行前端布局; 比较关注的点有:该程序中业务调用都是基于url进行反射调用,例如http://localhost:8080/express/UserServlet?method=seclectAll ,[servelt拦截器配置名称]?[固定请求参数名]=[调用的方法名称]
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8");//处理响应编码 /** * 1. 获取method参数,它是用户想调用的方法 2. 把方法名称变成Method类的实例对象 3. 通过invoke()来调用这个方法 */ String methodName = request.getParameter("method"); Method method = null; /** * 2. 通过方法名称获取Method对象 */ try { method = this.getClass().getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class); } catch (Exception e) { throw new RuntimeException("您要调用的方法:" + methodName + " 它不存在!", e); } /** * 3. 通过method对象来调用它 */ try { String result = (String) method.invoke(this, request, response); if (result != null && !result.trim().isEmpty()) {//如果请求处理方法返回不为空 int index = result.indexOf(":");//获取第一个冒号的位置 if (index == -1) {//如果没有冒号,使用转发 request.getRequestDispatcher(result).forward(request, response); } else {//如果存在冒号 String start = result.substring(0, index);//分割出前缀 String path = result.substring(index + 1);//分割出路径 if (start.equals("f")) {//前缀为f表示转发 request.getRequestDispatcher(path).forward(request, response); } else if (start.equals("r")) {//前缀为r表示重定向 response.sendRedirect(request.getContextPath() + path); } } } } catch (Exception e) { throw new RuntimeException(e); } }
代码提取:https://pan.baidu.com/s/1a06_ZJxuaMJDTTO1vXuEPA 提取码:tacs 说明:项目利用了spring、springmvc、mybatis技术【关注点ssm相关的架构,以及单元测试(junit)】,说明:运行发现该项目非完整版,还有许多地方待整改。
public class TestJdbc { private String str = "11"; @Test public void test(){ System.out.println("132"); } @Before public void testSpring(){ //说明:配置文件的路径需要使用项目部署后的路径 特别注意是否需要classpath* ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:conf/spring-*.xml"); UserController bean = (UserController) context.getBean("userController"); try { System.out.println(bean.execute("sysadmin", "1")); } catch (Exception e) { e.printStackTrace(); } } }获取代码:https://pan.baidu.com/s/1Lq7PRpW8Eyk-N5o0VeJ2Cw 提取码:j1jj 说明:项目利用了servlet3.0、c3p0、jsp技术; 关于servlet3.0 @WebServlet说明,通过@WebServlet标签配置URL映射。
1. @WebServlet("/login") /** 注意这里是使用了servlet3.0的语法 等效与在web.xml中配置 * <servlet> * <servlet-name>Log</servlet-name> * <servlet-class>com.crose.StudentCourse.web.LoginServlet</servlet-class> * </servlet> * <servlet-mapping> * <servlet-name>Log</servlet-name> * <url-pattern>/login/.*</url-pattern> * </servlet-mapping> * * 继承BaseServlet */ public class LoginServlet extends BaseServlet {} 2.通过baseServlet管理资源 /** * 统一处理HttpServlet请求 */ public class BaseServlet extends HttpServlet { /** * 核心思路通 * 准备:通过@WebServer已配置了请求资源位置对应的资源及为子类 * 第一步:过请求指定请求的方法名称 * 第二步:通过该方法名称反射到对应的实现方法 * @param request * @param response * @throws ServletException * @throws IOException */ @Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { // 1.获取子类 创建子类或者调用子类的时候 this代表的是子类对象 @SuppressWarnings("rawtypes") Class clazz = this.getClass(); // 2.获取请求的方法 String m = request.getParameter("method"); if (m == null) { m = "index"; } // 3.获取方法对象 Method method = clazz.getMethod(m, HttpServletRequest.class, HttpServletResponse.class); // 4.让方法执行 返回值为请求转发的路径 String s = (String) method.invoke(this, request, response);//相当于 userservlet.add(request,response) // 5.判断s是否为空 if (s != null) { request.getRequestDispatcher(s).forward(request, response); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } }
链接:https://pan.baidu.com/s/1MBYK1eaRQo8J_m1z_vz98Q 提取码:cfcn 说明:项目利用了servlet、jsp技术;
持续更新中
说明更新的项目来着小白日常搜集,学习相关逻辑,并加入了自己的设想,以及自己学习的内容与其中。 如有侵权,请联系处理谢谢。