Spring Thymeleaf img未调用弹簧控制器

Spring Thymeleaf img未调用弹簧控制器,spring,spring-boot,thymeleaf,Spring,Spring Boot,Thymeleaf,以下是我的gradle依赖项: dependencies { compile("org.springframework.boot:spring-boot-starter-thymeleaf") compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework:spring-jdbc:4.1.0.RELEASE") compile("org.sp

以下是我的gradle依赖项:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework:spring-jdbc:4.1.0.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("mysql:mysql-connector-java:5.1.+")
    compile("org.webjars:bootstrap:3.0.3")
    compile("org.webjars:jquery:2.0.3-1")
    compile("org.springframework.security.oauth:spring-security-oauth2:2.0.7.RELEASE")  
    compile("org.springframework.security:spring-security-test:4.0.0.RELEASE")
    compile("org.thymeleaf:thymeleaf-spring4")
    compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("com.google.code.gson:gson:2.2.4")
    compile("javax.mail:mail:1.4.5")
    compile("org.springframework:spring-context-support:3.2.2.RELEASE")
    compile("org.apache.commons:commons-io:1.3.2")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

    testCompile("junit:junit")
}
我在控制器中定义了一个方法:

@ResponseBody
    @RequestMapping(value = "/mainMenu/companyOfficeMainMenu/imagetest/{server_image_id}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
    public byte[] testphoto(@PathVariable("server_image_id") Long server_image_id) throws IOException {



        Image notUpdatedImage = mobileManagment.getImage(server_image_id);

        String locationRoot =  env.getProperty("location.sever.root");
        String locationOfCompanyData =  env.getProperty("location.compay.data");
        String locationOfImage =  env.getProperty("location.compay.media.images");


        String storeImageName = 
                locationOfCompanyData 
                + File.separator
                + locationOfImage 
                + File.separator
                + notUpdatedImage.getCompany_id() 
                + File.separator +
                + notUpdatedImage.getServer_questionnaire_attempt_key()
                + File.separator 
                + notUpdatedImage.getImage_name();      
        File uploadedFile = new File(locationRoot, storeImageName);             
        InputStream inputStream = new FileInputStream(uploadedFile.getAbsolutePath());


        return IOUtils.toByteArray(inputStream);
    }
在Thymeleaf,我试着称之为:

<img th:src="@{/mainMenu/companyOfficeMainMenu/imagetest/${object.getServer_image_id()}}" />

我在控制器中的方法中有一个断点,但它没有被调用

这里还有另一个未被调用的方法:

@RequestMapping(value = "/mainMenu/companyOfficeMainMenu/image/{server_image_id}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> getImage(@PathVariable("server_image_id") Long server_image_id) throws IOException {

        Image notUpdatedImage = mobileManagment.getImage(server_image_id);

        String locationRoot =  env.getProperty("location.sever.root");
        String locationOfCompanyData =  env.getProperty("location.compay.data");
        String locationOfImage =  env.getProperty("location.compay.media.images");


        String storeImageName = 
                locationOfCompanyData 
                + File.separator
                + locationOfImage 
                + File.separator
                + notUpdatedImage.getCompany_id() 
                + File.separator +
                + notUpdatedImage.getServer_questionnaire_attempt_key()
                + File.separator 
                + notUpdatedImage.getImage_name();      
        File uploadedFile = new File(locationRoot, storeImageName);             
        InputStream inputStream = new FileInputStream(uploadedFile.getAbsolutePath());


        byte[] imageContent = IOUtils.toByteArray(inputStream);
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.IMAGE_PNG);
        return new ResponseEntity<byte[]>(imageContent, headers, HttpStatus.OK);
    }


    @ResponseBody
    @RequestMapping(value = "/mainMenu/companyOfficeMainMenu/imagetest/{server_image_id}", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
    public byte[] testphoto(@PathVariable("server_image_id") Long server_image_id) throws IOException {



        Image notUpdatedImage = mobileManagment.getImage(server_image_id);

        String locationRoot =  env.getProperty("location.sever.root");
        String locationOfCompanyData =  env.getProperty("location.compay.data");
        String locationOfImage =  env.getProperty("location.compay.media.images");


        String storeImageName = 
                locationOfCompanyData 
                + File.separator
                + locationOfImage 
                + File.separator
                + notUpdatedImage.getCompany_id() 
                + File.separator +
                + notUpdatedImage.getServer_questionnaire_attempt_key()
                + File.separator 
                + notUpdatedImage.getImage_name();      
        File uploadedFile = new File(locationRoot, storeImageName);             
        InputStream inputStream = new FileInputStream(uploadedFile.getAbsolutePath());


        return IOUtils.toByteArray(inputStream);
    }
@RequestMapping(value=“/mainMenu/companyOfficeMainMenu/image/{server\u image\u id}”,method=RequestMethod.GET)
public ResponseEntity getImage(@PathVariable(“server\u image\u id”)Long server\u image\u id)引发IOException{
Image notupdateImage=mobileMagment.getImage(服务器映像id);
字符串locationRoot=env.getProperty(“location.sever.root”);
字符串locationOfCompanyData=env.getProperty(“location.compay.data”);
字符串locationOfImage=env.getProperty(“location.compay.media.images”);
字符串storeImageName=
公司数据的位置
+文件分隔符
+图像位置
+文件分隔符
+notupdateImage.getCompany_id()
+文件分隔符+
+NotUpdateImage.getServer\u调查问卷\u尝试\u密钥()
+文件分隔符
+notupdateImage.getImage_name();
File uploadedFile=新文件(locationRoot,storeImageName);
InputStream InputStream=新文件InputStream(uploadedFile.getAbsolutePath());
字节[]imageContent=IOUtils.toByteArray(inputStream);
最终HttpHeaders=新HttpHeaders();
headers.setContentType(MediaType.IMAGE\u PNG);
返回新的ResponseEntity(imageContent、Header、HttpStatus.OK);
}
@应答器
@RequestMapping(value=“/mainMenu/companyOfficeMainMenu/imagetest/{server\u image\u id}”,method=RequestMethod.GET,products=MediaType.image\u JPEG\u value)
公共字节[]testphoto(@PathVariable(“server\u image\u id”)Long server\u image\u id)引发IOException{
Image notupdateImage=mobileMagment.getImage(服务器映像id);
字符串locationRoot=env.getProperty(“location.sever.root”);
字符串locationOfCompanyData=env.getProperty(“location.compay.data”);
字符串locationOfImage=env.getProperty(“location.compay.media.images”);
字符串storeImageName=
公司数据的位置
+文件分隔符
+图像位置
+文件分隔符
+notupdateImage.getCompany_id()
+文件分隔符+
+NotUpdateImage.getServer\u调查问卷\u尝试\u密钥()
+文件分隔符
+notupdateImage.getImage_name();
File uploadedFile=新文件(locationRoot,storeImageName);
InputStream InputStream=新文件InputStream(uploadedFile.getAbsolutePath());
返回IOUtils.toByteArray(inputStream);
}
当我在屏幕上按f12时,我可以看到图像标签的输出:

<img src="/mainMenu/companyOfficeMainMenu/image/${object.getServer_image_id()}">

这看起来不对

当我输出时,我得到27(这是正确的)

您没有正确使用语法。您需要在大括号中指定一个参数(类似于@RequestMapping),例如
{server\u image\u id}
。然后指定值,用括号
(server\u image\u id=${object.getServer\u image\u id()

总而言之:

<img th:src="@{/mainMenu/companyOfficeMainMenu/imagetest/{server_image_id}(server_image_id=${object.getServer_image_id()})}" />


当您在浏览器中获得页面输出时,按F12键,查看
img
标记的
src
属性发生了什么变化。您可能在呈现页面或将标记指向其他位置时出错。能否显示
对象的代码。getServer\u image\u ids()
?嘿,我已将您的请求添加到帖子的底部。肯,有一个输入错误,我把方法改为getServer\u image\u id(),而不是getServer\u image\u id(),但它仍然不起作用。
<img th:src="@{/mainMenu/companyOfficeMainMenu/imagetest/{server_image_id}(server_image_id=${object.getServer_image_id()})}" />