大数据正式36 淩亂°似流年 2022-06-02 01:12 243阅读 0赞 # 大数据正式36 # ### MyBatis的接口形式 ### * 注意两点 1. 接口名---namespace值对应 2. 方法名---id一致 * 图解联系 * ![2RhSIBF.png][] * 代码示例 * UserMapper接口 # # package com.peng.mapper; import java.util.List; import com.peng.pojo.User; public interface UserMapper { // 查询全部的User public List<User> findAll(); } * UserMapper配置文件 # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.UserMapper"> <select id="findAll" resultType="User"> select * from user </select> </mapper> * User实体类 # # package com.peng.pojo; public class User { private int id; private String name; private int age; public User() { super(); } public User(int id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "编号:" + id + ",姓名:" + name + ",年龄:" + age; } } * Test测试 # # package com.peng.test; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Before; import com.peng.mapper.UserMapper; import com.peng.pojo.User; public class Test { SqlSession openSession = null; @Before public void before() throws Exception { // 加载配置文件 InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml"); // 创建会话工厂 SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in); // 创建会话对象 openSession = factory.openSession(true);// true每执行一条sql提交一次 } @org.junit.Test public void findAllTest() throws Exception { // 查询 UserMapper mapper = openSession.getMapper(UserMapper.class); List<User> selectList = mapper.findAll(); for (User user : selectList) { System.out.println(user); } } } ### Spring与Mybatis的整合 ### 1. jar包 2. bean 1. 会话工厂 1. 数据源 2. mybatis的核心配置文件 3. mapper.xml的配置文件 2. 接口扫描器 1. mapper接口所在的类 3. 项目结构,jar包,数据库表(database:mybatis\_db;table:user) * ![EwzQlms.png][] * ![5uwDfJA.png][] * ![AVW2n4L.png][] * ![Rp3k3fW.png][] 4. 代码 * com.peng.mapper * UserMapper # # package com.peng.mapper; import java.util.List; import org.springframework.stereotype.Repository; import com.peng.pojo.User; @Repository(value = "userMapper") public interface UserMapper { // 查询全部的User public List<User> findAll(); } * com.peng.pojo * User # # package com.peng.pojo; public class User { private int id; private String name; private int age; public User() { super(); } public User(int id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "编号:" + id + ",姓名:" + name + ",年龄:" + age; } } * UserMapper # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.UserMapper"> <select id="findAll" resultType="com.peng.pojo.User"> select * from user </select> </mapper> * com.peng.service * UserService # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.UserMapper"> <select id="findAll" resultType="com.peng.pojo.User"> select * from user </select> </mapper> * UserServiceImpl # # package com.peng.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import com.peng.mapper.UserMapper; import com.peng.pojo.User; @Service(value = "userService") public class UserServiceImpl implements UserService { @Autowired @Qualifier(value = "userMapper") private UserMapper userMapper; @Override public List<User> findAll() { return userMapper.findAll(); } } * com.peng.test * Test # # package com.peng.test; import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.peng.pojo.User; import com.peng.web.UserServlet; public class Test { @org.junit.Test public void findAllTest() { ApplicationContext ac = new ClassPathXmlApplicationContext( "applicationContext.xml"); UserServlet us = (UserServlet) ac.getBean("userServlet"); List<User> findAll = us.findAll(); for (User user : findAll) { System.out.println(user); } } } * com.peng.web * UserServlet # # package com.peng.test; import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.peng.pojo.User; import com.peng.web.UserServlet; public class Test { @org.junit.Test public void findAllTest() { ApplicationContext ac = new ClassPathXmlApplicationContext( "applicationContext.xml"); UserServlet us = (UserServlet) ac.getBean("userServlet"); List<User> findAll = us.findAll(); for (User user : findAll) { System.out.println(user); } } } * 配置文件 * applicationContext.xml # # <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd "> <!-- 扫描包 --> <context:component-scan base-package="com.peng"></context:component-scan> <!-- 扫描注解 --> <context:annotation-config></context:annotation-config> <!-- sql的会话工厂 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 引入数据源 --> <property name="dataSource" ref="c3p0dataSource"></property> <!-- 引入核心配置文件 --> <property name="configLocation" value="classpath:/sqlMapConfig.xml"></property> <!-- 引入映射文件 --> <property name="mapperLocations" value="classpath:/com/peng/pojo/*.xml"></property> </bean> <!-- Mapper接口的扫描器 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.peng.mapper"></property> </bean> <!-- 配置文件 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:/jdbc_config.properties"></property> </bean> <!--c3p0 --> <bean id="c3p0dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}"></property> <property name="jdbcUrl" value="${jdbc.url}"></property> <property name="user" value="${jdbc.user}"></property> <property name="password" value="${jdbc.password}"></property> <property name="minPoolSize" value="3"></property> <!--最小连接数 --> <property name="initialPoolSize" value="5"></property> <!-- 初始化连接数 --> <property name="acquireIncrement" value="3"></property> <!-- 每次增长的个数 --> </bean> </beans> * jdbc\_config.properties # # jdbc.user=root jdbc.password=root jdbc.url=jdbc\:mysql\://localhost\:3306/mybatis_db jdbc.driver=com.mysql.jdbc.Driver * log4j.properties # # log4j.rootLogger=DEBUG, Console #Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO log4j.logger.org.apache=INFO log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG * sqlMapConfig.xml # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> </configuration> * 测试结果 # # 编号:8,姓名:a,年龄:11 编号:9,姓名:a,年龄:11 编号:10,姓名:a,年龄:11 编号:11,姓名:a,年龄:11 编号:12,姓名:a,年龄:11 编号:13,姓名:a,年龄:11 编号:14,姓名:a,年龄:11 编号:15,姓名:a,年龄:11 ### MyBatis缓存 ### * 一级缓存 * 默认开启,第二次查询用第一次留下的缓存 * 二级缓存【只有session关闭的时候才会缓存;修改数据库后缓存会被清除】 * 默认关闭 * 打开 1. 核心配置文件当中开启缓存(二级缓存的总开关) # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!--缓存 --> <settings> <setting name="cacheEnabled" value="true"></setting> </settings> <!-- 别名 --> <typeAliases> <typeAlias type="com.peng.pojo.User" alias="User" /> </typeAliases> <!-- 配置数据源 --> <environments default="mysql"> <environment id="mysql"> <transactionManager type="JDBC" /> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/mybatis_db?characterEncoding=utf-8" /> <property name="username" value="root" /> <property name="password" value="root" /> </dataSource> </environment> <environment id="oracle"> <transactionManager type="JDBC" /> <dataSource type="POOLED"> <property name="driver" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:XE" /> <property name="username" value="ht1602" /> <property name="password" value="htdb" /> </dataSource> </environment> </environments> <!-- 映射文件 --> <mappers> <mapper resource="com/peng/pojo/UserMapper.xml" /> </mappers> </configuration> 2. 映射文件中的开关(当前表) # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.UserMapper"> <cache></cache> <select id="findAll" resultType="User"> select * from user </select> </mapper> 3. 必须让缓存的对象实现Serializable接口 # # package com.peng.pojo; import java.io.Serializable; @SuppressWarnings("serial") public class User implements Serializable { private int id; private String name; private int age; public User() { super(); } public User(int id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "编号:" + id + ",姓名:" + name + ",年龄:" + age; } } * 测试类中session必须关闭 # # package com.peng.test; import java.io.InputStream; import java.util.List; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Before; import com.peng.mapper.UserMapper; import com.peng.pojo.User; public class Test { SqlSession openSession = null; SqlSessionFactory factory = null; @Before public void before() throws Exception { // 加载配置文件 InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml"); // 创建会话工厂 factory = new SqlSessionFactoryBuilder().build(in); // 创建会话对象 openSession = factory.openSession(true);// true每执行一条sql提交一次 } @org.junit.Test public void findAllTest() throws Exception { // 查询 UserMapper mapper = openSession.getMapper(UserMapper.class); List<User> selectList = mapper.findAll(); for (User user : selectList) { System.out.println(user); } openSession.close(); // 查询 SqlSession openSession2 = factory.openSession(true); UserMapper mapper1 = openSession2.getMapper(UserMapper.class); List<User> selectList1 = mapper1.findAll(); for (User user : selectList1) { System.out.println(user); } } } ### 手动封装结果集【细节:和setter方法名有关,不管属性名到底是什么;主键必须【写】 ### * 属性名和字段名不一致 * sql别名 # # select id uid,name uname from user; * 配置文件中的别名 # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.UserMapper"> <resultMap type="com.peng.pojoUser" id="userMap"> <id column="id" property="u_id" /><!--必须有id--> <result column="name" property="u_name" /> </resultMap> <select id="oneByone" resultMap="userMap"> select * from user </select> </mapper> * 一对一【association】 * 多表查询,必须手动封装数据集 * 例 # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.UserMapper"> <!-- 多表查询 --> <resultMap type="User" id="userMap"> <id column="id" property="id" /> <result column="name" property="name" /> <result column="age" property="age" /> <!-- 内置对象 --> <association property="userinfo" javaType="com.peng.pojo.UserInfo"> <result column="uid" property="uid" /> <result column="nick" property="nick" /> <result column="uage" property="uage" /> <result column="phone" property="phone" /> <!-- 内置对象 --> <association property="parentUserInfo" javaType="com.peng.pojo.UserInfo"> <result column="p_uid" property="uid" /> <result column="p_nick" property="nick" /> <result column="p_uage" property="uage" /> <result column="p_phone" property="phone" /> </association> </association> </resultMap> <select id="oneByone" resultMap="userMap"> SELECT * FROM USER u LEFT JOIN (SELECT * FROM user_info ui LEFT JOIN (SELECT uid p_uid,nick p_nick,uage p_uage,phone p_phone FROM user_info) pui ON ui.parent_id=pui.p_uid) yt ON u.id=yt.p_uid; </select> </mapper> * 一对多【collection】 * 多表查询,必须手动封装数据集 * 例 # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.DeptMapper"> <!-- 一对多表查询 --> <resultMap type="com.peng.pojo.Dept" id="deptMap"> <id column="did" property="did" /> <result column="dname" property="dname" /> <collection property="userinfolist" ofType="com.peng.pojo.UserInfo"> <result column="uid" property="uid" /> <result column="nick" property="nick" /> <result column="uage" property="uage" /> <result column="phone" property="phone" /> </collection> </resultMap> <select id="oneBymore" resultMap="deptMap"> SELECT * FROM dept INNER JOIN user_info ON user_info.dedp_id=dept.did AND user_info.dedp_id IN(SELECT did FROM dept WHERE dname='法师部') </select> </mapper> * 多对多 * 多表查询,必须手动封装数据集 * 写两个一对多 ### spring+spring+mybatis整合 ### * 概览 * ![qpQmqJK.png][] * jar * ![4lPyxVQ.png][] * 数据库 * 数据库名称 * mybatis\_db * 表名称 * user * 表结构 * ![AVW2n4L.png][] * 实现 * com.peng.controller * UserServlet # # package com.peng.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.peng.pojo.User; import com.peng.service.UserService; @Controller(value = "userServlet") public class UserServlet { @Autowired @Qualifier(value = "userService") private UserService userService; @RequestMapping("/findAll.action") public String findAllAction() { List<User> users = userService.findAll(); System.out.println(users); return "message"; } } * com.peng.mapper * UserMapper # # package com.peng.mapper; import java.util.List; import org.springframework.stereotype.Repository; import com.peng.pojo.User; @Repository(value = "userMapper") public interface UserMapper { public List<User> findAll(); } * com.peng.pojo * User # # package com.peng.pojo; public class User { private int id; private String name; private int age; public User() { super(); } public User(int id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "【编号:" + id + "名称:" + name + "年龄:" + age+"】"; } } * UserMapper # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.peng.mapper.UserMapper"> <select id="findAll" resultType="com.peng.pojo.User"> select * from user </select> </mapper> * com.peng.service * UserService # # package com.peng.service; import java.util.List; import com.peng.pojo.User; public interface UserService { public List<User> findAll(); } * UserServiceImpl # # package com.peng.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import com.peng.mapper.UserMapper; import com.peng.pojo.User; @Service(value = "userService") public class UserServiceImpl implements UserService { @Autowired @Qualifier(value = "userMapper") private UserMapper userMapper; public List<User> findAll() { return userMapper.findAll(); } } * 配置文件 * applicationContext-mvc.xml # # <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd "> <!-- 扫描包 --> <context:component-scan base-package="com.peng"></context:component-scan> <!-- 扫描注解 --> <context:annotation-config></context:annotation-config> <!-- 资源解析器:前后缀 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"> </property> <property name="suffix" value=".jsp"></property> </bean> <!-- 文件上传资源解析器 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8"></property> <property name="maxUploadSize" value="10485760000"></property> <property name="maxInMemorySize" value="40960"></property> </bean> </beans> * applicationContext.xml # # <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd "> <!-- 扫描包 --> <context:component-scan base-package="com.peng"></context:component-scan> <!-- 扫描注解 --> <context:annotation-config></context:annotation-config> <!-- sql的会话工厂 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 引入数据源 --> <property name="dataSource" ref="c3p0dataSource"></property> <!-- 引入核心配置文件 --> <property name="configLocation" value="classpath:/sqlMapConfig.xml"></property> <!-- 引入映射文件 --> <property name="mapperLocations" value="classpath:/com/peng/pojo/*.xml"></property> </bean> <!-- Mapper接口的扫描器 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.peng.mapper"></property> </bean> <!-- 配置文件 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:/jdbc_config.properties"></property> </bean> <!--c3p0 --> <bean id="c3p0dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}"></property> <property name="jdbcUrl" value="${jdbc.url}"></property> <property name="user" value="${jdbc.user}"></property> <property name="password" value="${jdbc.password}"></property> <property name="minPoolSize" value="3"></property> <!--最小连接数 --> <property name="initialPoolSize" value="5"></property> <!-- 初始化连接数 --> <property name="acquireIncrement" value="3"></property> <!-- 每次增长的个数 --> </bean> </beans> * jdbc\_config.properties # # jdbc.user=root jdbc.password=root jdbc.url=jdbc\:mysql\://localhost\:3306/mybatis_db jdbc.driver=com.mysql.jdbc.Driver * log4j.properties # # log4j.rootLogger=DEBUG, Console #Console log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO log4j.logger.org.apache=INFO log4j.logger.java.sql.Connection=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG * sqlMapConfig.xml # # <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> </configuration> * WebRoot * WEB-INF * sessage.jsp # # <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> hello xy~~ <br> </body> </html> * web.xml # # <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 解决乱码过滤器(只能解决post的,get的需要手动解决) --> <!-- 乱码过滤器 --> <filter> <filter-name>characterFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 分发器 --> <servlet> <servlet-name>springmvc_dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/applicationContext*.xml</param-value><!-- 注:这里的* --> </init-param> </servlet> <!-- 分发器的映射 --> <servlet-mapping> <servlet-name>springmvc_dispatcher</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <!-- 欢迎界面 --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> * index.jsp # # <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> This is my JSP page. <br> </body> </html> [2RhSIBF.png]: https://i.imgur.com/2RhSIBF.png [EwzQlms.png]: https://i.imgur.com/EwzQlms.png [5uwDfJA.png]: https://i.imgur.com/5uwDfJA.png [AVW2n4L.png]: https://i.imgur.com/AVW2n4L.png [Rp3k3fW.png]: https://i.imgur.com/Rp3k3fW.png [qpQmqJK.png]: https://i.imgur.com/qpQmqJK.png [4lPyxVQ.png]: https://i.imgur.com/4lPyxVQ.png
相关 大数据正式5 大数据正式5 常见的shell命令 管道命令 管道符| 将两个命令隔开,左边命令的输出就会作为管道右边命令的输入 连续使 旧城等待,/ 2022年06月06日 10:29/ 0 赞/ 215 阅读
相关 大数据正式2 大数据正式2 用户身份与用户组记录的文件 在Linux系统当中,默认情况下所有的系统上的账号信息都记录在/etc/passwd这个文件内(包括root用户), 快来打我*/ 2022年06月06日 08:38/ 0 赞/ 140 阅读
相关 大数据正式10 大数据正式10 jQuery 定义:jQuery是一个“写的更少”,但“做的更多”的轻量级JavaScript函数库 优势 1. 可 ゞ 浴缸里的玫瑰/ 2022年06月05日 06:24/ 0 赞/ 222 阅读
相关 大数据正式32 大数据正式32 Spring中的JDBC jar包准备 ![zW1gEQQ.png][] bean+properties普通配置 悠悠/ 2022年06月03日 08:44/ 0 赞/ 146 阅读
相关 大数据正式27 大数据正式27 Spring 先来张图简单看一下 ![oQySJMC.png][] spring框架的特点 1 悠悠/ 2022年06月03日 04:38/ 0 赞/ 127 阅读
相关 大数据正式37 大数据正式37 Maven 传统项目存在的弊端 1. 导入jar包得经验丰富 2. 传统项目打包方式不通用,不能很好的支持聚合项 左手的ㄟ右手/ 2022年06月02日 01:46/ 0 赞/ 138 阅读
相关 大数据正式36 大数据正式36 MyBatis的接口形式 注意两点 1. 接口名---namespace值对应 2. 方法名---id一致 淩亂°似流年/ 2022年06月02日 01:12/ 0 赞/ 244 阅读
相关 大数据正式34 大数据正式34 Spring+SpringMVC 小例子 效果图 ![hsIEQmd.png][] 功能说明 川长思鸟来/ 2022年06月02日 00:16/ 0 赞/ 256 阅读
还没有评论,来说两句吧...