SpringBoot第三篇:跳转到html页面

照例,目录结构

 

在上一篇的基础上改动如下:

1.在pom.xml中添加依赖如下:

      <!-- HTML -->
       <dependency>
           <groupId>org.thymeleaf</groupId>
           <artifactId>thymeleaf-spring4</artifactId>
           <version>2.1.5.RELEASE</version>
       </dependency>

2.在application.properties中指定页面的位置和后缀

#视图层控制
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
spring.mvc.static-path-pattern=/static/**

3.在UserController.java

package com.cxs.controller;


import com.cxs.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.cxs.service.UserService;

@Controller
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
 private UserService userService;

    @RequestMapping(value = "/index")
    public String Hello() {
      return "user/index";
    }



    @RequestMapping(value = "/show", method = RequestMethod.GET)
    @ResponseBody
    public String findUserByName(@RequestParam(value = "name") String name) {
     User user=  userService.findUserByName(name);
        if (null != user)
            return "ID:"+ user.getUserId() + "--------------------用户名:" + user.getUserName()+ "--------------------密码:" + user.getPassword();
        else return "null";
    }

}

 

4.新建一个index.html,在里面写上“到此一游”!

5.访问

http://localhost:8090/demo/user/index

 

本来还想写一篇跳转到jsp页面的,但想一下jsp好像已经不怎么用了。springboot配上jsp大概就像时尚女郎穿着比基尼脚踏一双老北京布鞋,怎么想怎么感觉不搭。

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值