SpringMVC的表单组件、国际化
spring mvc 的表单标签库
1.Student实体类
package com.southwind.POJO;
import lombok.Data;
@Data
public class Student {
private Integer id;
private String name;
private Integer age;
private String gender;
}
2.Handler
package com.southwind.controller;
import com.southwind.POJO.Student;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/student")
public class StudenController {
@GetMapping("/get")
public String get(Model model){
Student student =new Student();
student.setId(1);
student.setAge(18);
student.setName("张三");
student.setGender("男");
model.addAttribute("student",student);
return "student";
}
}
3.JSP
<%--
Created by IntelliJ IDEA.
User: 郝泾钊
Date: 2022-04-07
Time: 20:53
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false"%>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>学生编号</h1>
<form action="" method="post">
学生编号:<input type="text" value="${student.id}" readonly><br>
学生姓名:<input type="text" value="${student.name}"><br>
学生年龄;<input type="text" value="${student.age}"><br>
学生性别:<input type="text" value="${student.gender}"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
表单标签库的使用
1.JSP页面表单标签库的导入
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
2.将form表单的业务数据进行绑定,通过modelAttribute属性完成绑定,将modelAttribute的值设置位控制器象model对象存值是的name即可。
<%--@elvariable id="student" type="com.southwind.POJO.Student"--%>
<form:form modelAttribute="student" action="/student/update" method="post">
学生编号:<form:input path="id"></form:input><br>
学生姓名:<form:input path="name"></form:input><br>
学生年龄;<form:input path="age"></form:input><br>
学生性别:<form:input path="gender"></form:input><br>
<input type="submit" value="提交">
</form:form>
常用标签的使用
1.from:
<form:form modelAttribute="student" action="/student/update" method="post">
</form:form>
渲染的是HTML的from标签,通过modelAttribute属性绑定业务数据。
2.input:
<form:input path="name"></form:input><br>
渲染的是HTML的input标签,type="text" 绑定的是业务数据中的属性值,与path的业务属性值一样。支持级联
3.password:
<form:password path="age"></form:password><br>
渲染的是HTML的password标签,type="text" 绑定的是业务数据中的属性值,与path的业务属性值一样。但是不会在页面现实
4.checkbox:
<form:checkbox path="hobby" value="读书">
</form:checkbox>
渲染的是HTML的checkbox标签,type="text" 绑定的是业务数据中的属性值,与path的业务属性值一样。
有Boolean,数组,集合
boolean 为true选中 false为不选中。
student.setFlag(true) check:<form:checkbox path="flag" value="读书"> </form:checkbox>
数组,集合如果和集合中的元素和checkbox相同就选中
5.checkboxs:
<form:checkboxes path="name" items="${student.hobby}"></form:checkboxes>
渲染的是一组checkbox标签
item绑定别遍历的数组,path表述选中的数组
student.setHobby(Array.asList("读书","鞋子"))
path可以直接写属性名,item则要通过EL表达式从作用域对象中取值,不能直接写属性名。
6.radiobuttion
<form:radiobutton path="name" value="0"></form:radiobutton>
渲染的是一个HTML中的一个单选按钮,值相同为选中状态,值不同为不状态。
7.radiobuttion
<form:radiobuttons path="name" items="${student.name}"></form:radiobuttons>
渲染的是html中的一组单选按钮标签
item绑定别遍历的数组,path表述选中的数组
8.select
<form:select path="name" items="${student.name}"></form:select>
渲染的是html中的一组选择标签
item绑定别遍历的数组,path表述选中的数组
9.from:select结合form:optations使用
from:select只定义path form:optations写 items
10.from:select结合form:optation使用
from:select只定义path form:optation写 value
path与哪个valu相等,则默认选择
Springmvc 国际化
在不同的语言设置的浏览器自动显示不同的语言。
1.spring.mvc
<!-- 国计化资源文件-->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<!-- 多语言配置文件放在根路径 以langua开头-->
<property name="basename" value="classpath:language"></property>
<property name="useCodeAsDefaultMessage" value="true"></property>
</bean>
<!-- 拦截器-->
<mvc:interceptors>
<bean id="localeChangeInterceotor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="Lang"></property>
</bean>
</mvc:interceptors>
<!-- 配置SessionResolver,动态获取local对象存入Session-->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"></bean>
2.创建国际化资源文件:
language_en_US.properties
language.cn=\u4E2D\u6587
language.en=English
info=login
userbane=username
password=password
repassword=repassword
tel=tel
email=email
submit=submit
reset=reset
language_en_US.properties
language.cn=\u4E2D\u6587
language.en=English
info=\u767B\u5F55
userbane=\u7528\u6237\u540D
password=\u5BC6\u7801
repassword=\u786E\u8BA4\u5BC6\u7801
tel=\u7535\u8BDD
email=\u7535\u5B50\u90AE\u7BB1
submit=\u63D0\u4EA4
reset=\u91CD\u7F6E
业务页面:
package com.southwind.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/inter")
public class InterHandler {
@GetMapping("/index")
public String index(){
return "inter";
}
}
SpringMVC的表单组件、国际化的更多相关文章
- 微信小程序-表单组件
button 按钮 注:button-hover 默认为{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;} 示例代码: /** wxss **/ ...
- Vue组件之自定义表单组件
今天又看了一遍vue的文档,记得之前学习的时候,官方文档中有提过,v-model指令是一个语法糖,做两件事,一个是给表单控件元素绑定value,第二个是当输入时更新绑定的值,不过后来在"表单 ...
- Form( 表单) 组件
本节课重点了解 EasyUI 中 Form(表单)组件的使用方法, 这个组件不依赖于任何组件.一. 加载方式表单组件只能在 JS 区域设置,首先定义一张表单.<form id="box ...
- 实现Ant Design 自定义表单组件
Ant Design 组件提供了Input,InputNumber,Radio,Select,uplod等表单组件,但实际开发中这是不能满足需求,同时我们希望可以继续使用Form提供的验证和提示等方法 ...
- springMVC(7)---表单标签
springMVC(7)---表单标签 form标签作用 简单来讲form表单有两大作用 1:第一就是往后端提交数据或者前端回显 ...
- 「小程序JAVA实战」小程序的表单组件(25)
转自:https://idig8.com/2018/08/18/xiaochengxujavashizhanxiaochengxudebiaodanzujian25/ 来说下 ,小程序的基础组件.源码 ...
- 第二百二十一节,jQuery EasyUI,Form(表单)组件
jQuery EasyUI,Form(表单)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Form(表单)组件的使用方法,这个组件不依赖于 ...
- SpringMVC from 表单标签和 input 表单标签
刚学习很懵 不知道还有springmvc 自己的表单 于是乎就上网查了一下 这个真的好用多啦 刚学习很懵 不知道还有springmvc 自己的表单 于是乎就上网查了一下 这个真的好用多啦 ...
- 【09】react 之 表单组件
不太清楚有多少初学React的同学和博主当时一样,在看完React的生命周期.数据流之后觉得已经上手了,甩开文档啪啪啪的开始敲了起来.结果...居然被一个input标签给教做人了. 故事是这样的:首先 ...
- SpringMVC(十四):SpringMVC 与表单提交(post/put/delete的用法);form属性设置encrypt='mutilpart/form-data'时,如何正确配置web.xml才能以put方式提交表单
SpringMVC 与表单提交(post/put/delete的用法) 为了迎合Restful风格,提供的接口可能会包含:put.delete提交方式.在springmvc中实现表单以put.dele ...
随机推荐
- Selenium4+Python3系列(九) - 上传文件及滚动条操作
一.上传文件操作 上传文件是每个做自动化测试同学都会遇到,而且可以说是面试必考的问题,标准控件我们一般用send_keys()就能完成上传, 但是我们的测试网站的上传控件一般为自己封装的,用传统的上传 ...
- Kubernetes(K8S) 配置管理-ConfigMap 介绍
作用:存储不加密数据到 etcd,让 Pod 以变量或者 Volume 挂载到容器中 场景:配置文件 创建配置文件 redis.properties redis.host=127.0.0.1 redi ...
- 【Scala】常见题目中Scala的使用
一.简单输出 BC2:打印一辆小飞机 object Main{ def main(args: Array[String]) { println(" ** ") println(&q ...
- 为什么推荐Kestrel作为网络开发框架
为什么推荐Kestrel 网络框架千千万万,在dotnet平台,我们可以直接手撸Socket,也可以基于dotnetty来开发,或者选择某些第三方类似于dotnetty的网络库,为何我要推荐Kestr ...
- view-design tabpane禁用后renderHeader失效问题
需求是这样的 在tabPane的renderHeader里面添加hover事件(使用组件自带的Poptip)能显示提示 其实这个不算是问题,设置disabled属性后,原本的元素上面添加了 ivu-t ...
- ATM购物车项目总结
目录 项目实现思路 ATM项目 优先实现功能 拆分函数 项目路径展示 项目启动文件 start.py 配置文件 setting.py 日志配置字典 日志函数 展示层 src.py 用户注册 获取用户输 ...
- 如何用 30s 给面试官讲清楚跳表
查找 假设有如下这样一个有序链表: 想要查找 24.43.59,按照顺序遍历,分别需要比较的次数为 2.4.6 目前查找的时间复杂度是 O(N),如何提高查找效率? 很容易想到二分查找,将查找的时间复 ...
- MyBatis是如何初始化的?
摘要:我们知道MyBatis和数据库的交互有两种方式有Java API和Mapper接口两种,所以MyBatis的初始化必然也有两种:那么MyBatis是如何初始化的呢? 本文分享自华为云社区< ...
- Linux基础:ssh与scp
登陆 登陆服务器 ssh user@hostname user: 用户名 hostname :IP地址或域名 第一次登陆会提示 The authenticity of host '123.57.47. ...
- [机器学习] PCA主成分分析原理分析和Matlab实现方法
转载于http://blog.csdn.net/guyuealian/article/details/68487833 网上关于PCA(主成分分析)原理和分析的博客很多,本博客并不打算长篇大论推论PC ...