当前位置: 首页 > news >正文

wordpress投稿管理苏州seo报价

wordpress投稿管理,苏州seo报价,河北做wap网站,asp网站加速------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 在处理方法中,参数写上之后,只要符合特定规则,就可以自动装配 首先 其次是:自定义的参数的自动装配: 案例如下:我的…

 

 

  ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

 

 

在处理方法中,参数写上之后,只要符合特定规则,就可以自动装配

首先

 

 

其次是:自定义的参数的自动装配:

案例如下:我的相同的配置文件就在下面不重复展示,不同的就展示一下:

 

 

第一种,零散参数自动装配:

  在处理器中定义方法:

 

package cn.dawn.day11autowire;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;/*** Created by Dawn on 2018/3/24.*/
/*注解定义处理器*/
@Controller
/*定义处理器访问路径*/
@RequestMapping("/user")
public class MyAController {/*第一种零散根据name*/@RequestMapping("/doLogin")public String doLogin(String username,String password, Model model) throws Exception {model.addAttribute("username",username);System.out.println(username);System.out.println(password);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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!--包扫描器--><context:component-scan base-package="cn.dawn.day11autowire"></context:component-scan><!--视图解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"></property><property name="suffix" value=".jsp"></property></bean></beans>

 

  xml配置文件中只需要包扫描器和视图解析器

  jsp页面:

 

<%@ page  pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"  %>
<html>
<head><title>Title</title>
</head>
<body>
<h2>登录</h2>
<form action="${pageContext.request.contextPath}/user/doLogin" method="post"><%--第一种自动装配零散参数--%>用户名:<input name="username"><input type="submit" value="登录"/>
</form>
</body>
</html>

  第二个jsp页面:success.jsp

 

<%@ page language="java" pageEncoding="utf-8" isELIgnored="false" %>
<html>
<body>
<%--<img src="image/1.jpg">--%>
<h2>Success!</h2>
<p>${username}</p>
</body>
</html>

 

  在web.xml中需要将指定的xml文件改成现在的即可

 

第二种:当写前台提交的name的属性名和实体类字段名或者参数名的不是一个人,有可能出现不一致,怎么解决

  处理方法:

 

    /*第二种零散参数name不一致*/@RequestMapping("/doLoginBie")public String doLoginBie(@RequestParam("uname") String username, String password, Model model) throws Exception {model.addAttribute("username",username);System.out.println(username);System.out.println(password);return "success";}

 

  form表单中的值,记得改action指向的地址,改为新的处理方法

 

    <%--第二种自动装配零散参数  别名--%>用户名:<input name="uname">

 

  第二种用到了@RequestParam("xxx")的这个注解

 

第三种:对象参数自动装配:只要表单里的name属性与对象的字段对应,就可以自动装配

  此处我将最终版实体类对象发上来(因为案例全做完才写的博客,不好删减):UserInfo实体类:

 

package cn.dawn.day11autowire;import java.util.List;/*** Created by Dawn on 2018/3/26.*/
public class UserInfo {private String username;private String password;private Car car;private List<Girls> girlsList;@Overridepublic String toString() {return "UserInfo{" +"username='" + username + '\'' +", password='" + password + '\'' +", car=" + car +", girlsList=" + girlsList +'}';}public List<Girls> getGirlsList() {return girlsList;}public void setGirlsList(List<Girls> girlsList) {this.girlsList = girlsList;}public Car getCar() {return car;}public void setCar(Car car) {this.car = car;}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;}
}

  第三个案例只用到了前俩个字段,我们看一下jsp中的form中的内容:记得改action指向的地址,改为新的处理方法

 

    用户名:<input name="username">密码:<input name="password">

 

 

 

第四种:当有域属性的时候怎么办?

  用到了UserInfo的car这个字段,所以,建一个Car的实体类:

 

package cn.dawn.day11autowire;/*** Created by Dawn on 2018/3/26.*/
public class Car {private String type;@Overridepublic String toString() {return "Car{" +"type='" + type + '\'' +'}';}public String getType() {return type;}public void setType(String type) {this.type = type;}
}

 

  处理方法如下:

 

    /*第三种对象参数传*/@RequestMapping("/doLoginObject")public String doLoginObject(UserInfo info, Model model) throws Exception {model.addAttribute("username",info.getUsername());System.out.println(info);return "success";}

  jsp页面from表单中的如下:action指向新的处理方法地址:

 

    用户名:<input name="username">密码:<input name="password"><%--第四种带域属性--%>车:<input name="car.type">

  这儿需注意的是car.type这个写法

 

第五种:集合自动装配

  在实体类中用到了girlsList这个对象List集合字段:所以我们建一个Girls表:

 

package cn.dawn.day11autowire;/*** Created by Dawn on 2018/3/26.*/
public class Girls {private String cool;@Overridepublic String toString() {return "Girls{" +"cool='" + cool + '\'' +'}';}public String getCool() {return cool;}public void setCool(String cool) {this.cool = cool;}
}

 

  处理方法如下:

 

    /*第五种对象携带集合对象参数传*/@RequestMapping("/doLoginObjectList")public String doLoginObjectList(UserInfo info, Model model) throws Exception {model.addAttribute("username",info.getUsername());System.out.println(info);return "success";}

 

  form表单内容如下:action指向新地址:

 

    用户名:<input name="username">密码:<input name="password">车:<input name="car.type"><%--第五种带List集合--%>女1:<input name="girlsList[0].cool">女2:<input name="girlsList[1].cool"><input type="submit" value="登录"/>

 

 

第六种:路径参数自动装配:是可以通过占位的方式来写的:

  处理方法如下:

 

    /*第六种路径参数传法1*/@RequestMapping("/doPathVariable01/{uname}")public String doPathVariable01(@PathVariable("uname") String username, Model model) throws Exception {model.addAttribute("username",username);System.out.println(username);return "success";}

 

  URL访问只需要在处理器方法之后加           /值      就可以自动装配

  用到了注解@PathVariable()和@RequestMapping中的{占位符}

 

延伸出来一个问题:如果form传过来的name值和action访问的Url地址中占位的那个参数一样,会出现什么

第七种:

  处理器方法:

 

    /*第七种路径参数传法2*/@RequestMapping("/doPathVariable02/{username}")public String doPathVariable02(@PathVariable String username, Model model) throws Exception {model.addAttribute("username",username);System.out.println(username);return "success";}

 

  jsp页面:

 

<%@ page  pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"  %>
<html>
<head><title>Title</title>
</head>
<body>
<h2>登录</h2>
<form action="${pageContext.request.contextPath}/user/doPathVariable02/happy" method="post">用户名:<input name="username"><input type="submit" value="登录"/>
</form>
</body>
</html>

 

  结果肯定是拿到URL里面的那个值

 

延伸出来一个问题:传中文会乱码,怎么办?看下篇博客

 

转载于:https://www.cnblogs.com/DawnCHENXI/p/8659913.html

http://www.lbrq.cn/news/2368243.html

相关文章:

  • 网站优化怎么做分录咖啡的营销推广软文
  • 北辰做网站公司网站互联网推广
  • 网站如何在360上做推广怎样制作一个网页
  • wordpress 适合外贸站软件开发公司有哪些
  • 中国商标查询网官网站长网站优化公司
  • 网站和做游戏网络推广费用高吗
  • 网页制作与网站建设文档2023年3月份疫情严重
  • 兰州建网站广州seo推广优化
  • 招聘类网站如何做百度网站的网址是什么
  • 橙子建站短信验证码安全吗免费推广网站大全下载安装
  • 网站外包建设 请示搜索引擎优化方法有哪几种
  • 网站备案有什么风险百度网站怎么优化排名
  • 企业高端网站建设seo的工作内容主要包括
  • wordpress商品列表抖音关键词优化排名靠前
  • 台湾做网站怎样制作网站教程
  • 泰州企业网站建站模板全网推广代理
  • 怎样用b2b网站开发客户网推项目
  • 网站建设费用会计科目搜索引擎优化教程
  • 如何做120急救网站湖南网络营销外包
  • 有道翻译网站 做翻译如何免费创建自己的平台
  • 柳州市城乡建设委员会网站360手机优化大师下载
  • wp做网站需要多久最新全国疫情消息
  • 什么是网站空间国外外链平台
  • 绍兴做网站公司百度网页版浏览器入口
  • 手机版网站如何做图片滚动条上海seo服务外包公司
  • 网站做app的软件叫什么中国免费网站服务器2020
  • 怎么做网页代码宁波seo整站优化软件
  • 买域名送网站百度关键词排名推广
  • 深圳网站建设信科网络优化推广网站排名
  • 网站建设进度表推广产品的软文怎么写
  • Python第八章作业(初级)
  • kimi-k2-api使用示例
  • PDF 转 Word 支持加密的PDF文件转换 批量转换 编辑排版自由
  • 【LLM】OpenRouter调用Anthropic Claude上下文缓存处理
  • JavaScript认识+JQuery的依赖引用
  • 【第二章自定义功能菜单_MenuItemAttribute_顶部菜单栏(本章进度1/7)】