Getting project web framework based SSM (vii) learning record

Beep beep Mile Mile with video learning [SSM] framework SpringMVC + Spring + Mybatis SSM real integration + + source code 17-18 set

7.SSM integration - add customers

7.1. Adding method in which CustomerController

package com.ssmlcx.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ssmlcx.domain.Customer;
import com.ssmlcx.service.CustomerService;

@Controller
@RequestMapping("/customer")
public class CustomerController {
	
	//注入业务对象
	@Resource
	private CustomerService customerService;
	
/*	@RequestMapping("/test")
	public String test()
	{
		return "test";
	}*/
	/**
	 * 跳转到input.jsp
	 */
	@RequestMapping("/input")
	public String input()
	{
		return "input";
	}
	
	/**
	 * 保存客户
	 */
	@RequestMapping("/svae")
	public String save(Customer customer)
	{
		customerService.saveCustomer(customer);
		return "succ";
	}
}

7.2. Writing customers input.jsp entry page

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>客户录入页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <form action="${pageContext.request.contextPath}/customer/save.action" method="post">
    	客户姓名:<input type="text" name="name"/><br/>
    	客户性别:
    	<input type="radio" name="gender" value="男"/>男
    	<input type="radio" name="gender" value="女"/>女<br/>
    	客户:<input type="text" name="name"/><br/>
    	客户手机:<input type="text" name="telephone"/><br/>
    	客户姓名:<input type="text" name="name"/><br/>
    	客户住址:<input type="text" name="address"/><br/>
    	<input type="submit" value="保存">
    </form>
  </body>
</html>

Then found page spread Controller, Chinese data is garbled, then the filter may be encoded in web.xml Cadogan

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>01.mybatis</display-name>
  
  <!-- 配置springMVC编码过滤器 -->
  <filter>
  	<filter-name>CharacterEncodingFilter</filter-name>
  	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  	<init-param>
  		<param-name>encoding</param-name>
  		<param-value>utf-8</param-value>
  	</init-param>
  </filter>
  <filter-mapping>
  	<filter-name>CharacterEncodingFilter</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
  
  
  
  <!-- 启动springMVC -->
  <servlet>
  	<servlet-name>DispatcherServlet</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<!-- 参数:读取 spring-mvc.xml-->
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>classpath:spring-mvc.xml</param-value>
  	</init-param>
  </servlet>
  <servlet-mapping>
  	<servlet-name>DispatcherServlet</servlet-name>
  	<url-pattern>*.action</url-pattern>
  </servlet-mapping>
  
  
  <!-- 启动spring -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 修改路径 -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Here Insert Picture Description
Here Insert Picture Description

Published 56 original articles · won praise 70 · views 8909

Guess you like

Origin blog.csdn.net/weixin_44835732/article/details/103832295