创建user类,并使其前台信息传至后台

优化部分代码
main
15844055585 5 months ago
parent 4a118aefd4
commit a9f3a87f9b

@ -0,0 +1,18 @@
package com.ssm.controller;
import com.ssm.entity.UserModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("user")
public class UserController {
@RequestMapping("add")
public String useradd(UserModel user) {
System.out.println("车主id" + user.getUserid());
System.out.println("车主名字:" + user.getUsername());
System.out.println("密码:" + user.getUserpw());
System.out.println("车主电话:" + user.getUserphone());
return "showUser";
}
}

@ -0,0 +1,41 @@
package com.ssm.entity;
public class UserModel {
private int userid;//用户id
private String username;//用户名
private int userpw;//用户密码
private int userphone;//用户电话
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getUserpw() {
return userpw;
}
public void setUserpw(int userpw) {
this.userpw = userpw;
}
public int getUserphone() {
return userphone;
}
public void setUserphone(int userphone) {
this.userphone = userphone;
}
}

@ -3,11 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 配置注解扫描器配置spring容器初始化对象时需要扫描的包 -->
<context:component-scan base-package="com.ssm.controller"></context:component-scan>
<context:component-scan base-package="com.ssm.controller"/>
<!-- 配置视图解析器,ctrl+shift+t搜索类将return的字符串逻辑视图+前缀+后缀,转换成真正的物理视图 -->
<!-- 逻辑视图success,真正的视图:/WEB-INF/view/success.jsp -->
<!-- -->
@ -15,9 +18,9 @@
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="prefix" value="/WEB-INF/view/"/>
<!-- 后缀 -->
<property name="suffix" value=".jsp"></property>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean">

@ -11,5 +11,4 @@ success
<br>
新闻类型信息已在控制台输出!
</body>
</body>
</html>

@ -0,0 +1,11 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>展示userController接收及响应数据</title>
</head>
<body>
success
<br>
车主信息已在控制台输出!
</body>
</html>

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>SpringMVCFirst</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
@ -8,7 +11,7 @@
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</welcome-file-list>
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
@ -25,7 +28,7 @@
<servlet-name>springDispatcherServlet</servlet-name>
<!-- 可以应答所有请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
</servlet-mapping>
<!--编码过滤器,解决中文乱码问题-->
<filter>
<filter-name>characterEncodingFilter</filter-name>
@ -39,5 +42,5 @@
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -1,10 +1,3 @@
<%--
Created by IntelliJ IDEA.
User: 吴彦祖
Date: 2025/3/26
Time: 16:31
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

@ -0,0 +1,36 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>添加用户类型</title>
</head>
<body>
<form action="user/add" method="post">
<table>
<tr>
<td>车主id</td>
<td width="20"></td>
<td><input type="text" name="userid" placeholder="请输入用户id" /></td>
</tr>
<tr>
<td>车主名:</td>
<td width="20"></td>
<td><input type="text" name="username" placeholder="请输入用户名" /></td>
</tr>
<tr>
<td>密码:</td>
<td width="20"></td>
<td><input type="password" name="user_password" placeholder="请输入密码" /></td>
</tr>
<tr>
<td>车主电话:</td>
<td width="20"></td>
<td><input type="text" name="user_phone" placeholder="请输入用户电话" /></td>
</tr>
<tr>
<td align="right"><input type="reset" value="重置"></td>
<td align="center"><input type="submit" value="添加"></td>
</tr>
</table>
</form>
</body>
</html>
Loading…
Cancel
Save