srping mvc学习_html/css_WEB-ITnose
程序员文章站
2022-04-15 08:35:00
...
- HOME 控制器
package ghy.webapp.myapp;import java.text.DateFormat;import java.util.Date;import java.util.Locale;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;/** * Handles requests for the application home page. */@Controllerpublic class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); /** * Simply selects the home view to render by returning its name. */ @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! The client locale is {}.", locale); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate ); return "home"; } @RequestMapping(value = "/Two", method = RequestMethod.GET) public String Two( int id,Model model ) { logger.info("two"); System.out.println("hello2 action:"+id); model.addAttribute("name", "huangjie"); //这个只有值没有键的情况下,使用Object的类型作为key,String-->string model.addAttribute("ok"); return "Two"; } }
- Two.jsp 视图
欢迎 Hello World!
- Two控制器
package ghy.webapp.myapp;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;@Controller public class TwoController { @RequestMapping("login") //用来处理前台的login请求 private @ResponseBody String hello( @RequestParam(value = "username", required = false)String username, @RequestParam(value = "password", required = false)String password ){ return "Hello "+username+",Your password is: "+password; } }
环境:sts +tomcat - 运行 http://localhost:8080/myapp 执行home控制器 ,http://localhost:8080/myapp/Two?id=3525是调用 Two控制器传参id
5.下载地址:。 下载
上一篇: 如何使用float实现文字环绕图片
下一篇: 怎么用css设置图片大小
推荐阅读
-
ASP.NET MVC3学习心得-----表单和HTML辅助方法
-
CSS Position学习_html/css_WEB-ITnose
-
CSS学习笔记二_html/css_WEB-ITnose
-
服务器重定向与客户端重定向学习,辨析与实现_html/css_WEB-ITnose
-
9大理由告诉你为什么应该学习HTML跟CSS_html/css_WEB-ITnose
-
Bootstrap3.0学习(一)_html/css_WEB-ITnose
-
css3 animation 学习_html/css_WEB-ITnose
-
css学习笔记二之inline-block_html/css_WEB-ITnose
-
学习使用 CSS3 制作网站面包屑导航效果_html/css_WEB-ITnose
-
avalon2学习教程13组件使用_html/css_WEB-ITnose