IDEA中使用Freemarker以及报Cannot resolve MVC View 'xxx'错

一开始新建,添加web、Apathe freemarker模版,这是项目的主要目录内容:
IDEA中使用Freemarker以及报Cannot resolve MVC View 'xxx'错_第1张图片

// User.java
package org.selina.freemarker2.User;

public class User {
    private Long id;
    private String username;
    private String password;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
// UserController.java	注意一定要加@Controller
package org.selina.freemarker2.controller;

import org.selina.freemarker2.User.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;
@Controller
public class UserController {
    @GetMapping("/user")
    public String user(Model model){
        List<User> users=new ArrayList<>();
        for(int i=0;i<10;i++)
        {
            User user=new User();
            user.setId((long)i);
            user.setUsername("javagirl"+i);
            user.setPassword("123"+i);
            users.add(user);
        }
        model.addAttribute("users",users);
        return "user";
    }
}


// user.ftl
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>111</title>
</head>
<body>
    <table>
        <tr>
            <td>编号</td>
            <td>用户名</td>
            <td>密码</td>
        </tr>
        <#list users as u>
            <tr>
                <td>${u.id}</td>
                <td>${u.username}</td>
                <td>${u.password}</td>
            </tr>
        </#list>
    </table>
</body>
</html>

项目中使用到user,都会有波浪线,没管他,运行
IDEA中使用Freemarker以及报Cannot resolve MVC View 'xxx'错_第2张图片
IDEA中使用Freemarker以及报Cannot resolve MVC View 'xxx'错_第3张图片
结果报错:
IDEA中使用Freemarker以及报Cannot resolve MVC View 'xxx'错_第4张图片
错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [user]: would dispatch back to the current handler URL [/user] again. Check your ViewResolver setup!
This may be the result of an unspecified view, due to default view name generation.
有道一下:
service()为上下文中的servlet [dispatcherServlet]抛出异常[循环视图路径[user]:将再次调度回当前处理程序URL [/user]。检查你的ViewResolver设置!
这可能是未指定视图的结果,因为默认视图名生成。

原来还要在application.properties配置文件中对freemarker进行配置!

IDEA中使用Freemarker以及报Cannot resolve MVC View 'xxx'错_第5张图片
再运行,好了
IDEA中使用Freemarker以及报Cannot resolve MVC View 'xxx'错_第6张图片

你可能感兴趣的:(java,freemarker,spring,intellij,idea)