maven搭建ssm初级框架
喜欢的朋友可以关注下,粉丝也缺。
前言:
想必大家对smm框架已经熟悉的不能再熟悉了,它是由Spring、SpringMVC、MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架。我们在一般的项目都能用到它,自己搭建一个smm也挺方便的。下面我就给大家介绍一下如何搭建一个初级的ssm框架。
下面吧demo的下载贡献给大家,需要的可以去下载
https://download.csdn.net/download/dsn727455218/10524640
正文:
1.创建一个maven项目,这个这里我就不做介绍了,很简单的,拿eclipse举例,下载maven插件就行,已经maven本地仓库。
2.准备需要得jar包,maven仓库有可以直接引用的,没有的可以动态的下载。
3.mybatis配置文件
- <?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" 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/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd">
- <context:property-placeholder location="classpath:remote/db.properties"
- ignore-unresolvable="true" />
- <!-- 配置数据源 使用的是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="driverClassName" value="${jdbc.driver}" />
- <!-- 初始化连接大小 -->
- <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="configLocation" value="classpath:spring/myBatis-config.xml" />
- <property name="mapperLocations" value="classpath:com/demo/mapper/*.xml" />
- <!-- 配置PageHelper拦截实现分页 -->
- <!-- <property name="plugins"> -->
- <!-- <array> -->
- <!-- <bean id="sqlInterceptor" class="com.shou6.filter.SqlInterceptor"> -->
- <!-- 拦截的sql语句 -->
- <!-- <property name="sql_Intercept" value="^\s*select[\s\S]*$" /> -->
- <!-- 不拦截的sql语句 ^\s*select\s+count\s*\\(\s*(?:\*|\w+)\s*\)\s+[\s\S]+$ -->
- <!-- <property name="sql_Not_Intercept" value="^\s*select\s+[\s\S]+\S+_enable=1\s+[\s\S]+$" /> -->
- <!-- </bean> -->
- <!-- <bean class="com.github.pagehelper.PageHelper"> -->
- <!-- <property name="properties"> -->
- <!-- <value> -->
- <!-- dialect=mysql -->
- <!-- 该参数默认为false,设置为true时,会将RowBounds第一个参数offset当成pageNum页码使用,和startPage中的pageNum效果一样 -->
- <!-- offsetAsPageNum=true -->
- <!-- 该参数默认为false,设置为true时,使用RowBounds分页会进行count查询 -->
- <!-- rowBoundsWithCount=true -->
- <!-- 设置为true时,如果pageSize=0或者RowBounds.limit = 0就会查询出全部的结果(相当于没有执行分页查询,但是返回结果仍然是Page类型) -->
- <!-- <property name="pageSizeZero" value="true"/> -->
- <!-- 3.3.0版本可用 - 分页参数合理化,默认false禁用 -->
- <!-- 启用合理化时,如果pageNum<1会查询第一页,如果pageNum>pages会查询最后一页 -->
- <!-- 禁用合理化时,如果pageNum<1或pageNum>pages会返回空数据 -->
- <!-- PageHelper.startPage(currentPage, pageSize, true)//第三个参数为true时,该设置的“pageNum>pages会查询最后一页”才生效 -->
- <!-- reasonable=false -->
- <!-- 3.5.0版本可用 - 为了支持startPage(Object params)方法 -->
- <!-- 增加了一个`params`参数来配置参数映射,用于从Map或ServletRequest中取值 -->
- <!-- 可以配置pageNum,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值 -->
- <!-- 不理解该含义的前提下,不要随便复制该配置 <property name="params" value="pageNum=start;pageSize=limit;"/> -->
- <!-- </value> -->
- <!-- </property> -->
- <!-- </bean> -->
- <!-- </array> -->
- <!-- </property> -->
- </bean>
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.demo.dao" />
- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
- </bean>
- </beans>
4.myBatis-config:自动扫描实体类
- <?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>
- <!-- 通过别名简化对类的使用 -->
- <typeAliases>
- <!-- 通过package, 可以直接指定package的名字, mybatis会自动扫描你指定包下面的javabean, 并且默认设置一个别名,默认的名字为非限定类名来作为它的别名。 -->
- <package name="com.demo.entity" />
- </typeAliases>
- </configuration>
5.application-trans:事务管理
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
- 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/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util.xsd">
- <!-- 配置事务管理器 -->
- <bean id="transactionManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <!-- 拦截器方式配置事物 -->
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
- <!-- 传播行为 -->
- <tx:method name="get*" propagation="REQUIRED" read-only="true" />
- <tx:method name="*" propagation="REQUIRED" rollback-for="Exception" />
- </tx:attributes>
- </tx:advice>
- <!-- 方式1:注解方式配置事物管理 -->
- <!-- <tx:annotation-driven transaction-manager="txAdvice" /> -->
- <!-- 方式2:Spring Aop配置事务管理 expose-proxy="true":解决非事务方法调用本类事务方法时事务不起作用 -->
- <aop:config expose-proxy="true">
- <aop:pointcut id="txPoint" expression="execution(* com.demo.service.impl.*.*(..))" />
- <aop:advisor pointcut-ref="txPoint" advice-ref="txAdvice" />
- </aop:config>
- </beans>
5.application:核心配置文件
- <?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:aop="http://www.springframework.org/schema/aop"
- 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/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd">
- <!-- xsi:schemaLocation尽量不配版本号,这样会默认从本地加载xsd文件,断网不会导致加载出错 -->
- <!--引入配置属性文件,使用@Value获取值 -->
- <!-- <bean id="props" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> -->
- <!-- <property name="locations"> -->
- <!-- <list> -->
- <!-- <value>classpath:nofilter.properties</value> -->
- <!-- <value>classpath:config/param-injection.properties</value> -->
- <!-- </list> -->
- <!-- </property> -->
- <!-- <property name="fileEncoding" value="UTF-8"/> -->
- <!-- </bean> -->
- <!-- <import resource="application-quartz.xml"/> -->
- <import resource="application-mybatis.xml"/>
- <!-- <import resource="application-redis.xml"/> -->
- <!--自动扫描含有@Service将其注入为bean -->
- <context:component-scan base-package="com.demo.service" />
- <import resource="application-trans.xml"/>
- <!-- 用于持有ApplicationContext,可以使用BeanMgrUtil.getBean('xxxx')的静态方法得到spring bean对象 -->
- <!-- <bean class="com.shou6.utils.tools.BeanMgrUtil" lazy-init="false" /> -->
- </beans>
6.spring-mvc:核心配置文件
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:mvc="http://www.springframework.org/schema/mvc" 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"
- xmlns:aop="http://www.springframework.org/schema/aop"
- 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
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd">
- <!-- spring全局异常捕获 -->
- <!-- <bean class="com.shou6.utils.exception.ExceptionHandler" /> -->
- <!-- AOP拦截controller注意:需要把切面类和controller 放在同一个spring的xml配置文件中 -->
- <context:component-scan base-package="com.demo.controller"/>
- <!-- <context:component-scan base-package="com.shou6.filter"/> -->
- <!-- 对@AspectJ切面的bean创建代理(不设置则@Aspect注解的切面将无效) -->
- <aop:aspectj-autoproxy proxy-target-class="true" />
- <!-- Jackson转换器 -->
- <bean id="mappingJacksonHttpMessageConverter"
- class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
- <property name="supportedMediaTypes">
- <list>
- <value>application/json;charset=UTF-8</value>
- <value>text/html;charset=UTF-8</value><!-- 避免IE出现下载JSON文件的情况 -->
- </list>
- </property>
- </bean>
- <!-- String转换器(为配合APP支付异步通知) -->
- <bean id="stringHttpMessageConverter"
- class="org.springframework.http.converter.StringHttpMessageConverter">
- <constructor-arg value="UTF-8" index="0"></constructor-arg><!--避免出现乱码 -->
- <property name="supportedMediaTypes">
- <list>
- <value>text/plain;charset=UTF-8</value>
- <value>text/xml;charset=UTF-8</value>
- </list>
- </property>
- </bean>
- <!-- 启动Spring MVC的注解功能,完成请求和返回的POJO-json/xml自动转换 -->
- <bean
- class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
- <property name="messageConverters">
- <list>
- <!-- json转换器 -->
- <ref bean="mappingJacksonHttpMessageConverter" />
- <ref bean="stringHttpMessageConverter" />
- </list>
- </property>
- </bean>
- <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
- <bean
- class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="viewClass"
- value="org.springframework.web.servlet.view.JstlView" />
- <!-- 解决默认返回均是application/json格式问题 -->
- <property name="contentType" value="text/html;charset=UTF-8" />
- <property name="prefix" value="/" />
- <property name="suffix" value=".jsp" />
- </bean>
- <!-- 配置多文件上传 -->
- <bean id="multipartResolver"
- class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
- <property name="defaultEncoding">
- <value>UTF-8</value>
- </property>
- <property name="maxUploadSize">
- <!-- 上传文件大小限制为5M,5120*1000b -->
- <value>5120000</value>
- </property>
- <property name="maxInMemorySize">
- <value>4096</value>
- </property>
- </bean>
- </beans>
7.log4j:日志配置文件
- # Rules reminder:
- # DEBUG < INFO < WARN < ERROR < FATAL
- # Global logging configuration
- log4j.rootLogger=debug,stdout
- # My logging configuration...
- log4j.logger.cn.jbit.mybatisdemo=DEBUG
- ## Console output...
- log4j.appender.stdout=org.apache.log4j.ConsoleAppender
- log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
- log4j.appender.stdout.layout.ConversionPattern=%5p %d %C: %m%n
- log4j.logger.org.apache.ibatis=DEBUG
- ## log4j.logger.org.apache.jdbc.SimpleDataSource=DEBUG
- log4j.logger.org.apache.ibatis.jdbc.ScriptRunner=DEBUG
- ## log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapclientDelegate=DEBUG
- log4j.logger.java.sql.Connection=DEBUG
- log4j.logger.java.sql.Statement=DEBUG
- log4j.logger.java.sql.PreparedStatement=DEBUG
- #base log config
- log4j.rootLogger=INFO,CONSOLE,INFO_FILE,ERROR_FILE
- log4j.addivity.org.apache=true
- #console config
- log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
- log4j.appender.CONSOLE.Threshold=INFO
- log4j.appender.CONSOLE.Target=System.out
- log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
- log4j.appender.CONSOLE.layout.ConversionPattern=[%d{HH\:mm\:ss ms}]-%5p (%F\:%L)\:%m%n
- # information logs config
- log4j.appender.INFO_FILE=org.apache.log4j.DailyRollingFileAppender
- log4j.appender.INFO_FILE.File=..\\logs\\OSS-INFO.log
- log4j.appender.INFO_FILE.Threshold=INFO
- log4j.appender.INFO_FILE.Append=true
- log4j.appender.INFO_FILE.layout=org.apache.log4j.PatternLayout
- log4j.appender.INFO_FILE.layout.ConversionPattern=[%d{HH\:mm\:ss ms}]-[%p]\:%m ->%l %n
- # error logs config
- log4j.appender.ERROR_FILE=org.apache.log4j.DailyRollingFileAppender
- log4j.appender.ERROR_FILE.File=..\\logs\\OSS-ERROR.log
- log4j.appender.ERROR_FILE.Threshold=ERROR
- log4j.appender.ERROR_FILE.Append=true
- log4j.appender.ERROR_FILE.layout=org.apache.log4j.PatternLayout
- log4j.appender.ERROR_FILE.layout.ConversionPattern=[%d{HH\:mm\:ss ms}]-[%p]\:%m ->%l %n
- # fail bill logs config
- log4j.logger.FAIL_BILL=INFO, FAIL_BILL
- log4j.appender.FAIL_BILL=org.apache.log4j.DailyRollingFileAppender
- log4j.appender.FAIL_BILL.File=..\\logs\\FAIL_BILL.log
- log4j.appender.FAIL_BILL.Threshold=FAIL_BILL
- log4j.appender.FAIL_BILL.Append=true
- log4j.appender.FAIL_BILL.layout=org.apache.log4j.PatternLayout
- log4j.appender.FAIL_BILL.layout.ConversionPattern=[%d{HH\:mm\:ss ms}]\:%m %n
8.web:项目启动加载spring配置
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
- <display-name>MyDemo</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:spring/application.xml</param-value>
- </context-param>
- <!-- 监听spring -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- 启动系统服务 -->
- <!-- <listener> -->
- <!-- <listener-class>com.shou6.init.ServerInitHandler</listener-class> -->
- <!-- </listener> -->
- <!-- 防止内存泄漏 -->
- <listener>
- <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
- </listener>
- <!-- 编码过滤 -->
- <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>
- <!-- spring mvc -->
- <servlet>
- <description>spring mvc servlet</description>
- <servlet-name>mvcServlet</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- classpath:spring/spring-mvc.xml
- </param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>mvcServlet</servlet-name>
- <url-pattern>*.do</url-pattern>
- <url-pattern>*.mdo</url-pattern>
- </servlet-mapping>
- </web-app>
所需要的配置文件就这么多,当然你需要redis,quartz也可以加入配置。
下面我就来测试一下
在项目中我创建BaseMapper作为一个父类接口,只需要继承就可以调用其方法,是为了方便重复创建方法;BaseService也是同样的道理。
首先我们创建一个实体类User:
- /**
- * @author dsn
- *
- * @version 创建时间:2018年7月5日 上午11:30:00
- */
- package com.demo.entity;
- /**
- * @author dsn
- * @version 创建时间:2018年7月5日 上午11:30:00
- */
- public class User {
- /**
- * @return the id
- */
- public int getId() {
- return id;
- }
- /**
- * @param id
- * the id to set
- */
- public void setId(int id) {
- this.id = id;
- }
- /**
- * @return the username
- */
- public String getUsername() {
- return username;
- }
- /**
- * @param username
- * the username to set
- */
- public void setUsername(String username) {
- this.username = username;
- }
- /**
- * @return the userpass
- */
- public String getUserpass() {
- return userpass;
- }
- /**
- * @param userpass
- * the userpass to set
- */
- public void setUserpass(String userpass) {
- this.userpass = userpass;
- }
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
- /**
- * @param name
- * the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
- private int id;
- private String username;
- private String userpass;
- private String name;
- }
创建一个dao层接口:继承BaseMapper引入实体类User
- /**
- * @author dsn
- *
- * @version 创建时间:2018年7月5日 上午11:35:10
- */
- package com.demo.dao;
- import com.demo.entity.User;
- /**
- * @author dsn
- * @version 创建时间:2018年7月5日 上午11:35:10
- */
- public interface UserMapper extends BaseMapper<User> {
- }
创建一个service接口:继承BaseService引入实体类User
- /**
- * @author dsn
- *
- * @version 创建时间:2018年7月5日 上午11:35:36
- */
- package com.demo.service;
- import com.demo.entity.User;
- /**
- * @author dsn
- * @version 创建时间:2018年7月5日 上午11:35:36
- */
- public interface UserService extends BaseService<User> {
- }
创建一个Mapper文件:UserMapper.xml,这里我写一个insert的语句以及一个select语句,需要注意的是column需要与实体类User字段对应以及对应的type
- <?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.demo.dao.UserMapper" >
- <resultMap id="userResultMap" type="com.demo.entity.User" >
- <id column="id" property="id" jdbcType="INTEGER" />
- <result column="name" property="name" jdbcType="VARCHAR" />
- <result column="username" property="username" jdbcType="VARCHAR" />
- <result column="userpass" property="userpass" jdbcType="VARCHAR" />
- </resultMap>
- <select id="selectList" parameterType="User" resultMap="userResultMap">
- select
- id,username,userpass,name
- from user
- <where>
- disable='1'
- <if test="key!=null">
- and (
- username = #{key,jdbcType=VARCHAR}
- or
- name = #{key,jdbcType=VARCHAR}
- )
- </if>
- </where>
- </select>
- <insert id="insert" parameterType="User"
- useGeneratedKeys="true" keyProperty="id">
- insert into user(name,username,userpass)
- values(#{name},#{username},#{userpass})
- </insert>
- </mapper>
接下来我们创建一个UserAction:这是作为controller控制器,处理所有的访问请求以及逻辑
- /**
- * @author dsn
- *
- * @version 创建时间:2018年7月5日 上午11:47:26
- */
- package com.demo.controller;
- import javax.annotation.Resource;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import com.demo.entity.User;
- import com.demo.service.UserService;
- /**
- * @author dsn
- * @version 创建时间:2018年7月5日 上午11:47:26
- */
- @Controller
- @RequestMapping("user")
- public class UserAction {
- @Resource
- private UserService userService;
- @ResponseBody
- @RequestMapping(value = "/adduser")
- public String addactivity(User user, String msg) throws Exception {
- int insert = userService.insert(user);
- if (insert == 1) {
- msg = "插入成功";
- } else {
- msg = "插入失败";
- }
- return msg;
- }
- }
启动项目,用postman测试一下,完美收官。
下面吧demo的下载贡献给大家,需要的可以去下载
https://download.csdn.net/download/dsn727455218/10524640
如有需要可以加我Q群【308742428】大家一起讨论技术。
后面会不定时为大家更新文章,敬请期待。
喜欢的朋友可以关注下,粉丝也缺。
maven搭建ssm初级框架的更多相关文章
- Maven项目搭建(二):Maven搭建SSM框架
上一章给大家讲解了如何使用Maven搭建web项目. 这次给大家介绍一下怎么使用Maven搭建SSM框架项目. 首先我们来看一下pom.xml的属性介绍: project: pom的xml根元素. p ...
- Eclipse中使用Maven搭建SSM框架
Eclipse中不使用Maven搭建SSM框架:https://www.cnblogs.com/xuyiqing/p/9569459.html IDEA中使用Maven搭建SSM框架:https:// ...
- 使用maven搭建ssm框架的javaweb项目
目前主流的javaweb项目,常会用到ssm(Spring+Spring MVC+Mybatis)框架来搭建项目的主体框架,本篇介绍搭建SSM框架的maven项目的实施流程.记之共享! 一.SSM框架 ...
- 使用maven搭建SSM框架
使用maven搭建SSM框架,首先得准备好maven环境. 搭建maven环境 第一步:下载maven http://maven.apache.org/download.cgi 下载后解压就可以了. ...
- 使用Maven搭建SSM框架(Eclipse)
今天学习一下使用Maven搭建SSM框架,以前都是用别人配置好的框架写代码,今天试试自己配置一下SSM框架. 这里我的参数是Windows7 64位,tomcat9,eclipse-jee-neon- ...
- 使用maven搭建ssm框架环境
1.前言 因为经常换环境,在搭ssm框架的时候老是出错,所以记录一下最近搭建的环境,以供参考. 本文讲解如何使用maven搭建ssm框架,并能用于简单的登录注册. IDE:IDEA,JDK版本:1.8 ...
- Maven 搭建 SSM 项目 (oracle)
简单谈一下maven搭建 ssm 项目 (使用数据库oracle,比 mysql 难,所以这里谈一下) 在创建maven 的web项目时,常常会缺了main/java , main/test 两个文件 ...
- maven搭建ssm
前言 本文旨在利用maven搭建ssm环境,而关于maven的具体内容,大家可以去阅读<Maven 实战>.其实园内这方面文章已有不少,那么为什么我还要重复造轮子呢?我只是想记录自己的实践 ...
- 【原】无脑操作:eclipse + maven搭建SSM框架
网上看到一些Spring + Spring MVC + MyBatis框架的搭建教程,不是很详细或是时间久远了,自己动手整一个简单无脑的! 0.系统环境 1)Windows 10 企业版 2)JDK ...
随机推荐
- docker 加速器配置目录
centos 7 : /lib/systemd/system/docker.service
- 01.Java 开发简单的计算器
难度为一般,适合具有 Java 基础和 Swing 组件编程知识的用户学习一. 实验介绍1.1 实验内容本次实验利用Java开发一个可以进行简单的四则运算的图形化计算器,会使用到 Java Swing ...
- 2018.11.01 NOIP训练 图论(线段树+倍增+dfs序)
传送门 一道挺妙的题. 对于询问点(u,v),如右图所示,我们可以发现存在一个点m在u->v的路径中,m子树的点到u是最近的,m子树外到v是最近的.其中dis(u,m)=(dis(u,v)-1) ...
- s5-2 Cpu调度算法
调度程序采用什么算法选择一个进程(作业)? 如何评价调度算法的性能? 调度准则 CPU利用率 – 使CPU尽可能的忙碌 吞吐量 – 单位时间内运行完的进程数 周转时间 – 进程从提交到运行结束的全部时 ...
- mysql学习之路_基础知识
Mysql php阶段将数据库分为三个阶 基础阶段: mysql数据库的基本操作(增删改查),以及一些高级操作(视图,触发器,函数,存储过程等),PHP操作没有sql数 ...
- XML xmlns
xmlns xml namespaces 参考 http://www.w3school.com.cn/tags/tag_prop_xmlns.asp http://www.w3school.com.c ...
- C#重点内容之:事件(Event)
一.事件的五个组成部分 事件的五个部分: 事件拥有者(对象) 事件成员(Event ,成员) 事件的响应者(对象) 事件处理器(成员,本质是一个回调方法) 事件订阅——把事件处理器与事件关联在一起 二 ...
- 2.2.11同步synchronized方法无限等待与解决
同步方法容易造成死循环. package com.cky.bean; /** * Created by edison on 2017/12/8. */ public class Service { s ...
- 1.7.8使用return 停止线程
package com.cky.thread; /** * Created by edison on 2017/12/3. */ public class MyThread12 extends Thr ...
- 知识点:定义input type=file 样式的方法(转)
——“当我们想要用css美化表单的时候,有两个控件就会和前段人员作对,一个是是大名鼎鼎的select,另一个就是我现在要说说的 input type=file” 为什么要美化file控件?试想一下,别 ...