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"; } }<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%><html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>欢迎</title> </head> <body> <h2>hello world!</h2> <form action="login"> 用户名:<input id="username" name="username" type="text" value='${name}'></input><br> 密 码:<input id="username" name="password" type="password"></input><br> <input type="submit"> </form> <span>当前ip:<%=request.getremoteaddr() %></span> </body> </html>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; } }5.下载地址:。 下载
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号