Exception processing template "updateUser": Error resolving template [updateUser], template might no

springboot+thymeleaf中,访问请求updateUser时报错,报错内容如下:

2019-07-29 16:17:10.197 DEBUG 9820 --- [nio-8080-exec-4] c.l.y.mapper.UserMapper.findByUserId     : ==>  Preparing: select * from user where id = ? 
2019-07-29 16:17:10.230 DEBUG 9820 --- [nio-8080-exec-4] c.l.y.mapper.UserMapper.findByUserId     : ==> Parameters: 1(Integer)
2019-07-29 16:17:10.267 DEBUG 9820 --- [nio-8080-exec-4] c.l.y.mapper.UserMapper.findByUserId     : <==      Total: 1
2019-07-29 16:17:12.474 DEBUG 9820 --- [nio-8080-exec-3] c.l.y.mapper.UserMapper.updateUserInfo   : ==>  Preparing: update user set name=?,age=?,address=?,qq=?,weixin=?,email=?,sex=?,birthday=?,account=? where id=? 
2019-07-29 16:17:12.477 DEBUG 9820 --- [nio-8080-exec-3] c.l.y.mapper.UserMapper.updateUserInfo   : ==> Parameters: 王二麻子222(String), 24(Integer), 上海宝山(String), 12345678910(String), weixin123(String), 1213@123.com(String), 1(Integer), 1992-12-26 22:00:00.0(Timestamp), admin(String), 1(Integer)
2019-07-29 16:17:12.479 DEBUG 9820 --- [nio-8080-exec-3] c.l.y.mapper.UserMapper.updateUserInfo   : <==    Updates: 1
2019-07-29 16:17:12.493 ERROR 9820 --- [nio-8080-exec-3] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-3] Exception processing template "updateUser": Error resolving template [updateUser], template might not exist or might not be accessible by any of the configured Template Resolvers

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [updateUser], template might not exist or might not be accessible by any of the configured Template Resolvers
	at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]

Java代码段:

package com.lucifer.youfanshopuser.controller;

import com.lucifer.youfanshopuser.model.User;
import com.lucifer.youfanshopuser.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: lucifer
 * @date: 2019/7/29
 * @description:
 */
@Controller
public class UserController {

    @Resource
    UserService userService;

    @GetMapping(value = "/toUpdateUser")
    public String toUpdateUser(int id,Model model){
        User user =  userService.findByUserId(id);
        model.addAttribute("user",user);
        return "userUpdate";
    }

    @PostMapping(value = "/updateUser")
    public void updateUser(User user){
        userService.updateUserInfo(user);
    }



}

解决办法:

由于用的是@Controller而非@RestController注解,所以这里返回json串,需要加上@ResponseBody注解即可,否则返回的是静态页面,而不是json串,由于没有找到静态页面所以报错;

    @PostMapping(value = "/updateUser")
    @ResponseBody
    public void updateUser(User user){
        userService.updateUserInfo(user);
    }

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:C马雯娟 返回首页