ssm框架项目的时候tomcat启动都正常,但是点击图片跳转页面路径中间就会缺少/tickert,导致找不到页面,然而点击导演名则会路径完整正常跳转,我这路径配置是哪里配置出问题了呢
controller层代码
package com.duing.controller;
import com.duing.service.FilmService;
import com.duing.vo.FilmDetailVo;
import com.duing.vo.FilmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class FilmController {
@Autowired
private FilmService filmService;
@RequestMapping("/filmList")
@ResponseBody
public List selectAll(){
List filmVos = filmService.selectAll();
return filmVos;
}
@RequestMapping("/home")
public String home(Model model){
System.out.println("接受首页请求");
List filmVoList = filmService.selectAll();
model.addAttribute("filmVoList",filmVoList);
return "home";
}
// 接受请求参数
@RequestMapping("/filmInfo")
public String filmInfo(@RequestParam String filmId, Model model){
FilmDetailVo detailVo=filmService.findFilmById(filmId);
model.addAttribute("detailVo",detailVo);
return "detail";
}
}
dao层
package com.duing.dao;
import com.duing.entity.Film;
import java.util.List;
public interface FilmDao {
List getList();
Film getFilmById(String filmId);
}
跟数据库映射的实体类
package com.duing.entity;
import java.io.Serializable;
import java.util.Date;
// 实体类 跟数据库的表映射
public class Film implements Serializable {
private static final long serialVersionUID = -4427069375523038931L;
private long id;
private String film_id;
private String name;
private String director;
private String player;
private String type;
private String country;
private int length;
private String synopsis;
private Date play_time;
private String img_path;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFilm_id() {
return film_id;
}
public void setFilm_id(String film_id) {
this.film_id = film_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getPlayer() {
return player;
}
public void setPlayer(String player) {
this.player = player;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getSynopsis() {
return synopsis;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public Date getPlay_time() {
return play_time;
}
public void setPlay_time(Date play_time) {
this.play_time = play_time;
}
public String getImg_path() {
return img_path;
}
public void setImg_path(String img_path) {
this.img_path = img_path;
}
}
service层
package com.duing.entity;
import java.io.Serializable;
import java.util.Date;
// 实体类 跟数据库的表映射
public class Film implements Serializable {
private static final long serialVersionUID = -4427069375523038931L;
private long id;
private String film_id;
private String name;
private String director;
private String player;
private String type;
private String country;
private int length;
private String synopsis;
private Date play_time;
private String img_path;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFilm_id() {
return film_id;
}
public void setFilm_id(String film_id) {
this.film_id = film_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getPlayer() {
return player;
}
public void setPlayer(String player) {
this.player = player;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getSynopsis() {
return synopsis;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public Date getPlay_time() {
return play_time;
}
public void setPlay_time(Date play_time) {
this.play_time = play_time;
}
public String getImg_path() {
return img_path;
}
public void setImg_path(String img_path) {
this.img_path = img_path;
}
}
service接口
package com.duing.service;
import com.duing.vo.FilmDetailVo;
import com.duing.vo.FilmVo;
import java.util.List;
public interface FilmService {
List selectAll();
FilmDetailVo findFilmById(String filmId);
}
vo数据
package com.duing.vo;
import java.util.Date;
public class FilmDetailVo {
private String filmId;
private String name;
private String director;
private String player;
private String type;
private String country;
private int length;
private String synopsis;
private Date playTime;
private String imgPath;
public String getFilmId() {
return filmId;
}
public void setFilmId(String filmId) {
this.filmId = filmId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getPlayer() {
return player;
}
public void setPlayer(String player) {
this.player = player;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getSynopsis() {
return synopsis;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public Date getPlayTime() {
return playTime;
}
public void setPlayTime(Date playTime) {
this.playTime = playTime;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
}
package com.duing.vo;
// 视图层对象 用来展示给用户使用
public class FilmVo {
private String filmId;
private String name;
private String director;
private String imgPath;
public String getFilmId() {
return filmId;
}
public void setFilmId(String filmId) {
this.filmId = filmId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgpath) {
this.imgPath = imgpath;
}
}
mapper配置文件
package com.duing.vo;
// 视图层对象 用来展示给用户使用
public class FilmVo {
private String filmId;
private String name;
private String director;
private String imgPath;
public String getFilmId() {
return filmId;
}
public void setFilmId(String filmId) {
this.filmId = filmId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgpath) {
this.imgPath = imgpath;
}
}
mybatis配置
configuration
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<mappers>
<package name="com.duing.dao"/>
mappers>
configuration>
spring配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
https://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<context:component-scan base-package="com.duing.service"/>
<context:property-placeholder location="classpath:druid.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
bean>
<bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:/mybatis.xml"/>
<property name="mapperLocations" value="classpath:mappers/*.xml"/>
bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="factory"/>
<property name="basePackage" value="com.duing.dao"/>
bean>
beans>
springmvc配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<context:component-scan base-package="com.duing.controller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
bean>
<mvc:resources mapping="/img/**" location="/img/"/>
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:annotation-driven/>
beans>
jsp文件
<%--
Created by IntelliJ IDEA.
User: 22018
Date: 2022/7/28
Time: 15:23
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Titletitle>
head>
<body>
<img src="${pageContext.request.contextPath}${detailVo.imgPath}">
${detailVo.name}p>
${detailVo.country}p>
${detailVo.length}分钟p>
${detailVo.director}p>
${detailVo.player}p>
${detailVo.synopsis}p>
div>
body>
html>
web配置
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:/spring.xmlparam-value>
context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<servlet>
<servlet-name>DispatcherServletservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<init-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:/springmvc.xmlparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>DispatcherServletservlet-name>
<url-pattern>/url-pattern>
servlet-mapping>
<filter>
<filter-name>characterEncodingFilterfilter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
<init-param>
<param-name>encodingparam-name>
<param-value>utf-8param-value>
init-param>
<init-param>
<param-name>forceRequestEncodingparam-name>
<param-value>trueparam-value>
init-param>
<init-param>
<param-name>forceResponseEncodingparam-name>
<param-value>trueparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>characterEncodingFilterfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
web-app>
index文件
<html>
<body>
Hello World!h2>
<jsp:forward page="/home"/>
body>
html>