ssm-xml配置文件基本信息

本文是XML配置文件的总结,适合新手入门。涵盖了Mybatis的核心配置mybatis-config.xml,映射文件mapper.xml,springmvc的servlet配置,web.xml,以及spring的applicationContext.xml。同时提及了Mybatis动态创建表的功能,以及List<String>数据的读写操作。
摘要由CSDN通过智能技术生成

本人小白,xml配置文件的头着实让我头疼,索性总结一下方便使用

Mybatis核心配置文件mybatis-config.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>

Mybatis映射文件mapper.xml

<?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="">

</mapper>

springmvc-servlet.xml配置文件

(可以直接去spring手册上找)

<?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"
    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">

    <context:component-scan base-package="org.example.web"/>

    <!-- ... -->

</beans>

web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	version="3.1" metadata-complete="true">
    <!-- -->
</web-app>

spring的核心配置文件applicationContext.xml

(直接去spring手册上找的)

<?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">

    <bean id="..." class="...">   
        <!-- collaborators and configuration for this bean go here -->
    </bean>

    <bean id="..." class="...">
        <!-- collaborators and configuration for this bean go here -->
    </bean>

    <!-- more bean definitions go here -->

</beans>

Mybatis动态创建表

<update id="addTable" parameterType="Map">
    CREATE TABLE ${tableName}(
	id int(10) unsigned NOT NULL AUTO_INCREMENT,
	<foreach collection="tableColumns" item="value">
		${value} varchar(20) DEFAULT NULL,
	</foreach>
	PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8;
</update>

 List<String> optionsDataForm;和List<String> describeDataForm;的读和写

<?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="physical.examination.record.dao.DataFormDao">
	<select id="getDataForm" resultMap="dataform">
		select *
		from tryAndTry
	</select>
	<resultMap type="entity.DataFormEntity" id="dataform">
		<result column="Id" property="Id" jdbcType="INTEGER" />
		<collection property="describeDataForm" ofType="java.lang.String">
			<result column="describeDataForm" />
		</collection>
		<collection property="optionsDataForm" ofType="java.lang.String">
			<result column="optionsDataForm" />
		</collection>
	</resultMap>

	<insert id="addDataFormStandard" parameterType="entity.DataFormEntity">
		insert into
		tryAndTry(describeDataForm,optionsDataForm)
		values(
		<foreach collection="describeDataForm" item="describeDataForm">#{describeDataForm}
		</foreach>
		,
		<foreach collection="optionsDataForm" item="optionsDataForm">#{optionsDataForm}
		</foreach>
		)
	</insert>
</mapper>

 

(新手入门暂时遇到这些,后续再补充)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值