编写矿建

main
Administrator 5 days ago
parent 127be63a3d
commit 440b6c8d44

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="commons-logging-1.1.1">
<CLASSES>
<root url="jar://$PROJECT_DIR$/moonlighting-SpringProject/src/lib/commons-logging-1.1.1.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting-SpringProject/src/lib/spring-beans-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting-SpringProject/src/lib/spring-context-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting-SpringProject/src/lib/spring-core-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting-SpringProject/src/lib/spring-expression-5.1.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,26 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-beans-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/commons-dbcp2-2.5.0.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/commons-logging-1.1.1.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-tx-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-web-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/commons-pool2-2.7.0.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/mybatis-spring-2.0.3.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/commons-fileupload-1.3.1.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/jstl-1.2.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-jdbc-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-context-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-core-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/commons-io-2.5.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-aop-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-expression-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/mybatis-3.5.0.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/mysql-connector-java-8.0.11.jar!/" />
<root url="jar://$PROJECT_DIR$/moonlighting/web/WEB-INF/lib/spring-webmvc-5.1.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/CampusParttimePlatform25-12.iml" filepath="$PROJECT_DIR$/.idea/CampusParttimePlatform25-12.iml" />
<module fileurl="file://$PROJECT_DIR$/moonlighting/moonlighting.iml" filepath="$PROJECT_DIR$/moonlighting/moonlighting.iml" />
<module fileurl="file://$PROJECT_DIR$/moonlighting-MyBatisProject/moonlighting-MyBatisProject.iml" filepath="$PROJECT_DIR$/moonlighting-MyBatisProject/moonlighting-MyBatisProject.iml" />
<module fileurl="file://$PROJECT_DIR$/moonlighting-SpringMVCProject/moonlighting-SpringMVCProject.iml" filepath="$PROJECT_DIR$/moonlighting-SpringMVCProject/moonlighting-SpringMVCProject.iml" />
<module fileurl="file://$PROJECT_DIR$/moonlighting-SpringProject/moonlighting-SpringProject.iml" filepath="$PROJECT_DIR$/moonlighting-SpringProject/moonlighting-SpringProject.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="commons-logging-1.1.1" level="project" />
</component>
</module>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>

@ -0,0 +1,8 @@
<?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">
<!-- mybatis全局配置文件 -->
<configuration>
</configuration>

@ -0,0 +1,9 @@
<?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: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">
</beans>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
</beans>

@ -0,0 +1,85 @@
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
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-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!-- 1.自动扫描包希望Spring管理所有业务逻辑组件、Bean等,SpringMVC负责网站跳转逻辑的控制Controller
注意①当springmvc.xml配置了只扫描@Controller此处就要配
除了标了@Controller注解的控制器以外都扫描即配置子标签
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> -->
<context:component-scan base-package="com.ssm">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 2.引入db.properties
注意:①方式二:<bean id="" class="PropertyPlaceholderConfigurer"> -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 3.引入数据库的数据源配置:
注意①还可以配置事务控制、AOP等
②当使用c3p0连接池时配置如下
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean> -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<!-- 这里报错说明类中不存在这个属性,需要改成规定的属性名 -->
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean>
<!-- 事务管理器DataSourceTransactionManager该类在spring-jdbc包中指定这个事务管理器管理配置的dataSource数据源 -->
<!-- <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> -->
<!-- 开启基于注解的事务 -->
<!-- <tx:annotation-driven transaction-manager="dataSourceTransactionManager"/> -->
<!-- 4.整合mybatis配置:创建MyBatis核心对象SqlSessionFactory整合关键步骤
目的:(1)想让Spring管理所有组件包括mapper
以后Service层要调用Dao层时只需使用@Autowired注解自动注入即可。
这样就避免了每次操作增删改查之前需要先获取到SqlSessionFactory->SqlSession->getMapper方法获得动态代理对象
即接口类的对象,然后才能操作具体增删改查操作。
(2)Spring声明式事务非常强大想让Spring管理事务。
注意①SqlSessionFactoryBean类能创建出SqlSessionFactory对象意味着容器一启动让容器帮我们创建SqlSessionFactory-->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 访问数据库必然需要数据源,管理数据库的连接,提高数据库性能,在数据源中配置使用的连接池 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 加载MyBatis全局配置文件config.xml如果config.xml中没有东西可以删掉
但一般建议留下可以放一些不太常用的配置如全局参数settings、数据库提供厂商等配置 -->
<!-- <property name="configLocation" value="classpath:config.xml"></property> -->
<!-- 指定SQL映射文件的位置当SQL映射文件和接口名不一致时使用该方法指定。
(不讲)?如果名字一致,则可以使用<mybatis:scan base-package=""/>扫描所有mapper SQL映射文件(报错mybatis前缀未绑定)? -->
<property name="mapperLocations" value="classpath:com/ssm/mapper/*.xml"></property>
<!-- 此处还可以配置别名处理器等,这些以前都是在全局配置文件中定义的现在都变成sqlSessionFactoryBean的一个属性,
相当于mybatis全局配置文件中的内容都拿到Spring配置文件来配置。 -->
</bean>
<!-- 5.扫描所有的mapper接口类让这些mapper能够自动注入
base-package:指定mapper接口的包名
注意:① 查找类路径下的映射器并自动将它们创建成MapperFactoryBean
即扫描所有的mapper接口类让这些mapper能够自动注入
② 如果有红叉报错也可以用,是约束引入有问题,不影响;
③ 以前还有这种写法(老版的项目一般这么做):
a.使用MapperScannerConfigurer
<bean class="MapperScannerConfigurer">
<property name="basePackage" value="Dao接口包名"/>
<bean> 或者
b.采用实体DAO调用方式采用接口org.apache.ibatis.session.SqlSession的实现类org.mybatis.spring.SqlSessionTemplate
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
-->
<mybatis-spring:scan base-package="com.ssm.mapper"/>
</beans>

@ -0,0 +1,63 @@
<?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">
<!-- 映射文件存放CRUD的sql语句 -->
<mapper namespace="com.ssm.mapper.DemoMapper">
<select id="getDemoById" resultMap="DemoResult" parameterType="Integer">
SELECT did,dname,comment
FROM Demo d
WHERE d.did=#{did}
</select>
<resultMap type="com.ssm.entity.Demo" id="DemoResult">
<id property="did" column="did"/>
<result property="dname" column="dname"/>
<result property="comment" column="comment"/>
</resultMap>
<select id="getDemoAll" resultMap="DemoResult" parameterType="int">
SELECT did,dname,comment
FROM Demo d
WHERE 1=1
limit #{param1},#{param2}
</select>
<insert id="addDemo" parameterType="com.ssm.entity.Demo">
insert into Demo(dname,comment)
values(#{dname},#{comment})
</insert>
<update id="updateDemo" parameterType="com.ssm.entity.Demo">
update Demo set dname=#{dname},comment=#{comment} where did=#{did}
</update>
<delete id="deleteDemoById" parameterType="Integer">
<!-- delete from 表名 where 列名称=某值 -->
delete from Demo where did=#{did}
</delete>
<delete id="deleteDemoAll">
<!-- delete from 表名 -->
delete from Demo
</delete>
<select id="countTotlePage" resultType="Integer">
SELECT count(*)
FROM Demo d
</select>
<select id="findDemoByDid" resultMap="DemoResult" parameterType="Integer">
SELECT did,dname,comment
FROM Demo d
WHERE d.did=#{did}
</select>
<!-- 模糊查询 -->
<select id="searchDemoByCondition" parameterType="String"
resultMap="DemoResult">
SELECT did,dname,comment
FROM Demo d
WHERE d.dname like '%${value}%' or d.comment like '%${value}%'
</select>
</mapper>

@ -0,0 +1,4 @@
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/ssm_farm?serverTimezone=Asia/Shanghai
user=root
password=root

@ -0,0 +1,41 @@
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<!-- 配置扫描器
只扫描标了@Controller的控制器
use-default-filters="false"禁用掉默认的过滤行为,只包含才会生效。即:
<context:component-scan base-package="com.ssm" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> -->
<!-- <context:component-scan base-package="com.ssm"></context:component-scan> -->
<context:component-scan base-package="com.ssm" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property> <!-- 前缀 -->
<property name="suffix" value=".jsp"></property> <!-- 后缀 -->
</bean>
<!-- 处理动态资源是SpringMVC的基础配置可以协调很多功能一般写SpringMVC项目都加上 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 正确的处理静态资源 -->
<mvc:default-servlet-handler/>
<bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean>
</beans>
Loading…
Cancel
Save