在建立表之前,需要考虑外键约束关系(表与表之间存在依赖关系):比如,用户表对应订单(用户指向订单)
因此,需要先建立被外键指向的表
1、ERROR [RMI TCP Connection(3)-127.0.0.1] - init datasource error, url: jdbc:m
MySQL和Druid版本问题: Druid-1.1.12,MySQL-5.1.35
2、/WEB-INF/jsp/admin/…/include/admin/adminHeader.jsp (line: [2], column: [1])
包含页面与被包含页面的@page指令里面的contentType不一致: 必须一模一样,多个空格都不行的
<!-- resultType:SQL执行结果的类型 namespace:绑定mapper接口,相当于mapper接口地址 --> <mapper namespace="com.linjie.tmall.mapper.CategoryMapper"> <select id="list" resultType="Category"> select * from category order by id desc </select> </mapper>
# Global logging configuration log4j.rootLogger=ERROR, stdout # MyBatis logging configuration... log4j.logger.com.linjie.tmall=TRACE # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3307/tmall_ssm?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8 jdbc.username=root jdbc.password=123456
1. 启动对注解的识别 2. 指定对jdbc.properties的引用 3. 配置数据源 4. 配置Mybatis的SessionFactory,其中声明了别名,并且使用前面配置的数据源,扫描CategoryMapper.xml配置文件 5. 扫描Mapper类: CategoryMapper <!-- 启动对注解的识别 --> <context:annotation-config/> <context:component-scan base-package="com.linjie.tmall.service"/> <!-- 指定对jdbc.properties的引用 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 配置数据库连接池--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <!-- 基本属性 --> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 配置mybatis的SessionFactory,申明别名,并使用前面配置的数据源,扫描CategoryMapper.xml文件 --> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="typeAliasesPackage" value="com.linjie.tmall.pojo"/> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean> <!-- Mybatis的Mapper文件识别 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.linjie.tmall.mapper"/> </bean>
1. 开启注解的识别 2.开通静态资源的访问,否则访问图片,css,js等文件可能出错 3. 视图定位:视图定位到/WEB-INF/JSP/*.jsp这里 4. 对上传文件的解析 <!--启动注解识别--> <context:annotation-config/> <context:component-scan base-package="com.linjie.tmall.controller"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <mvc:annotation-driven /> <!--开通静态资源的访问--> <mvc:default-servlet-handler /> <!-- 视图定位 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 对上传文件的解析--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
1. 指定spring的配置文件为classpath下的applicationContext.xml 2. 设置中文过滤器 3. 指定spring mvc配置文件为classpath下的springMVC.xml <!-- spring的配置文件--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--中文过滤器--> <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> <!-- spring mvc核心:分发servlet --> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- spring mvc的配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>