基于SSM框架做的增删改查

一、项目布局

 使用的编辑工具 idea2020  数据库 mysql5.1   前端代码因时间仓促就没怎么写。

1.1:导包:导入之后记得还标记为库。这样才能使用jar包。

 

1.2:导包完成后就需要创建SQL数据库和建表。因为这个项目相对来说算是一个入门SSM的小项目。数据库中的表就只有两张表 t_empployee和t_user两张表

t_empployee

 t_user

 1.3建库建表完成后就需要写配置文件

首先是Spring的核心配置文件 applicationContext.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: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">
<!--        加载jdbc.properties配置文件-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 扫描service包 -->
    <context:component-scan base-package="com.lzq.service"/>
<!-- 搭建数据库数据源  -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
    </bean>

<!--     MyBatis   配置SqlSessionFactoryBean对象-->
      <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--         依赖dataSource-->
          <property name="dataSource" ref="dataSource"/>
<!--          设置公共包别名-->
          <property name="typeAliasesPackage" value="com.lzq.domain"/>
<!--          加载指定路径下的mapper.xml文件-->
          <property name="mapperLocations" value="classpath:com/lzq/mapper/*.xml"/>
      </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--        扫描该包下的接口,只要是接口。底层就会创建实现类,去实现该包下的接口。-->
        <property name="basePackage" value="com.lzq.mapper"/>
    </bean>
</beans>

SpringMVC配置文件 SpringMVC.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
    <!--          SpringMVC配置文件-->
    <!--    扫描包下所有的文件-->
    <context:component-scan base-package="com.lzq.controller"/>
    <!--    开启扫描-->
    <mvc:annotation-driven/>
<!--    加载静态资源-->
    <mvc:default-servlet-handler/>


    <!--    视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
</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_4_0.xsd"
         version=
  • 3
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值