标签:adc intern support ber path 注册 ons over 数据格式
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <a href="${pageContext.request.contextPath}/test?user=adc,123456,1">增加数据</a> </body> </html>
package com.sunxiaping.springmvc.domain; import java.io.Serializable; public class User implements Serializable { private String username; private String password; private Integer age; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } }
package com.sunxiaping.springmvc.converters; import com.sunxiaping.springmvc.domain.User; import org.springframework.core.convert.converter.Converter; public class UserConverter implements Converter<String, User> { @Override public User convert(String s) { if (null == s || s.length() == 0) { return null; } String[] split = s.split(","); User user = new User(); user.setUsername(split[0]); user.setPassword(split[1]); user.setAge(Integer.parseInt(split[2])); return user; } }
package com.sunxiaping.springmvc.controller; import com.sunxiaping.springmvc.domain.User; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class UserController { @RequestMapping(value = "/test") public String test(User user){ System.out.println(user); return "success"; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd "> <!-- 配置自动扫描的包 --> <context:component-scan base-package="com.sunxiaping.springmvc"></context:component-scan> <!-- 配置视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"></property> <property name="suffix" value=".jsp"></property> </bean> <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters"> <set> <bean class="com.sunxiaping.springmvc.converters.UserConverter"></bean> </set> </property> </bean> <mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven> </beans>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> 成功啦 <br/> </body> </html>
@InitBinder public void initBinder(WebDataBinder webDataBinder){ webDataBinder.setDisallowedFields("roleIds"); }
标签:adc intern support ber path 注册 ons over 数据格式
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/11854569.html