JAVAEE_springmvc+maven+batis

首先是创建一个maven的web项目,在这里就不详细说明了,大家可以自己去百度查一下。

创建好了之后我们需要配置该项目的build_path,这里我们选择java1.7以及tomcat7这里写图片描述
之后是对应src下的source文件夹,如果项目里面src/main下没有java,resource,或者src/test下没有java,resource的话我们可以自己手动创建一下,build_path时候对应其文件夹。
这里写图片描述
,接下来我们开始配置maven依赖。
以下是我的pom.xml中的配置:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ahiib</groupId>
  <artifactId>independent_recruit_student</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>independent_recruit_student Maven Webapp</name>
  <url>http://maven.apache.org</url>

   <properties>  
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
        <spring.version>4.1.4.RELEASE</spring.version>  
        <jackson.version>2.5.0</jackson.version>  
    </properties>

  <dependencies>
    <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
            <version>4.12</version>  
            <scope>test</scope>  
        </dependency>  

        <!-- spring -->  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-core</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-beans</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-tx</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-web</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-webmvc</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-jdbc</artifactId>  
            <version>${spring.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-test</artifactId>  
            <version>${spring.version}</version>  
            <scope>test</scope>  
        </dependency>  

        <!-- mybatis 包 -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis</artifactId>  
            <version>3.2.8</version>  
        </dependency>  

        <!--mybatis spring 插件 -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis-spring</artifactId>  
            <version>1.2.2</version>  
        </dependency>  

        <!-- mysql连接 -->  
        <dependency>  
            <groupId>mysql</groupId>  
            <artifactId>mysql-connector-java</artifactId>  
            <version>5.1.34</version>  
        </dependency>  

        <!-- 数据源 -->  
        <dependency>  
            <groupId>com.alibaba</groupId>  
            <artifactId>druid</artifactId>  
            <version>1.0.12</version>  
        </dependency>  

        <dependency>  
            <groupId>org.aspectj</groupId>  
            <artifactId>aspectjweaver</artifactId>  
            <version>1.8.4</version>  
        </dependency>  

        <!-- log4j -->  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
            <version>1.2.17</version>  
        </dependency>  

        <!-- servlet -->  
        <dependency>  
            <groupId>javax.servlet</groupId>  
            <artifactId>servlet-api</artifactId>  
            <version>3.0-alpha-1</version>  
        </dependency>  

        <dependency>  
            <groupId>javax.servlet</groupId>  
            <artifactId>jstl</artifactId>  
            <version>1.2</version>  
        </dependency>  

        <!-- json -->  
        <dependency>  
            <groupId>org.codehaus.jackson</groupId>  
            <artifactId>jackson-mapper-asl</artifactId>  
            <version>1.9.13</version>  
        </dependency>  

        <dependency>  
            <groupId>com.alibaba</groupId>  
            <artifactId>fastjson</artifactId>  
            <version>1.2.3</version>  
        </dependency>  

        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-annotations</artifactId>  
            <version>${jackson.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-core</artifactId>  
            <version>${jackson.version}</version>  
        </dependency>  

        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-databind</artifactId>  
            <version>${jackson.version}</version>  
        </dependency>  
        <!-- 文件上传 -->  
        <dependency>  
            <groupId>commons-io</groupId>  
            <artifactId>commons-io</artifactId>  
            <version>2.4</version>  
        </dependency>  

        <dependency>  
            <groupId>commons-fileupload</groupId>  
            <artifactId>commons-fileupload</artifactId>  
            <version>1.2.2</version>  
        </dependency>  
  </dependencies>
  <build>
    <finalName>independent_recruit_student</finalName>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

     <plugins>  
            <!-- Run the JUnit unit tests in an isolated classloader -->  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-surefire-plugin</artifactId>  
                <version>2.4.2</version>  
                <configuration>  
                    <skipTests>true</skipTests>  
                </configuration>  
            </plugin>  

            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-war-plugin</artifactId>  
                <version>2.3</version>  
                <configuration>  
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>  
                </configuration>  
            </plugin>  

            <!-- generate java doc -->  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-javadoc-plugin</artifactId>  
                <version>2.9.1</version>  
                <configuration>  
                    <javadocDirectory>target/javadoc</javadocDirectory>  
                    <reportOutputDirectory>target/javadoc</reportOutputDirectory>  
                    <charset>UTF-8</charset>  
                    <encoding>UTF-8</encoding>  
                    <docencoding>UTF-8</docencoding>  
                    <show>private</show>  
                </configuration>  
            </plugin>  

      </plugins>
  </build>
</project>

接下来再resource文件夹中配置spring.xml文件,我们创建spring.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-4.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-4.1.xsd">

    <!--引入配置属性文件 -->
    <context:property-placeholder location="classpath:config.properties" />

    <!--自动扫描含有@Service将其注入为bean -->
    <context:component-scan base-package="com.ahiib.service" />

</beans>

接着继续配置spring-batis.xml文件。配置名都是可以随便起的。这个没有多大的影响,有些人喜欢配置application-context.xml。这些都是没有多大关系的,具体我的batis.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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
        ">

    <!-- 配置数据源 使用的是Druid数据源 -->
    <bean name="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}" />

        <!-- 初始化连接大小 -->
        <property name="initialSize" value="0" />
        <!-- 连接池最大使用连接数量 -->
        <property name="maxActive" value="20" />

        <!-- 连接池最小空闲 -->
        <property name="minIdle" value="0" />
        <!-- 获取连接最大等待时间 -->
        <property name="maxWait" value="60000" />
        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize"
            value="33" />
        <!-- 用来检测有效sql -->
        <property name="validationQuery" value="${validationQuery}" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
        <property name="testWhileIdle" value="true" />
        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="25200000" />
        <!-- 打开removeAbandoned功能 -->
        <property name="removeAbandoned" value="true" />
        <!-- 1800秒,也就是30分钟 -->
        <property name="removeAbandonedTimeout" value="1800" />
        <!-- 关闭abanded连接时输出错误日志 -->
        <property name="logAbandoned" value="true" />
        <!-- 监控数据库 -->
        <property name="filters" value="mergeStat" />
    </bean>

    <!-- myBatis文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
        <property name="mapperLocations" value="classpath:com/ahiib/mapping/*.xml" />
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ahiib.dao" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 注解方式配置事物 -->
    <!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->

    <!-- 拦截器方式配置事物 -->
    <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />

            <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="select*" propagation="SUPPORTS" read-only="true" />

        </tx:attributes>
    </tx:advice>
    <!-- Spring aop事务管理 -->
    <aop:config>
        <aop:pointcut id="transactionPointcut"
            expression="execution(* com.ahiib.service..*Impl.*(..))" />
        <aop:advisor pointcut-ref="transactionPointcut"
            advice-ref="transactionAdvice" />
    </aop:config>

</beans>

配置完之后我们配置jdbc数据连接配置文件,这里需要对应之前spring.xml中的config配置文件名;
config.properties中配置为:

#mysql version database druid setting
validationQuery=SELECT 1
jdbc.url=jdbc:mysql://localhost:3306/independent_recruit_student?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456

Log4J的配置为:

### set log levels ###
log4j.rootLogger = INFO , C , D , E 

### console ###
log4j.appender.C = org.apache.log4j.ConsoleAppender
log4j.appender.C.Target = System.out
log4j.appender.C.layout = org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern = [independent_recruit_student][%p] [%-d{yyyy-MM-dd HH:mm:ss}] %C.%M(%L) | %m%n

### log file ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ../logs/independent_recruit_student.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = INFO 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = [independent_recruit_student][%p] [%-d{yyyy-MM-dd HH:mm:ss}] %C.%M(%L) | %m%n

### exception ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = ../logs/independent_recruit_student_error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = [independent_recruit_student][%p] [%-d{yyyy-MM-dd HH:mm:ss}] %C.%M(%L) | %m%n

最后我们配置web.xml文件。这里我们确定下该文件的project Facets。我们右击该项目-properties-maven-project factes
具体的配置是:
这里写图片描述

然后我们配置web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <display-name>independent_recruit_student</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring.xml,classpath:spring-mybatis.xml</param-value>
    </context-param>

    <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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

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

    <servlet>
        <description>spring mvc servlet</description>
        <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>
    </servlet>
    <servlet-mapping>
        <servlet-name>springMvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

<!-- 由于请求路径为"/",拦截所有的请求,以致无法访问静态资源,故而 采用以下方式访问 -->
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.js</url-pattern>
        <url-pattern>*.css</url-pattern>
        <url-pattern>*.gif</url-pattern>
        <url-pattern>*.png</url-pattern>
        <url-pattern>*.jpg</url-pattern>
        <url-pattern>*.eot</url-pattern>
        <url-pattern>*.ttf</url-pattern>
        <url-pattern>*.eot@</url-pattern>
        <url-pattern>*.woff</url-pattern>
        <url-pattern>*.html</url-pattern>
        <url-pattern>*.less</url-pattern>
        <url-pattern>*.ico</url-pattern>
        <url-pattern>*.js.map</url-pattern>
    </servlet-mapping>

    <!-- 配置session超时时间,单位分钟 -->
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

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

我之前也有看到很多人的配置,因为其拦截很多静态页,导致html和css,js等都被拦截,所以我们在web.xml中我有详细注释,一定得加上去。
至此整个项目已经完成了一大半了。接下来我们创建文件夹,我们在src/main/java/com/ahiib/ 下创建

  1. controller
  2. dao
  3. entity
  4. service
  5. mapping(这个文件夹我们在配置batis中有扫面该文件夹下所有的xml)

    在controller中创建UserController

package com.ahiib.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ahiib.entity.User;
import com.ahiib.service.UserService;


@Controller  
@RequestMapping("/user")  
public class UserController {
     @Autowired  
     private UserService userService;

     @RequestMapping("/findAllUsers")
     @ResponseBody
     public Object findAllUsers(){  
         List<User> users = userService.findAll();  
         return users;  
     }  

     @RequestMapping("/findUser/{userId}")  
     public String findUser(Map<String, Object> map,  String userId){  
         User user = userService.selectByPrimaryKey(userId);  
         map.put("user", user);
         return "jsp/userInfo";  
     }  
}

这里我们尽管可以使用map,作用相等于request.setAttribute(“key”,value);

在service文件夹中创建UserService

package com.ahiib.service;

import java.util.List;

import com.ahiib.entity.User;

public interface UserService {
    int deleteByPrimaryKey(String userId);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(String userId);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    List<User> findAll();
}

在service。Impl文件夹中创建UserServiceImpl的class

package com.ahiib.service.Impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ahiib.dao.UserMapper;
import com.ahiib.entity.User;
import com.ahiib.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService{

    @Autowired  
    private UserMapper userMapper;

    public int deleteByPrimaryKey(String userId) {
        return userMapper.deleteByPrimaryKey(userId);
    }

    public int insert(User user) {
        return userMapper.insert(user);
    }

    public int insertSelective(User user) {
        return userMapper.insertSelective(user);
    }

    public User selectByPrimaryKey(String userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    public int updateByPrimaryKeySelective(User user) {
        return userMapper.updateByPrimaryKeySelective(user);
    }

    public int updateByPrimaryKey(User user) {
        return userMapper.updateByPrimaryKey(user);
    }

    public List<User> findAll() {
        return userMapper.findAll();
    }

}

上面的代码并没有多大可用之处,我只是用到了selectByPrimaryKey以及findAll这2个实现,其他的大家可以自己去写。
最后差不多了 我们继续配置mapper文件
我们可以用General工具去自动生成javaBean和mapper文件以及dao文件
我的userMapper文件配置:

<?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="com.ahiib.dao.UserMapper" >
  <resultMap id="BaseResultMap" type="com.ahiib.entity.User" >
    <id column="user_id" property="userId" jdbcType="VARCHAR" />
    <result column="userName" property="username" jdbcType="VARCHAR" />
    <result column="user_type" property="userType" jdbcType="VARCHAR" />
    <result column="employeeId" property="employeeid" jdbcType="VARCHAR" />
    <result column="password" property="password" jdbcType="VARCHAR" />
    <result column="org_id" property="orgId" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="Mobie_Phone" property="mobiePhone" jdbcType="VARCHAR" />
    <result column="IsLocked" property="islocked" jdbcType="INTEGER" />
    <result column="is_enable" property="isEnable" jdbcType="INTEGER" />
    <result column="randNum" property="randnum" jdbcType="VARCHAR" />
    <result column="expire_Time" property="expireTime" jdbcType="TIMESTAMP" />
    <result column="require_password_change" property="requirePasswordChange" jdbcType="INTEGER" />
    <result column="last_locale" property="lastLocale" jdbcType="VARCHAR" />
    <result column="Last_Login_date" property="lastLoginDate" jdbcType="TIMESTAMP" />
    <result column="operration_user_id" property="operrationUserId" jdbcType="VARCHAR" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
    <result column="remark" property="remark" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    user_id, userName, user_type, employeeId, password, org_id, email, Mobie_Phone, IsLocked, 
    is_enable, randNum, expire_Time, require_password_change, last_locale, Last_Login_date, 
    operration_user_id, create_date, update_date, remark
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_user
    where user_id = #{userId,jdbcType=VARCHAR}
  </select>

  <!-- findAll查询所有的用户信息  -->
  <select id="findAll" resultMap="BaseResultMap" >
    select 
    <include refid="Base_Column_List" />
    from t_user
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_user
    where user_id = #{userId,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.ahiib.entity.User" >
    insert into t_user (user_id, userName, user_type, 
      employeeId, password, org_id, 
      email, Mobie_Phone, IsLocked, 
      is_enable, randNum, expire_Time, 
      require_password_change, last_locale, Last_Login_date, 
      operration_user_id, create_date, update_date, 
      remark)
    values (#{userId,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{userType,jdbcType=VARCHAR}, 
      #{employeeid,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{orgId,jdbcType=VARCHAR}, 
      #{email,jdbcType=VARCHAR}, #{mobiePhone,jdbcType=VARCHAR}, #{islocked,jdbcType=INTEGER}, 
      #{isEnable,jdbcType=INTEGER}, #{randnum,jdbcType=VARCHAR}, #{expireTime,jdbcType=TIMESTAMP}, 
      #{requirePasswordChange,jdbcType=INTEGER}, #{lastLocale,jdbcType=VARCHAR}, #{lastLoginDate,jdbcType=TIMESTAMP}, 
      #{operrationUserId,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, #{updateDate,jdbcType=TIMESTAMP}, 
      #{remark,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.ahiib.entity.User" >
    insert into t_user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        user_id,
      </if>
      <if test="username != null" >
        userName,
      </if>
      <if test="userType != null" >
        user_type,
      </if>
      <if test="employeeid != null" >
        employeeId,
      </if>
      <if test="password != null" >
        password,
      </if>
      <if test="orgId != null" >
        org_id,
      </if>
      <if test="email != null" >
        email,
      </if>
      <if test="mobiePhone != null" >
        Mobie_Phone,
      </if>
      <if test="islocked != null" >
        IsLocked,
      </if>
      <if test="isEnable != null" >
        is_enable,
      </if>
      <if test="randnum != null" >
        randNum,
      </if>
      <if test="expireTime != null" >
        expire_Time,
      </if>
      <if test="requirePasswordChange != null" >
        require_password_change,
      </if>
      <if test="lastLocale != null" >
        last_locale,
      </if>
      <if test="lastLoginDate != null" >
        Last_Login_date,
      </if>
      <if test="operrationUserId != null" >
        operration_user_id,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="updateDate != null" >
        update_date,
      </if>
      <if test="remark != null" >
        remark,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="userId != null" >
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="username != null" >
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="userType != null" >
        #{userType,jdbcType=VARCHAR},
      </if>
      <if test="employeeid != null" >
        #{employeeid,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null" >
        #{orgId,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="mobiePhone != null" >
        #{mobiePhone,jdbcType=VARCHAR},
      </if>
      <if test="islocked != null" >
        #{islocked,jdbcType=INTEGER},
      </if>
      <if test="isEnable != null" >
        #{isEnable,jdbcType=INTEGER},
      </if>
      <if test="randnum != null" >
        #{randnum,jdbcType=VARCHAR},
      </if>
      <if test="expireTime != null" >
        #{expireTime,jdbcType=TIMESTAMP},
      </if>
      <if test="requirePasswordChange != null" >
        #{requirePasswordChange,jdbcType=INTEGER},
      </if>
      <if test="lastLocale != null" >
        #{lastLocale,jdbcType=VARCHAR},
      </if>
      <if test="lastLoginDate != null" >
        #{lastLoginDate,jdbcType=TIMESTAMP},
      </if>
      <if test="operrationUserId != null" >
        #{operrationUserId,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.ahiib.entity.User" >
    update t_user
    <set >
      <if test="username != null" >
        userName = #{username,jdbcType=VARCHAR},
      </if>
      <if test="userType != null" >
        user_type = #{userType,jdbcType=VARCHAR},
      </if>
      <if test="employeeid != null" >
        employeeId = #{employeeid,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        password = #{password,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null" >
        org_id = #{orgId,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="mobiePhone != null" >
        Mobie_Phone = #{mobiePhone,jdbcType=VARCHAR},
      </if>
      <if test="islocked != null" >
        IsLocked = #{islocked,jdbcType=INTEGER},
      </if>
      <if test="isEnable != null" >
        is_enable = #{isEnable,jdbcType=INTEGER},
      </if>
      <if test="randnum != null" >
        randNum = #{randnum,jdbcType=VARCHAR},
      </if>
      <if test="expireTime != null" >
        expire_Time = #{expireTime,jdbcType=TIMESTAMP},
      </if>
      <if test="requirePasswordChange != null" >
        require_password_change = #{requirePasswordChange,jdbcType=INTEGER},
      </if>
      <if test="lastLocale != null" >
        last_locale = #{lastLocale,jdbcType=VARCHAR},
      </if>
      <if test="lastLoginDate != null" >
        Last_Login_date = #{lastLoginDate,jdbcType=TIMESTAMP},
      </if>
      <if test="operrationUserId != null" >
        operration_user_id = #{operrationUserId,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateDate != null" >
        update_date = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null" >
        remark = #{remark,jdbcType=VARCHAR},
      </if>
    </set>
    where user_id = #{userId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ahiib.entity.User" >
    update t_user
    set userName = #{username,jdbcType=VARCHAR},
      user_type = #{userType,jdbcType=VARCHAR},
      employeeId = #{employeeid,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      org_id = #{orgId,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      Mobie_Phone = #{mobiePhone,jdbcType=VARCHAR},
      IsLocked = #{islocked,jdbcType=INTEGER},
      is_enable = #{isEnable,jdbcType=INTEGER},
      randNum = #{randnum,jdbcType=VARCHAR},
      expire_Time = #{expireTime,jdbcType=TIMESTAMP},
      require_password_change = #{requirePasswordChange,jdbcType=INTEGER},
      last_locale = #{lastLocale,jdbcType=VARCHAR},
      Last_Login_date = #{lastLoginDate,jdbcType=TIMESTAMP},
      operration_user_id = #{operrationUserId,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      remark = #{remark,jdbcType=VARCHAR}
    where user_id = #{userId,jdbcType=VARCHAR}
  </update>
</mapper>

有些时候我们会对应层服务,service-serviceImpl
dao-daoImpl,习惯这些的话我们也多说下,我们在创建DaoImpl其实现dao曾的mapper后用到了session去处理resource时候我们会用到mapper文件,这个时候我们会去小写这些mapper,列userMapper,这时候我们需要对应UserMapper文件中的nameSpace就要去对应上就行了。

至此我们可以去跑这项目了。

整个项目的截图:
这里写图片描述

最后访问该项目
这里写图片描述

第一次发这样的框架基础搭建,如果有问题大家指出,我会回复。如果对我的博文有不一样的观点,纠正我,谢谢啦

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很高兴回答您的问题!Java项目员工管理系统是一个非常常见的实践项目。它通常涉及到前后端分离的架构,使用JavaEE作为后端框架,Vue作为前端框架,SSM作为整个项目的技术栈,MySQL作为数据库,同时使用Maven进行项目构建和依赖管理,Axios用于前后端数据交互,HTML用于构建前端页面。 以下是一个简单的步骤指南,以帮助您开始这个项目: 1. 确定项目需求:明确系统所需的功能和特性,例如员工信息的增删改查、权限管理等。 2. 创建数据库:使用MySQL或其他数据库管理系统创建一个数据库,定义员工表和其他相关表。 3. 后端开发: - 使用JavaEE作为后端框架,搭建项目结构。 - 使用SSM框架(Spring、SpringMVC、MyBatis)进行后端开发。配置数据源、连接数据库,并编写DAO层接口和Mapper文件。 - 实现业务逻辑层和控制层,编写接口和请求处理方法。 4. 前端开发: - 使用Vue作为前端框架,搭建项目结构。 - 使用Axios进行前后端数据交互,发送HTTP请求。 - 使用HTML和CSS构建前端页面,实现员工信息的展示、增删改查等功能。 5. 前后端联调: - 后端提供接口,在前端使用Axios发送请求,获取后端数据。 - 前端通过Ajax获取数据,并进行展示和交互。 6. 项目打包部署: - 使用Maven进行项目构建和依赖管理。配置pom.xml文件,添加所需的依赖。 - 部署后端项目到服务器,配置数据库连接等相关配置。 - 将前端代码打包为静态文件,并部署到Web服务器中。 这只是一个简单的指南,实际开发过程中还需要考虑更多的细节和问题。希望以上信息对您有所帮助!如有任何进一步的问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值