用户工具

站点工具


分享:技术:示例项目:springmvc_mybatis_spring_freemarker_maven

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

后一修订版
前一修订版
分享:技术:示例项目:springmvc_mybatis_spring_freemarker_maven [2015/07/07 08:23]
gxx 创建
分享:技术:示例项目:springmvc_mybatis_spring_freemarker_maven [2015/07/07 10:37] (当前版本)
gxx
行 8: 行 8:
 |  maven  |  3.0  | |  maven  |  3.0  |
 ===== 项目结构 ===== ===== 项目结构 =====
-{{ :​分享:​技术:​模板项目:​项目结构.png?​300 |}}+{{ :​分享:​技术:​示例项目:​项目结构.png?​300 |}}
 ===== 源代码 ===== ===== 源代码 =====
 +==== UserMapper.java ====
 <file java UserMapper.java>​ <file java UserMapper.java>​
 package com.gxx.record.base.dao;​ package com.gxx.record.base.dao;​
行 39: 行 40:
 } }
 </​file>​ </​file>​
 +==== UserMapper.xml ====
 +<file xml UserMapper.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="​com.gxx.record.base.dao.UserMapper"​ >
 +  <​resultMap id="​BaseResultMap"​ type="​com.gxx.record.base.vo.User"​ >
 +    <id column="​id"​ property="​id"​ jdbcType="​INTEGER"​ />
 +    <result column="​name"​ property="​name"​ jdbcType="​VARCHAR"​ />
 +    <result column="​password"​ property="​password"​ jdbcType="​VARCHAR"​ />
 +    <result column="​create_date"​ property="​createDate"​ jdbcType="​VARCHAR"​ />
 +    <result column="​create_time"​ property="​createTime"​ jdbcType="​VARCHAR"​ />
 +  </​resultMap>​
 +  <sql id="​Base_Column_List"​ >
 +    id, name, password, create_date,​ create_time
 +  </​sql>​
 +  <select id="​selectByPrimaryKey"​ resultMap="​BaseResultMap"​ parameterType="​java.lang.Integer"​ >
 +    select ​
 +    <include refid="​Base_Column_List"​ />
 +    from user
 +    where id = #​{id,​jdbcType=INTEGER}
 +  </​select>​
 +  <delete id="​deleteByPrimaryKey"​ parameterType="​java.lang.Integer"​ >
 +    delete from user
 +    where id = #​{id,​jdbcType=INTEGER}
 +  </​delete>​
 +  <insert id="​insert"​ parameterType="​com.gxx.record.base.vo.User"​ >
 +    insert into user (id, name, password, ​
 +      create_date,​ create_time)
 +    values (#​{id,​jdbcType=INTEGER},​ #​{name,​jdbcType=VARCHAR},​ #​{password,​jdbcType=VARCHAR}, ​
 +      #​{createDate,​jdbcType=VARCHAR},​ #​{createTime,​jdbcType=VARCHAR})
 +  </​insert>​
 +  <insert id="​insertSelective"​ parameterType="​com.gxx.record.base.vo.User"​ >
 +    insert into user
 +    <trim prefix="​("​ suffix="​)"​ suffixOverrides=","​ >
 +      <if test="​id != null" >
 +        id,
 +      </if>
 +      <if test="​name != null" >
 +        name,
 +      </if>
 +      <if test="​password != null" >
 +        password,
 +      </if>
 +      <if test="​createDate != null" >
 +        create_date,​
 +      </if>
 +      <if test="​createTime != null" >
 +        create_time,​
 +      </if>
 +    </​trim>​
 +    <trim prefix="​values (" suffix="​)"​ suffixOverrides=","​ >
 +      <if test="​id != null" >
 +        #​{id,​jdbcType=INTEGER},​
 +      </if>
 +      <if test="​name != null" >
 +        #​{name,​jdbcType=VARCHAR},​
 +      </if>
 +      <if test="​password != null" >
 +        #​{password,​jdbcType=VARCHAR},​
 +      </if>
 +      <if test="​createDate != null" >
 +        #​{createDate,​jdbcType=VARCHAR},​
 +      </if>
 +      <if test="​createTime != null" >
 +        #​{createTime,​jdbcType=VARCHAR},​
 +      </if>
 +    </​trim>​
 +  </​insert>​
 +  <update id="​updateByPrimaryKeySelective"​ parameterType="​com.gxx.record.base.vo.User"​ >
 +    update user
 +    <set >
 +      <if test="​name != null" >
 +        name = #​{name,​jdbcType=VARCHAR},​
 +      </if>
 +      <if test="​password != null" >
 +        password = #​{password,​jdbcType=VARCHAR},​
 +      </if>
 +      <if test="​createDate != null" >
 +        create_date = #​{createDate,​jdbcType=VARCHAR},​
 +      </if>
 +      <if test="​createTime != null" >
 +        create_time = #​{createTime,​jdbcType=VARCHAR},​
 +      </if>
 +    </​set>​
 +    where id = #​{id,​jdbcType=INTEGER}
 +  </​update>​
 +  <update id="​updateByPrimaryKey"​ parameterType="​com.gxx.record.base.vo.User"​ >
 +    update user
 +    set name = #​{name,​jdbcType=VARCHAR},​
 +      password = #​{password,​jdbcType=VARCHAR},​
 +      create_date = #​{createDate,​jdbcType=VARCHAR},​
 +      create_time = #​{createTime,​jdbcType=VARCHAR}
 +    where id = #​{id,​jdbcType=INTEGER}
 +  </​update>​
 +  ​
 +  <select id="​getUserByName"​ resultMap="​BaseResultMap"​ parameterType="​java.lang.String"​ >
 +    select ​
 +    <include refid="​Base_Column_List"​ />
 +    from user
 +    where name = #​{name,​jdbcType=VARCHAR}
 +  </​select>​
 +</​mapper>​
 +</​file>​
 +==== User.java ====
 +<file java User.java>​
 +package com.gxx.record.base.vo;​
 +
 +public class User {
 +    private Integer id;
 +
 +    private String name;
 +
 +    private String password;
 +
 +    private String createDate;
 +
 +    private String createTime;
 +
 +    public Integer getId() {
 +        return id;
 +    }
 +
 +    public void setId(Integer id) {
 +        this.id = id;
 +    }
 +
 +    public String getName() {
 +        return name;
 +    }
 +
 +    public void setName(String name) {
 +        this.name = name == null ? null : name.trim();​
 +    }
 +
 +    public String getPassword() {
 +        return password;
 +    }
 +
 +    public void setPassword(String password) {
 +        this.password = password == null ? null : password.trim();​
 +    }
 +
 +    public String getCreateDate() {
 +        return createDate;
 +    }
 +
 +    public void setCreateDate(String createDate) {
 +        this.createDate = createDate == null ? null : createDate.trim();​
 +    }
 +
 +    public String getCreateTime() {
 +        return createTime;
 +    }
 +
 +    public void setCreateTime(String createTime) {
 +        this.createTime = createTime == null ? null : createTime.trim();​
 +    }
 +}
 +</​file>​
 +==== BaseDto.java ====
 +<file java BaseDto.java>​
 +package com.gxx.record.dto;​
 +
 +/**
 + * <dl>
 + ​* ​   <​dt><​b>​Title:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   基础传输对象
 + ​* ​   </dd>
 + ​* ​   <​dt><​b>​Description:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   <​p>​none
 + ​* ​   </dd>
 + * </dl>
 + *
 + * @author Administrator
 + * @version 1.0, 2015年6月18日
 + * @since record
 + *
 + */
 +public class BaseDto {
 +
 + String message;//​信息
 + boolean success;//​是否成功
 +
 + public String getMessage() {
 + return message;
 + }
 + public void setMessage(String message) {
 + this.message = message;
 + }
 + public boolean getSuccess() {
 + return success;
 + }
 + public void setSuccess(boolean success) {
 + this.success = success;
 + }
 +}
 +</​file>​
 +==== UserDto.java ====
 +<file java UserDto.java>​
 +package com.gxx.record.dto;​
 +/**
 + * <dl>
 + ​* ​   <​dt><​b>​Title:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   用户传输对象
 + ​* ​   </dd>
 + ​* ​   <​dt><​b>​Description:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   <​p>​none
 + ​* ​   </dd>
 + * </dl>
 + *
 + * @author Administrator
 + * @version 1.0, 2015年6月18日
 + * @since record
 + *
 + */
 +public class UserDto extends BaseDto {
 +
 + private Integer id;//id
 +    private String name;//​姓名
 +    private String password;//​密码
 +    private String createDate;//​创建日期
 +    private String createTime;//​创建时间
 +    ​
 + public Integer getId() {
 + return id;
 + }
 + public void setId(Integer id) {
 + this.id = id;
 + }
 + public String getName() {
 + return name;
 + }
 + public void setName(String name) {
 + this.name = name;
 + }
 + public String getPassword() {
 + return password;
 + }
 + public void setPassword(String password) {
 + this.password = password;
 + }
 + public String getCreateDate() {
 + return createDate;
 + }
 + public void setCreateDate(String createDate) {
 + this.createDate = createDate;
 + }
 + public String getCreateTime() {
 + return createTime;
 + }
 + public void setCreateTime(String createTime) {
 + this.createTime = createTime;
 + }
 +}
 +</​file>​
 +==== UserService.java ====
 +<file java UserService.java>​
 +package com.gxx.record.service;​
 +
 +import com.gxx.record.base.vo.User;​
 +
 +/**
 + * <dl>
 + ​* ​   <​dt><​b>​Title:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   用户服务接口
 + ​* ​   </dd>
 + ​* ​   <​dt><​b>​Description:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   <​p>​none
 + ​* ​   </dd>
 + * </dl>
 + *
 + * @author Administrator
 + * @version 1.0, 2015年6月18日
 + * @since record
 + *
 + */
 +public interface UserService {
 + /**
 + * 新增用户
 + * @param user
 + */
 + public void doSaveUser(User user);
 +
 + /**
 + * 根据姓名查用户
 + * @param name
 + * @return
 + */
 + public User getUserByName(String name);
 +}
 +</​file>​
 +==== UserServiceImpl.java ====
 +<file java UserServiceImpl.java>​
 +package com.gxx.record.service.impl;​
 +
 +import org.springframework.beans.factory.annotation.Autowired;​
 +import org.springframework.stereotype.Service;​
 +
 +import com.gxx.record.base.dao.UserMapper;​
 +import com.gxx.record.base.vo.User;​
 +import com.gxx.record.service.UserService;​
 +
 +/**
 + * <dl>
 + ​* ​   <​dt><​b>​Title:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   用户服务实现类
 + ​* ​   </dd>
 + ​* ​   <​dt><​b>​Description:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   <​p>​none
 + ​* ​   </dd>
 + * </dl>
 + *
 + * @author Administrator
 + * @version 1.0, 2015年6月18日
 + * @since record
 + *
 + */
 +@Service("​userService"​)
 +public class UserServiceImpl implements UserService {
 +
 + @Autowired
 + private UserMapper userDao;
 +
 + /**
 + * 新增用户
 + * @param user
 + */
 + public void doSaveUser(User user) {
 + userDao.insert(user);​
 + }
 +
 + /**
 + * 根据姓名查用户
 + * @param name
 + * @return
 + */
 + public User getUserByName(String name) {
 + return userDao.getUserByName(name);​
 + }
 +}
 +</​file>​
 +==== UserController.java ====
 +<file java UserController.java>​
 +package com.gxx.record.web.user;​
 +
 +import javax.servlet.http.HttpServletRequest;​
 +
 +import org.apache.log4j.Logger;​
 +import org.springframework.beans.factory.annotation.Autowired;​
 +import org.springframework.stereotype.Controller;​
 +import org.springframework.web.bind.annotation.RequestMapping;​
 +import org.springframework.web.bind.annotation.RequestMethod;​
 +import org.springframework.web.bind.annotation.ResponseBody;​
 +
 +import com.gxx.record.base.vo.User;​
 +import com.gxx.record.dto.UserDto;​
 +import com.gxx.record.service.UserService;​
 +
 +/**
 + * QueryAllocateController负责查询调拨
 + ​* ​
 + * @author gxx
 + */
 +@Controller
 +@RequestMapping("/​user/"​)
 +public class UserController {
 + /**
 + * 日志处理器
 + */
 + private final Logger logger = Logger.getLogger(UserController.class);​
 +
 + @Autowired
 + private UserService userService;​
 +
 + @RequestMapping(value = "/​preRegistFtl",​ method = RequestMethod.GET)
 + public String preRegistFtl() {
 + return "​user/​preRegistFtl";​
 + }
 +
 + @RequestMapping(value = "/​preRegistJsp",​ method = RequestMethod.GET)
 + public String preRegistJsp() {
 + return "​user/​preRegistJsp";​
 + }
 +
 + /**
 + * 注册
 + * @param request
 + * @param userDto
 + * @return
 + */
 + @RequestMapping(value = "/​registJsp",​produces="​application/​json"​)
 + public @ResponseBody UserDto registJsp(HttpServletRequest request, UserDto userDto) {
 + logger.info("​用户注册:姓名["​ + userDto.getName() + "​],密码["​ + userDto.getPassword() + "​]"​);​
 + /**
 + * 1.判用户名是否存在
 + */
 + User user = userService.getUserByName(userDto.getName());​
 + if(user != null){
 + userDto.setSuccess(Boolean.FALSE.booleanValue());​
 + userDto.setMessage("​用户名["​ + userDto.getName() + "​]已存在!"​);​
 + return userDto;
 + }
 + /**
 + * 2.创建用户对象 并 新增用户
 + */
 + user = new User();
 + user.setName(userDto.getName());​
 + user.setPassword(userDto.getPassword());​
 + user.setCreateDate("​20150618"​);​
 + user.setCreateTime("​000000"​);​
 + userService.doSaveUser(user);​
 + /**
 + * 3.返回结果
 + */
 + userDto.setSuccess(Boolean.TRUE.booleanValue());​
 + userDto.setMessage("​注册成功!"​);​
 + return userDto;
 + }
 +
 + /**
 + * 注册
 + * @param request
 + * @param userDto
 + * @return
 + */
 + @RequestMapping(value = "/​registFtl"​)
 + public String registFtl(HttpServletRequest request, UserDto userDto) {
 + logger.info("​用户注册:姓名["​ + userDto.getName() + "​],密码["​ + userDto.getPassword() + "​]"​);​
 + /**
 + * 1.判用户名是否存在
 + */
 + User user = userService.getUserByName(userDto.getName());​
 + if(user != null){
 + userDto.setSuccess(Boolean.FALSE.booleanValue());​
 + userDto.setMessage("​用户名["​ + userDto.getName() + "​]已存在!"​);​
 + return "​user/​result";​
 + }
 + /**
 + * 2.创建用户对象 并 新增用户
 + */
 + user = new User();
 + user.setName(userDto.getName());​
 + user.setPassword(userDto.getPassword());​
 + user.setCreateDate("​20150618"​);​
 + user.setCreateTime("​000000"​);​
 + userService.doSaveUser(user);​
 + /**
 + * 3.返回结果
 + */
 + userDto.setSuccess(Boolean.TRUE.booleanValue());​
 + userDto.setMessage("​注册成功!"​);​
 + return "​user/​result";​
 + }
 +}
 +</​file>​
 +==== application-context.xml ====
 +<file xml application-context.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:​aop="​http://​www.springframework.org/​schema/​aop"​
 + xmlns:​context="​http://​www.springframework.org/​schema/​context"​ xmlns:​tx="​http://​www.springframework.org/​schema/​tx"​
 + xmlns:​jpa="​http://​www.springframework.org/​schema/​data/​jpa"​
 + xmlns:​security="​http://​www.springframework.org/​schema/​security"​
 + xsi:​schemaLocation="​
 + http://​www.springframework.org/​schema/​aop ​
 + http://​www.springframework.org/​schema/​aop/​spring-aop-4.0.xsd
 + http://​www.springframework.org/​schema/​security ​
 + http://​www.springframework.org/​schema/​security/​spring-security-3.2.xsd
 + http://​www.springframework.org/​schema/​beans ​
 + http://​www.springframework.org/​schema/​beans/​spring-beans-4.0.xsd
 + http://​www.springframework.org/​schema/​data/​jpa ​
 + http://​www.springframework.org/​schema/​data/​jpa/​spring-jpa-1.3.xsd
 + http://​www.springframework.org/​schema/​tx ​
 + http://​www.springframework.org/​schema/​tx/​spring-tx-4.0.xsd
 + http://​www.springframework.org/​schema/​context ​
 + http://​www.springframework.org/​schema/​context/​spring-context-4.0.xsd">​
 +
 + <!-- Activates annotation-based bean configuration -->
 + <​context:​annotation-config />
 +
 + <!-- Scans for application @Components to deploy -->
 + <​context:​component-scan base-package="​com.gxx.record"​ />
 +
 + <!-- 数据库配置文件位置 -->
 + <​context:​property-placeholder location="​classpath:/​jdbc.properties"​ />
 +
 + <!-- 配置dbcp数据源 -->
 + <bean id="​dataSource"​ class="​org.apache.commons.dbcp.BasicDataSource"​
 + destroy-method="​close">​
 + <​property name="​driverClassName"​ value="​${jdbc.driverClassName}"​ />
 + <​property name="​url"​ value="​${jdbc.url}"​ />
 + <​property name="​username"​ value="​${jdbc.username}"​ />
 + <​property name="​password"​ value="​${jdbc.password}"​ />
 + </​bean>​
 +
 + <!-- 使用JDBC事务 -->
 + <bean id="​transactionManager"​
 + class="​org.springframework.jdbc.datasource.DataSourceTransactionManager">​
 + <​property name="​dataSource"​ ref="​dataSource"​ />
 + </​bean>​
 +
 + <!-- AOP配置事物 -->
 + <​tx:​advice id="​transactionAdvice"​ transaction-manager="​transactionManager">​
 + <​tx:​attributes>​
 + <​tx:​method name="​query*"​ read-only="​true"​ propagation="​REQUIRED"​ />
 + <​tx:​method name="​delete*" ​ propagation="​REQUIRED"​ />
 + <​tx:​method name="​update*"​ propagation="​REQUIRED"​ />
 + <​tx:​method name="​insert*"​ propagation="​REQUIRED"​ />
 + <​tx:​method name="​*"​ propagation="​REQUIRED"​ />
 + </​tx:​attributes>​
 + </​tx:​advice>​
 +
 + <!-- 配置AOP切面 -->
 + <​aop:​config>​
 +        <​aop:​pointcut id="​transactionPointcut"​ expression="​execution(* com.gxx.record.service.*.*(..))"/>​
 +        <​aop:​advisor pointcut-ref="​transactionPointcut"​ advice-ref="​transactionAdvice"/>​
 +    </​aop:​config>​
 +
 +
 + <!-- 使用annotation注解方式配置事务 -->
 + <​tx:​annotation-driven transaction-manager="​transactionManager"​ />
 +
 + <bean id="​sqlSessionFactory"​ class="​org.mybatis.spring.SqlSessionFactoryBean">​
 + <​property name="​dataSource"​ ref="​dataSource"​ />
 + <​property name="​configLocation"​ value="​classpath:​mybatis.xml"></​property>​
 + <​property name="​mapperLocations"​ value="​classpath:​com/​gxx/​record/​base/​mapping/​*.xml"></​property>​
 + </​bean>​
 +
 + <!-- 配置SQLSession模板 -->
 + <bean id="​sqlSession"​ class="​org.mybatis.spring.SqlSessionTemplate">​
 + <​constructor-arg index="​0"​ ref="​sqlSessionFactory"​ />
 + </​bean>​
 +
 + <​!--扫描basePackage下所有以@Repository注解的接口 ​ -->
 + <bean class="​org.mybatis.spring.mapper.MapperScannerConfigurer">​
 +        <​property name="​sqlSessionFactoryBeanName"​ value="​sqlSessionFactory"​ />
 +        <​property name="​basePackage"​ value="​com.gxx.record"/>​
 +        <​property name="​annotationClass"​ value="​org.springframework.stereotype.Repository"/>​
 +    </​bean>​
 +</​beans>​
 +</​file>​
 +==== jdbc.properties ====
 +<file properties jdbc.properties>​
 +jdbc.driverClassName=com.mysql.jdbc.Driver
 +jdbc.url=jdbc:​mysql://​127.0.0.1:​3306/​record?​useUnicode=true&​characterEncoding=UTF-8&​useOldAlias
 +jdbc.username=root
 +jdbc.password=root
 +</​file>​
 +==== log4j.properties ====
 +<file properties log4j.properties>​
 +# Output pattern : date [thread] priority category - message ​  FATAL 0  ERROR 3  WARN 4  INFO 6  DEBUG 7 
 +log4j.rootLogger=INFO,​ Console, RollingFile
 +
 +#Console
 +log4j.appender.Console=org.apache.log4j.ConsoleAppender
 +log4j.appender.Console.layout=org.apache.log4j.PatternLayout
 +log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
 +
 +#​RollingFile
 +log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
 +log4j.appender.RollingFile.File=D:/​logs/​record.log
 +log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
 +log4j.appender.RollingFile.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
 +</​file>​
 +==== mybatis.xml ====
 +<file xml mybatis.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>​
 + <​settings>​
 + <​setting name="​cacheEnabled"​ value="​true"​ />
 + <​setting name="​lazyLoadingEnabled"​ value="​true"​ />
 + <​setting name="​multipleResultSetsEnabled"​ value="​true"​ />
 + <​setting name="​useColumnLabel"​ value="​true"​ />
 + <​setting name="​defaultExecutorType"​ value="​REUSE"​ />
 + <​setting name="​defaultStatementTimeout"​ value="​25000"​ />
 + </​settings>​
 +</​configuration>​
 +</​file>​
 +==== spring-mvc.xml ====
 +<file xml spring-mvc.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"​
 + xmlns:​p="​http://​www.springframework.org/​schema/​p"​
 + xmlns:​mvc="​http://​www.springframework.org/​schema/​mvc"​
 + xmlns:​util="​http://​www.springframework.org/​schema/​util"​
 + xmlns:​cache="​http://​www.springframework.org/​schema/​cache"​
 + xsi:​schemaLocation="​http://​www.springframework.org/​schema/​beans http://​www.springframework.org/​schema/​beans/​spring-beans-4.0.xsd
 + http://​www.springframework.org/​schema/​util http://​www.springframework.org/​schema/​util/​spring-util-4.0.xsd
 +                http://​www.springframework.org/​schema/​context http://​www.springframework.org/​schema/​context/​spring-context-4.0.xsd
 +                http://​www.springframework.org/​schema/​cache http://​www.springframework.org/​schema/​cache/​spring-cache-4.0.xsd
 +                http://​www.springframework.org/​schema/​mvc http://​www.springframework.org/​schema/​mvc/​spring-mvc-4.0.xsd">​
 +
 + <!-- XML转码器 -->
 + <bean id="​fmXmlEscape"​ class="​freemarker.template.utility.XmlEscape"​ />
 +
 + <!-- 配置freeMarker的模板路径 -->
 + <bean id="​freemarkerConfig"​ class="​org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">​
 + <​property name="​templateLoaderPath"​ value="/​WEB-INF/​ftl/"​ />
 + <​property name="​freemarkerVariables">​
 + <​map>​
 + <​entry key="​xml_escape"​ value-ref="​fmXmlEscape"​ />
 + </​map>​
 + </​property>​
 + <​property name="​freemarkerSettings">​
 + <​props>​
 + <!-- <prop key="​datetime_format">​MM/​dd/​yyyy</​prop>​ <prop key="​number_format">​0.######</​prop>​ -->
 + <​prop key="​defaultEncoding">​UTF-8</​prop>​
 + <!-- <prop key="​template_update_delay">​0</​prop>​ -->
 + <​prop key="​template_exception_handler">​ignore</​prop>​
 + <​prop key="​number_format">​0.##</​prop>​
 + </​props>​
 + </​property>​
 + </​bean>​
 +
 + <!-- 配置freeMarker视图解析器 -->
 + <bean id="​freeMarkerViewResolver"​ class="​org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">​
 + <​property name="​viewClass"​ value="​org.springframework.web.servlet.view.freemarker.FreeMarkerView"​ />
 + <​property name="​contentType"​ value="​text/​html;​charset=UTF-8"​ />
 + <​property name="​suffix"​ value="​.ftl"​ />
 + <​property name="​order"​ value="​0"/>​
 + <​property name="​prefix"​ value="/"​ />
 +
 + <​property name="​requestContextAttribute"​ value="​rc"​ />
 + <​property name="​exposeRequestAttributes"​ value="​true"​ />
 + <​property name="​exposeSpringMacroHelpers"​ value="​true"​ />
 + </​bean>​
 +
 + <!-- jsp视图解析器 -->  ​
 + <bean id="​jstlViewResolver"​ class="​org.springframework.web.servlet.view.InternalResourceViewResolver">​
 + <​property name="​viewClass"​ value="​org.springframework.web.servlet.view.JstlView"​ />
 + <​property name="​prefix"​ value="/​WEB-INF/​ftl/"​ />
 + <​property name="​suffix"​ value="​.jsp"​ />
 + <​property name="​order"​ value="​2"​ />
 + </​bean>​
 +
 + <!-- 扫描控制器类 -->
 + <​context:​component-scan base-package="​com.gxx.record"​ />
 +
 + <!-- 采用注解方式配置MVC -->
 + <​mvc:​annotation-driven content-negotiation-manager="​contentNegotiationManager">​
 +     <​mvc:​message-converters>​
 +     <bean class="​org.springframework.http.converter.StringHttpMessageConverter">​
 +                <​constructor-arg value="​UTF-8"​ />
 +            </​bean>​
 +         <bean class="​org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">​
 +             <!-- <​property name="​objectMapper"​ ref="​jackson2ObjectMapperFactoryBean"​ />  -->
 +             <​property name="​objectMapper">  ​
 +                    <bean class="​com.fasterxml.jackson.databind.ObjectMapper">  ​
 +                        <​property name="​dateFormat">  ​
 +                            <bean class="​java.text.SimpleDateFormat">  ​
 +                                <​constructor-arg type="​java.lang.String"​ value="​yyyy-MM-dd HH:​mm:​ss"​ />  ​
 +                            </​bean>  ​
 +                        </​property>  ​
 +                    </​bean>  ​
 +                </​property>​
 +             <​property name="​supportedMediaTypes">  ​
 +                    <​list>  ​
 +                     <​value>​text/​plain;​charset=utf-8</​value>​
 +                     <​value>​html/​text;​charset=utf-8</​value>​
 +                 <​value>​text/​html;​charset=utf-8</​value>​
 +                 <​value>​text/​json;​charset=utf-8</​value>​
 +                 <​value>​application/​json;​charset=utf-8</​value>​
 +                    </​list>  ​
 +                 </​property> ​
 +         </​bean> ​    
 +     </​mvc:​message-converters>​
 + </​mvc:​annotation-driven>​
 +
 + <!-- Supporty medieType Content Manager Config-->​
 + <bean id="​contentNegotiationManager"​ class="​org.springframework.web.accept.ContentNegotiationManagerFactoryBean">​
 +     <​property name="​favorPathExtension"​ value="​false"​ />
 +     <​property name="​favorParameter"​ value="​true"​ />
 +     <​property name="​mediaTypes">​
 +         <​value>​
 +             atom=application/​atom+xml
 +             html=text/​html
 +             json=application/​json
 +             xml=application/​xml
 +             *=*/*
 +         </​value>​
 +     </​property>​
 + </​bean>​
 +</​beans>​
 +</​file>​
 +==== MybatisGeneratorMain.java ====
 +<file java MybatisGeneratorMain.java>​
 +package com.gxx.record.generator;​
 +
 +import java.io.File;​
 +import java.io.IOException;​
 +import java.sql.SQLException;​
 +import java.util.ArrayList;​
 +import java.util.List;​
 +
 +import org.mybatis.generator.api.MyBatisGenerator;​
 +import org.mybatis.generator.config.Configuration;​
 +import org.mybatis.generator.config.xml.ConfigurationParser;​
 +import org.mybatis.generator.exception.InvalidConfigurationException;​
 +import org.mybatis.generator.exception.XMLParserException;​
 +import org.mybatis.generator.internal.DefaultShellCallback;​
 +
 +/**
 + * <dl>
 + ​* ​   <​dt><​b>​Title:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   mybatis-generator逆向框架代码生成工具
 + ​* ​   </dd>
 + ​* ​   <​dt><​b>​Description:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   <​p>​none
 + ​* ​   </dd>
 + * </dl>
 + *
 + * @author Administrator
 + * @version 1.0, 2015年6月18日
 + * @since record
 + *
 + */
 +public class MybatisGeneratorMain {
 + /**
 + * main方法
 + * @param args
 + */
 +    public static void main(String[] args) {
 +        List<​String>​ warnings = new ArrayList<​String>​();​
 +        boolean overwrite = true;
 +        String genCfg = "/​generatorConfig.xml";​
 +        File configFile = new File(MybatisGeneratorMain.class.getResource(genCfg).getFile());​
 +        ConfigurationParser cp = new ConfigurationParser(warnings);​
 +        Configuration config = null;
 +        try {
 +            config = cp.parseConfiguration(configFile);​
 +        } catch (IOException e) {
 +            e.printStackTrace();​
 +        } catch (XMLParserException e) {
 +            e.printStackTrace();​
 +        }
 +        DefaultShellCallback callback = new DefaultShellCallback(overwrite);​
 +        MyBatisGenerator myBatisGenerator = null;
 +        try {
 +            myBatisGenerator = new MyBatisGenerator(config,​ callback, warnings);
 +        } catch (InvalidConfigurationException e) {
 +            e.printStackTrace();​
 +        }
 +        try {
 +            myBatisGenerator.generate(null);​
 +        } catch (SQLException e) {
 +            e.printStackTrace();​
 +        } catch (IOException e) {
 +            e.printStackTrace();​
 +        } catch (InterruptedException e) {
 +            e.printStackTrace();​
 +        }
 +    }
 +}
 +</​file>​
 +==== generatorConfig.xml ====
 +<file xml generatorConfig.xml>​
 +<?xml version="​1.0"​ encoding="​UTF-8"?>​
 +<​!DOCTYPE generatorConfiguration
 +  PUBLIC "​-//​mybatis.org//​DTD MyBatis Generator Configuration 1.0//​EN"​
 +  "​http://​mybatis.org/​dtd/​mybatis-generator-config_1_0.dtd">​
 +
 +<​generatorConfiguration>​
 +  ​
 +  <!-- 配置mysql 驱动jar包路径.用了绝对路径 -->
 +  <​classPathEntry location="​C:/​Users/​Administrator/​.m2/​repository/​mysql/​mysql-connector-java/​5.1.9/​mysql-connector-java-5.1.9.jar"​ />
 +
 +  <context id="​DB2Tables"​ targetRuntime="​MyBatis3">​
 +  ​
 +    <!-- 为了防止生成的代码中有很多注释,比较难看,加入下面的配置控制 -->
 +    <​commentGenerator>​
 +      <​property name="​suppressAllComments"​ value="​true"​ />
 +      <​property name="​suppressDate"​ value="​true"​ />
 +    </​commentGenerator>​
 +    <!-- 注释控制完毕 -->
 +  ​
 +    <!-- 数据库连接 -->
 +    <​jdbcConnection driverClass="​com.mysql.jdbc.Driver"​
 +        connectionURL="​jdbc:​mysql://​127.0.0.1:​3306/​record?​characterEncoding=utf8"​
 +        userId="​root"​
 +        password="​root">​
 +    </​jdbcConnection>​
 +
 +    <​javaTypeResolver >
 +      <​property name="​forceBigDecimals"​ value="​false"​ />
 +    </​javaTypeResolver>​
 +    ​
 +    <!-- 数据表对应的model 层  -->
 +    <​javaModelGenerator targetPackage="​com.gxx.record.base.vo"​ targetProject="​D:/​05.HeadWorkspace/​record/​src/​main/​java">​
 +      <​property name="​enableSubPackages"​ value="​true"​ />
 +      <​property name="​trimStrings"​ value="​true"​ />
 +    </​javaModelGenerator>​
 +    ​
 +    <!-- sql mapper 隐射配置文件 -->
 +    <​sqlMapGenerator targetPackage="​com.gxx.record.base.mapping" ​ targetProject="​D:/​05.HeadWorkspace/​record/​src/​main/​java">​
 +      <​property name="​enableSubPackages"​ value="​true"​ />
 +    </​sqlMapGenerator>​
 +    ​
 +    <!-- 在ibatis2 中是dao层,但在mybatis3中,其实就是mapper接口 -->
 +    <​javaClientGenerator type="​XMLMAPPER"​ targetPackage="​com.gxx.record.base.dao" ​ targetProject="​D:/​05.HeadWorkspace/​record/​src/​main/​java">​
 +      <​property name="​enableSubPackages"​ value="​true"​ />
 +    </​javaClientGenerator>​
 +    ​
 +    <!-- 要对那些数据表进行生成操作,必须要有一个. -->
 +    <table schema="​record"​ tableName="​user"​ domainObjectName="​User" ​
 +        enableCountByExample="​false"​ enableUpdateByExample="​false"​
 +        enableDeleteByExample="​false"​ enableSelectByExample="​false"​
 +        selectByExampleQueryId="​false"> ​    
 +    </​table>​
 +
 +  </​context>​
 +</​generatorConfiguration>​
 +</​file>​
 +==== preRegistFtl.ftl ====
 +<file ftl preRegistFtl.ftl>​
 +<​!DOCTYPE html PUBLIC "​-//​W3C//​DTD XHTML 1.0 Transitional//​EN"​ "​http://​www.w3.org/​TR/​xhtml1/​DTD/​xhtml1-transitional.dtd">​
 +<html xmlns="​http://​www.w3.org/​1999/​xhtml">​
 + <​head>​
 + <meta http-equiv="​Content-Type"​ content="​text/​html;​ charset=utf-8"​ />
 + <​title>​注册页面</​title>​
 + </​head>​
 + <​body>​
 + <form action="/​record/​user/​registFtl.htm"​ method="​post">​
 + <​table border="​1">​
 + <​tr><​td>​用户名:</​td><​td><​input type="​text"​ name="​name"/></​td></​tr>​
 + <​tr><​td>​密码:</​td><​td><​input type="​password"​ name="​password"/></​td></​tr>​
 + <​tr><​td colspan="​2"​ align="​center"><​input type="​submit"​ value="​提交"/></​td></​tr>​
 + </​table>​
 + </​form>​
 + </​body>​
 +</​html>​
 +</​file>​
 +==== preRegistJsp.jsp ====
 +<file jsp preRegistJsp.jsp>​
 +<%@ page language="​java"​ contentType="​text/​html;​ charset=UTF-8"​
 +    pageEncoding="​UTF-8"​%>​
 +<​!DOCTYPE html PUBLIC "​-//​W3C//​DTD XHTML 1.0 Transitional//​EN"​ "​http://​www.w3.org/​TR/​xhtml1/​DTD/​xhtml1-transitional.dtd">​
 +<html xmlns="​http://​www.w3.org/​1999/​xhtml">​
 + <​head>​
 + <meta http-equiv="​Content-Type"​ content="​text/​html;​ charset=utf-8"​ />
 + <​title>​注册页面</​title>​
 + </​head>​
 + <​body>​
 + <form action="/​record/​user/​registJsp.htm"​ method="​post">​
 + <​table border="​1">​
 + <​tr><​td>​用户名:</​td><​td><​input type="​text"​ name="​name"/></​td></​tr>​
 + <​tr><​td>​密码:</​td><​td><​input type="​password"​ name="​password"/></​td></​tr>​
 + <​tr><​td colspan="​2"​ align="​center"><​input type="​submit"​ value="​提交"/></​td></​tr>​
 + </​table>​
 + </​form>​
 + </​body>​
 +</​html>​
 +</​file>​
 +==== result.ftl ====
 +<file ftl result.ftl>​
 +<​html>​
 +<​body>​
 + <​p>​This is my result:<​br>​ ${userDto.success?​string('​true','​false'​)}</​p>  ​
 + <​p>​This is my message:<​br>​ ${userDto.message}</​p>  ​
 +</​body>​
 +</​html>​
 +</​file>​
 +==== web.xml ====
 +<file xml web.xml>
 +<​!DOCTYPE web-app PUBLIC
 + "​-//​Sun Microsystems,​ Inc.//DTD Web Application 2.3//​EN"​
 + "​http://​java.sun.com/​dtd/​web-app_2_3.dtd"​ >
 +
 +<​web-app>​
 +    <​display-name>​Archetype Created Web Application</​display-name>​
 +  ​
 +    <!-- Context Configuration locations for Spring XML files -->
 +    <​context-param>​
 +        <​param-name>​contextConfigLocation</​param-name>​
 +        <​param-value>​
 +        classpath*:/​application-*.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>​
 +
 +    <!-- serlvet listeners -->
 +    <​listener>​
 +        <​listener-class>​org.springframework.web.context.ContextLoaderListener</​listener-class>​
 +    </​listener>​
 +     <​listener>​
 +        <​listener-class>​org.springframework.web.util.IntrospectorCleanupListener</​listener-class>​
 +    </​listener>​
 +
 +    <​servlet>​
 +        <​servlet-name>​dispatcher</​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>​dispatcher</​servlet-name>​
 +        <​url-pattern>​*.htm</​url-pattern>​
 +    </​servlet-mapping>​
 +    ​
 +    <!-- welcome file list config -->
 + ​ <​welcome-file-list>​
 +  <​welcome-file>​index.jsp</​welcome-file>​
 + ​ </​welcome-file-list>​
 +    ​
 +    <​jsp-config>​
 + <​jsp-property-group>​
 + <​display-name>​JSPConfiguration</​display-name>​
 + <​url-pattern>​*.jsp</​url-pattern>​
 + <​page-encoding>​UTF-8</​page-encoding>​
 + </​jsp-property-group>​
 + </​jsp-config>​
 +</​web-app>​
 +</​file>​
 +==== index.jsp ====
 +<file jsp index.jsp>​
 +<​html>​
 +<​body>​
 +<​h2>​Hello World!</​h2>​
 +</​body>​
 +</​html>​
 +</​file>​
 +==== pom.xml ====
 +<file xml pom.xml>
 +<?xml version="​1.0"​ encoding="​UTF-8"?>​
 +<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.gxx</​groupId>​
 + <​artifactId>​record</​artifactId>​
 + <​packaging>​war</​packaging>​
 + <​version>​0.0.1-SNAPSHOT</​version>​
 + <​name>​record Maven Webapp</​name>​
 + <​url>​http://​maven.apache.org</​url>​
 +
 + <!-- 项目属性 -->
 + <​properties>​
 + <!-- jar 版本设置 -->
 + <​spring.version>​4.0.5.RELEASE</​spring.version>​
 + <​aspectjrt.version>​1.6.9</​aspectjrt.version>​
 + <​aspectjweaver.version>​1.6.1</​aspectjweaver.version>​
 + <​freemarker.version>​2.3.20</​freemarker.version>​
 + <​mybatis.version>​3.2.7</​mybatis.version>​
 + <​mybatis-spring.version>​1.2.2</​mybatis-spring.version>​
 + <​mybatis-generator-core.version>​1.3.2</​mybatis-generator-core.version>​
 + <​servlet-api.version>​2.4</​servlet-api.version>​
 + <​jsp-api.version>​2.0</​jsp-api.version>​
 + <​jstl.version>​1.2</​jstl.version>​
 + <​standard.version>​1.1.2</​standard.version>​
 + <​jackson-databind.version>​2.4.0</​jackson-databind.version>​
 + <​jackson-annotations.version>​2.4.0</​jackson-annotations.version>​
 + <​jackson-module-jaxb-annotations.version>​2.4.0</​jackson-module-jaxb-annotations.version>​
 + <​jackson-core.version>​2.4.0</​jackson-core.version>​
 + <​junit.version>​4.11</​junit.version>​
 + <​log4j.version>​1.2.16</​log4j.version>​
 + <​mysql-connector-java.version>​5.1.9</​mysql-connector-java.version>​
 + <​commons-dbcp.version>​1.4</​commons-dbcp.version>​
 + </​properties>​
 +
 + <!-- scm软件配置管理 -->
 + <​scm>​
 + <​connection>​scm:​svn:​svn://​121.43.104.34/​gxx/​trunk/​record</​connection>​
 + <​developerConnection>​scm:​svn:​svn://​121.43.104.34/​gxx/​trunk/​record</​developerConnection>​
 + </​scm>​
 +
 + <​dependencies>​
 + <!-- 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-context-support</​artifactId>​
 + <​version>​${spring.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​org.springframework</​groupId>​
 + <​artifactId>​spring-aop</​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-web</​artifactId>​
 + <​version>​${spring.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​org.springframework</​groupId>​
 + <​artifactId>​spring-webmvc</​artifactId>​
 + <​version>​${spring.version}</​version>​
 + </​dependency>​
 +
 + <!-- aspectj -->
 + <​dependency>​
 + <​groupId>​org.aspectj</​groupId>​
 + <​artifactId>​aspectjrt</​artifactId>​
 + <​version>​${aspectjrt.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​org.aspectj</​groupId>​
 + <​artifactId>​aspectjweaver</​artifactId>​
 + <​version>​${aspectjweaver.version}</​version>​
 + </​dependency>​
 +
 + <!-- freemarker -->
 + <​dependency>​
 + <​groupId>​org.freemarker</​groupId>​
 + <​artifactId>​freemarker</​artifactId>​
 + <​version>​${freemarker.version}</​version>​
 + </​dependency>​
 +
 + <!-- mybatis -->
 + <​dependency>​
 + <​groupId>​org.mybatis</​groupId>​
 + <​artifactId>​mybatis</​artifactId>​
 + <​version>​${mybatis.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​org.mybatis</​groupId>​
 + <​artifactId>​mybatis-spring</​artifactId>​
 + <​version>​${mybatis-spring.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​org.mybatis.generator</​groupId>​
 + <​artifactId>​mybatis-generator-core</​artifactId>​
 + <​version>​${mybatis-generator-core.version}</​version>​
 + </​dependency>​
 +
 + <!-- j2ee基础 -->
 + <​dependency>​
 + <​groupId>​javax.servlet</​groupId>​
 + <​artifactId>​servlet-api</​artifactId>​
 + <​version>​${servlet-api.version}</​version>​
 + <​scope>​provided</​scope>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​javax.servlet.jsp</​groupId>​
 + <​artifactId>​jsp-api</​artifactId>​
 + <​version>​${jsp-api.version}</​version>​
 + <​scope>​provided</​scope>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​javax.servlet</​groupId>​
 + <​artifactId>​jstl</​artifactId>​
 + <​version>​${jstl.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​taglibs</​groupId>​
 + <​artifactId>​standard</​artifactId>​
 + <​version>​${standard.version}</​version>​
 + </​dependency>​
 +
 + <!-- jackson -->
 + <​dependency>​
 + <​groupId>​com.fasterxml.jackson.core</​groupId>​
 + <​artifactId>​jackson-databind</​artifactId>​
 + <​version>​${jackson-databind.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​com.fasterxml.jackson.core</​groupId>​
 + <​artifactId>​jackson-annotations</​artifactId>​
 + <​version>​${jackson-annotations.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​com.fasterxml.jackson.module</​groupId>​
 + <​artifactId>​jackson-module-jaxb-annotations</​artifactId>​
 + <​version>​${jackson-module-jaxb-annotations.version}</​version>​
 + </​dependency>​
 + <​dependency>​
 + <​groupId>​com.fasterxml.jackson.core</​groupId>​
 + <​artifactId>​jackson-core</​artifactId>​
 + <​version>​${jackson-core.version}</​version>​
 + </​dependency>​
 +
 + <!-- log4j -->
 + <​dependency>​
 + <​groupId>​log4j</​groupId>​
 + <​artifactId>​log4j</​artifactId>​
 + <​version>​${log4j.version}</​version>​
 + </​dependency>​
 +
 + <!-- junit -->
 + <​dependency>​
 + <​groupId>​junit</​groupId>​
 + <​artifactId>​junit</​artifactId>​
 + <​scope>​test</​scope>​
 + <​version>​${junit.version}</​version>​
 + </​dependency>​
 +
 + <!-- mysql -->
 + <​dependency>​
 + <​groupId>​mysql</​groupId>​
 + <​artifactId>​mysql-connector-java</​artifactId>​
 + <​version>​${mysql-connector-java.version}</​version>​
 + </​dependency>​
 +
 + <!-- dbcp -->
 + <​dependency>​
 + <​groupId>​commons-dbcp</​groupId>​
 + <​artifactId>​commons-dbcp</​artifactId>​
 + <​version>​${commons-dbcp.version}</​version>​
 + </​dependency>​
 + </​dependencies>​
 +
 + <!-- 设定除中央仓repo1.maven.org/​maven2/​)外的其他仓库,​按设定顺序进行查 -->
 + <​repositories>​
 + <!-- nexus私服仓库 -->
 + <​repository>​
 + <​id>​nexus</​id>​
 + <​name>​Team Nexus Repository</​name>​
 + <​url>​http://​121.43.104.34:​8081/​nexus/​content/​groups/​public</​url>​
 + </​repository>​
 + <​repository>​
 + <​id>​offical</​id>​
 + <​name>​Maven Official Repository</​name>​
 + <​url>​http://​repo1.maven.org/​maven2</​url>​
 + <​snapshots>​
 + <​enabled>​false</​enabled>​
 + </​snapshots>​
 + </​repository>​
 + <​repository>​
 + <​id>​spring-milestone</​id>​
 + <​name>​Spring Maven MILESTONE Repository</​name>​
 + <​url>​http://​maven.springframework.org/​milestone</​url>​
 + </​repository>​
 + <​repository>​
 + <​id>​jboss</​id>​
 + <​name>​Jboss Repository</​name>​
 + <​url>​http://​repository.jboss.org/​nexus/​content/​groups/​public-jboss/</​url>​
 + <​snapshots>​
 + <​enabled>​false</​enabled>​
 + </​snapshots>​
 + </​repository>​
 + <​repository>​
 + <​id>​java.net</​id>​
 + <​name>​Java.net Repository</​name>​
 + <​url>​http://​download.java.net/​maven/​2/</​url>​
 + <​snapshots>​
 + <​enabled>​false</​enabled>​
 + </​snapshots>​
 + </​repository>​
 + <​repository>​
 + <​id>​spring-release</​id>​
 + <​name>​Spring Maven Release Repository</​name>​
 + <​url>​http://​repo.springsource.org/​libs-release</​url>​
 + <​snapshots>​
 + <​enabled>​false</​enabled>​
 + </​snapshots>​
 + </​repository>​
 + </​repositories>​
 +
 + <​build>​
 + <​finalName>​record</​finalName>​
 + <​plugins>​
 + <!-- jdk编译插件 -->
 + <​plugin>​
 + <​groupId>​org.apache.maven.plugins</​groupId>​
 + <​artifactId>​maven-compiler-plugin</​artifactId>​
 + <​version>​2.0.2</​version>​
 + <​configuration>​
 + <​source>​1.6</​source>​
 + <​target>​1.6</​target>​
 + <​encoding>​utf8</​encoding>​
 + </​configuration>​
 + </​plugin>​
 + <!-- scm软件配置管理插件 -->
 + <​plugin>​
 + <​groupId>​org.apache.maven.plugins</​groupId>​
 + <​artifactId>​maven-scm-plugin</​artifactId>​
 + <​version>​1.3</​version>​
 + </​plugin>​
 + <!-- 版本发布插件 -->
 + <​plugin>​
 + <​groupId>​org.apache.maven.plugins</​groupId>​
 + <​artifactId>​maven-release-plugin</​artifactId>​
 + <​version>​2.4</​version>​
 + <​configuration>​
 + <​tagBase>​svn://​121.43.104.34/​gxx/​tags/​record</​tagBase>​
 + <​branchBase>​svn://​121.43.104.34/​gxx/​branches/​record</​branchBase>​
 + </​configuration>​
 + </​plugin>​
 + <!-- 原型插件 -->
 + <​plugin>​
 + <​groupId>​org.apache.maven.plugins</​groupId>​
 + <​artifactId>​maven-archetype-plugin</​artifactId>​
 + <​version>​2.2</​version>​
 + </​plugin>​
 + </​plugins>​
 + </​build>​
 +
 + <!-- 版本发布管理 -->
 + <​distributionManagement>​
 + <!-- release稳定版本 -->
 + <​repository>​
 + <​id>​nexus-releases</​id>​
 + <​name>​Nexus Release Repository</​name>​
 + <​url>​http://​121.43.104.34:​8081/​nexus/​content/​repositories/​releases/</​url>​
 + </​repository>​
 + <!-- snapshots快照版本 -->
 + <​snapshotRepository>​
 + <​id>​nexus-snapshots</​id>​
 + <​name>​Nexus Snapshot Repository</​name>​
 + <​url>​http://​121.43.104.34:​8081/​nexus/​content/​repositories/​snapshots/</​url>​
 + </​snapshotRepository>​
 + </​distributionManagement>​
 +</​project>​
 +</​file>​
 +===== SQL脚本 =====
 +<code sql database.sql>​
 +create database record;
 +use record;
 +CREATE TABLE `user` (
 +  `id` int(10) unsigned NOT NULL auto_increment COMMENT '​主键',​
 +  `name` varchar(50) NOT NULL COMMENT '​姓名',​
 +  `password` varchar(32) NOT NULL COMMENT '​密码',​
 +  `create_date` varchar(8) NOT NULL COMMENT '​创建日期',​
 +  `create_time` varchar(6) NOT NULL COMMENT '​创建时间',​
 +  PRIMARY KEY  (`id`)
 +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='​用户表'​
 +</​code>​
 +===== 打包下载 =====
 +{{:​分享:​技术:​示例项目:​record.zip|}}
 +===== 使用说明 =====
 +==== 怎么在eclipse中运行项目 ====
 +  - 本地需要安装maven3
 +  - 打包下载
 +  - 导入eclipse中,自动Build Project,​第一次下载maven依赖耗时较长,请耐心等待
 +  - 修改相应配置,比如log4j.properties中的绝对路径
 +  - 开启mysql,运行上面的database.sql
 +  - 部署到eclipse绑定的tomcat中,启动tomcat
 +  - 启动成功之后,访问http://​localhost/​record/​,看到Hello World!,表示项目成功运行
 +  - 访问http://​localhost/​record/​user/​preRegistFtl.htm和http://​localhost/​record/​user/​preRegistJsp.htm进行测试
 +==== 使用mybatis-generator逆向生成框架代码 ====
 +  - 修改generatorConfig.xml中的配置
 +    - 驱动jar包路径
 +    - 数据库连接
 +    - 模型层配置
 +    - 映射配置
 +    - mapper接口配置
 +    - 需要生成的数据表配置
 +  - 运行MybatisGeneratorMain.java
 +  - 刷新目标目录中是否有新文件生成vo,​mapper,​dao
 +  - 注意:重复生成vo和dao会覆盖原文件,mapper会继续写在文件后面,所以重复生成程序运行会出错,需要手动删除再重新生成
分享/技术/示例项目/springmvc_mybatis_spring_freemarker_maven.1436228601.txt.gz · 最后更改: 2015/07/07 08:23 由 gxx