zoukankan      html  css  js  c++  java
  • ________________初学springboot12

    规定请求方式 RequestMapping(value="/hello" Method=RequestMethod.GET)

    @RequestMapping(value="/hello" Method="Request.Method.GET")

    @ResponseBody

    public String  home(){

      return "user home";

    }

    //建议使用以下

    @ResponseBody

    @GetMapping("/hello")//PostMapping

    public String show(@RequestParam("username")String username,@RequestParam("password")String password){

    //@RquestParam 默认必须提供值

    return "user show"+username+"__---"+password;

     可以接收HttpServletRequest

    @ResponseBody

    @GetMapping("/hello")

    public String edit(HttpServletRequest req){

    return "server:"+req.getRemoteHost();

    }

    public static void main(String[] args) {

    SpringApplication.run(App.class, args);

    }

    }

    @SpringBootApplication

    @Controller

    @SpringBootConfiguration

    public class App {

    @ResponseBody

    @GetMapping("hello")

    //public String show(@RequestParam(value="username",required=false)String username,@RequestParam(value="password",required=false)String password){

    public String show(@Value("${username}")String username,@Value("${password}")String password){

    //@RquestParam 默认必须提供值

    return "user show:"+username+"||__---||"+password;

    }

    public static void main(String[] args) {

    SpringApplication.run(App.class, args);

    }

    }

    @RestController//无需@ResponseBody

    public class RoleController {

    @GetMapping("/hello")

    public String edit(HttpServletRequest req){

    return "server:"+req.getRemoteHost();

    }

    }

     Model.addAttribute(name, value)设置参数 UI 接口

    更换web容器 ,默认Tomcat可以更换成jetty

    1、排除Tomcat依赖

    2、加入jetty依赖

  • 相关阅读:
    Boost.Asio c++ 网络编程翻译(10)
    建站手册:网站品质
    建站手册-template
    CDN:分类
    CDN:BootCDN 项目列表-摘录-20180405
    CDN:BootCDN
    CDN:目录
    CDN-template
    JavaScript-Tool:md5.js
    Regexp-Utils:基本
  • 原文地址:https://www.cnblogs.com/qiqisx/p/9371902.html
Copyright © 2011-2022 走看看