复习第4点-4.注入不同的对象(集合对象/)

注入集合对象
<%--
Created by IntelliJ IDEA.
User: 19413
Date: 2023/1/13
Time: 15:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="/springmvc_war_exploded/userHobby">
用户姓名:<input type="text" name="username"/><br/>
爱好:<br/>
体育<input type="checkbox" value="Sport" name="userlike"/>
音乐<input type="checkbox" value="Music" name="userlike"/>
艺术<input type="checkbox" value="Art" name="userlike"/><br/>
<input type="submit" value="OK"/>
</form>
</body>
</html>
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
public class DifferentObject {
@RequestMapping("/userHobby")
public ModelAndView addUser(String username,@RequestParam List<String> userlike) { // 集合前面必须要加 @RequestParam
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("/index.jsp");
modelAndView.addObject("name", username);
String hobby = "";
for (String h: userlike) {
hobby += h + " ";
}
modelAndView.addObject("hobby", hobby);
return modelAndView;
}
}
posted @   jsqup  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
历史上的今天:
2022-01-13 12. 寻找环形链表的头结点
点击右上角即可分享
微信分享提示