05-配置和编码流程

starrylsi
2024-09-16 / 0 评论 / 18 阅读 / 正在检测是否收录...

题外内容

需要理解: forward和redirect的区别
问题: 一开始就需要把amidn,student,teacher抽象出来吗(面向对象分析)
问题: 什么是类路径
问题: 如何确定是没有@Autowired引起
注意: jdbc连接的url配置参数,mysql8.0和5.0两种版本的配置方式是不同的
理解: 目录WEB-INF(Web Application Archive Information)

介绍WEB-INF目录

这个目录是 Java Web 应用程序中用于存放私有数据和配置文件的区域,这些内容对客户端是不可见的,只有服务器端可以访问。WEB-INF 目录提供了一种机制,用于隔离和保护应用程序的敏感信息,如类文件、配置文件和库文件等。

1.spring-mvc配置

  • 掌握:
    1.放行静态资源如何配置
    2.springmvc扫描注解如何配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

  <!-- springmvc扫描controller注解 -->
  <context:component-scan base-package="com.zhuama" use-default-filters="false">
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  </context:component-scan>
  
  <!-- 视图解析器 -->
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/files/" />
      <property name="suffix" value=".jsp" />
  </bean>
  
  
  <!-- 静态资源放行 和 注解驱动 -->
  <mvc:default-servlet-handler/>
  <mvc:annotation-driven/>
</beans>

spring mvc编写顺序

采用领导式思维模式: 总分的形式编写代码

  1. 将html文件改为jsp文件
  2. 编写controller外壳,让页面显示(注意理清是直接分发还是经过处理后分发)

    • 直接分发就是 .....jsp(直接写页面路径)
    • 经过处理后分发 .....(写需要处理的路径经过service后添加上页面路径)
  3. 分析页面需要的数据
  4. 编写controller分发逻辑
  5. 编写service层
  6. 编写dao层
0

评论 (0)

取消