美文网首页
springboot视图层技术

springboot视图层技术

作者: 李霖神谷 | 来源:发表于2019-11-28 15:46 被阅读0次

1.springboot与jsp的整合
jsp页面,如果发现new中没有jsp页面可以从protectstructure中设置选中web,路径选中当前项目,就可以在项目中任意位置中设置jsp文件了。

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<table>
    ${userlist}
</table>
</body>
</html>

controller层:

@Controller
public class UserController {
@RequestMapping("/show")
    public String sgowUser(Model modle){
        List<user> userList=new ArrayList<>();
        userList.add(new user("刘岩",1));
        userList.add(new user("刘老根",1));
        userList.add(new user("大叫",1));
        modle.addAttribute("userlist",userList);
        return  "userLists";
    }
}

需要在配置文件中,配置

spring.mvc.view.prefix=/WEB-INF/JSP/
spring.mvc.view.suffix=.jsp

添加的依赖:

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.6</version>
        </dependency>

2.springboot与freemark的整合:
首先需要在配置文件中配置:

spring.freemarker.tempalte-loader-path=classpath:/templates
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.suffix=.ftl

freemarker的静态文件是ftl格式的

<html>
<head>
    <title>Title</title>
</head>
<body>
hhhhh
</body>
</html>

pom文件配置:

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

相关文章

网友评论

      本文标题:springboot视图层技术

      本文链接:https://www.haomeiwen.com/subject/nlgvwctx.html