ssm framework to build a personal blog system (in progress, error recording)

I won't talk about the construction process.
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_3_0.xsd"
         version="3.0">
  <display-name>dreamland-web</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath*:spring-batis.xml
    </param-value>
  </context-param>

  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>

  <!-- 编码过滤器 解决POST乱码问题-->
  <filter>
    <filter-name>encodingFilter</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>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- spring监听器 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 防止spring内存溢出监听器,比如quartz -->
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>

  <!-- spring mvc servlet-->
  <servlet>
    <servlet-name>SpringMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
  </servlet>
  <!-- servlet-mapping -->
  <servlet-mapping>
    <servlet-name>SpringMVC</servlet-name>
    <!-- 此处也可以配置成 *.do 形式 -->
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 指明对于如下资源文件不采用spring的过滤器 -->
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.xml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!-- session配置 -->
  <session-config>
    <session-timeout>15</session-timeout>
  </session-config>
</web-app>

springmvc.xml

<?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:p="http://www.springframework.org/schema/p"
       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-4.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <mvc:default-servlet-handler />
    <!-- 自动扫描 -->
    <context:component-scan base-package="my_first.ssm.www.controller"/>
    <!--避免IE执行AJAX时,返回JSON出现下载文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <!-- 默认的注解映射的支持,自动注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter -->
    <mvc:annotation-driven />
    <!-- 定义跳转的文件的前后缀 ,视图模式配置 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/" />
        <property name="suffix" value=".jsp"/>
    </bean>
    <!-- 文件上传配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 上传文件大小限制为31M,31*1024*1024 -->
        <property name="maxUploadSize" value="32505856"/>
        <!-- 内存中的最大值 -->
        <property name="maxInMemorySize" value="4096"/>
    </bean>

    <!-- 对静态资源文件的访问-->
    <mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/>
    <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/>
    <mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/>
</beans>

springmabatis.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>
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
    <typeAliases>
        <!--默认别名为:javabean 的首字母小写的非限定类名来作为它的别名-->
        <package name="wang.dreamland.www.entity" />
    </typeAliases>
    <plugins>
        <plugin interceptor="tk.mybatis.mapper.mapperhelper.MapperInterceptor">
            <property name="IDENTITY" value="MYSQL"/>
   <!--可选参数一共3个,对应0,1,2,分别为SequenceName,ColumnName,PropertyName-->
            <property name="seqFormat" value="{0}.nextval"/>

            <!--通用Mapper接口,多个通用接口用逗号隔开-->
            <property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
        </plugin>
        <!-- 自定义分页插件 -->
        <!--   <plugin interceptor="wang.dreamland.www.common.PageHelper"></plugin>-->
    </plugins>
</configuration>

The current project structure is as follows
The current project structure is as shown in the figure above. The work on the first day was completed, and three pits were stepped on during the period. The
first one was when powerDesigner created the sql file. After generating it, pay attention to open it. The above drop statement needs to be deleted, otherwise an error will be reported. The second is to pay attention not to use keywords when creating field names. I forgot like, and I used like as my favorite field name. As a result, the creation failed. After looking at it for a long time, I found out. Remember to remember, be sure to open it and take a look.

The second question is to use the mysql8.0 version. Remember to add &l;nullCatalogMeansCurrent = true after the url. This is a problem of the driver after 8.0. If you don’t add it, how many implementation classes will appear when you use generatorConfig.xml to create a table library? An additional class, and the field names will be different.

For this attribute in the last generatorConfig.xml file, it is recommended to use a relative path, copy a jar package from the project and put it in the root directory for use. Do not use the built-in 5.1.25, because the database version 8.0 or later, use the old driver No connection at all.

Updated on April 2nd. The
database table field data is underlined. You need to turn off the camel case matching in mybatis-config, otherwise empty fields will be queried.

The @id annotation introduces the javax.persistence.Id package
instead of org.springframework.data.annotation.id.
This wastes me a long time looking for errors.

Guess you like

Origin blog.csdn.net/qq_45789385/article/details/104953295