发表于: 2020-06-08 22:40:17
2 1398
今天完成的事情:
1. 跑通 tiles demo
2. 完成了静态主页的拆分,并且用 tiles 重组复原页面
3. 建立任务四数据库
优秀学员信息表
id | int |
|
name | varchar | 姓名 |
img | varchar | 头像图片地址 |
major | varchar | 学习方向 |
introduction | varchar | 学员简介 |
updateat | timestamp | 更新时间 |
createat | timestamp | 创建时间 |
职业方向
(这里的 学习人数 字段其实就是相应的细分职业中的学习人数之和。之所以这里再写一次是因为首页的访问量比较大,每次都去细分职业表查询效率太低。
缺点就是每次有新人加入学习的话也要更新一下这里的学习人数)
id | int |
|
career_direction | varchar | 职业方向 |
number_of_student | int | 学习人数 |
updateat | timestamp | 更新时间 |
createat | timestamp | 创建时间 |
职业细分
id | int |
|
career_direction | int | 职业方向id |
major | varchar | 学习方向 |
imges | varchar | 图片地址 |
introduction | varchar | 简介 |
threshold | int | 学习门槛 |
difficulty | int | 学习难度 |
growth_cycle | varchar | 成长周期 |
scarcity | int | 稀缺程度(市场需求量) |
salary | varchar | 初始薪资 |
coefficient | float | 薪资增长系数 |
number_of_student | int | 在学人数 |
employed_population | int | 就业人数 |
prompt | varchar | 提示信息 |
updateat | timestamp | 更新时间 |
createat | timestamp | 创建时间 |
轮播图
id | int |
|
img | varchar | 图片地址 |
updateat | timestamp | 更新时间 |
createat | timestamp | 创建时间 |
友情连接、合作企业、微信图片什么的我就不做数据库了。
遇到的问题:
1. spring-servlet.xml 中添加 mvc:annotation-driven 爆红线
报错信息:通配符的匹配很全面, 但无法找到元素 'mvc:annotation-driven' 的声明
原因是:虽然在xml文件上方声明了mvc,但没有配置此声明对应的文件信息,正确配置如下:
<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/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd ">
意思就是,mvc声明用http://www.springframework.org/schema/mvc/spring-mvc.xsd这个文件来解析
解决方法:加上浅蓝色标注部分
2. css、js、imges 静态文件被拦截
原因:客户端没有访问 WEB-INF 文件夹的权限。
这个我是知道的,但是做项目的时候跟着 jsp 文件夹一起建立了静态资源文件夹,发现访问不了就绕不出这个坑了··· 折腾了一个小时才想起来这回事。
解决方法:把静态资源放到 webapp 文件夹下,只要不是在 WEB-INF 文件夹就好。
顺便记录一下开启静态资源访问的一种方法:
文件目录:
spring-servlet.xml
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:resources mapping="/img/**" location="/imges/"/>
<mvc:resources mapping="/js/**" location="/js/"/>
web.xml
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!--<url-pattern>/</url-pattern>-->
<url-pattern>*.do</url-pattern>
</servlet-mapping>
3. 往 tiles.xml 里传参的方法(特别注意标红的部分,否则占位符会当作字符串处理)
controller.java
@RequestMapping(value = "test.do")
public ModelAndView test(){
System.out.println("----------------------");
System.out.println("test.do");
ModelAndView modelAndView = new ModelAndView("contact");
modelAndView.addObject("title", "首页");
modelAndView.addObject("center", "pthome");
return modelAndView;
}
tiles.xml
<definition name="contact" extends="base.definition">
<put-attribute name="title" expression="${title}" />
<put-attribute name="center" expression="/WEB-INF/jsp/${center}.jsp" />
</definition>
这里传参来填入网页的 title 与 中间的主题页面文件名,就不用在 tiles.xml 文件中写很多次 <definition> 标签了。
收获:
1. 对 tiles 有了一个初步的认知,并且实际体会了复用 jsp 的便利性
明天的计划:
1. 完成 service 与 controller
2. 学习 c 标签,往网页填充数据
项目上传 github,主分支目前只有最简单的 tiles demo,拆分的网页目前位于 Split-page 分支。
评论