struts2+spring+ibatis框架整合实现增删改查

初步学习SSI框架,做的struts2+spring+ibatis框架整合的小实例,实现增删改查操作。

项目框架如下所示:

准备工作:导入需要的struts2、spring、ibatis的jar包,这里不一一列举了。

下面直接上完整的配置文件内容和代码,不说明先后步骤了

一、配置文件

1、spring配置文件applicationContext.xml(业务逻辑层)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- 引入参数配置文件,数据库配置信息 -->
 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 <property name="locations">
 <list>
 <value>classpath*:jdbc.properties</value>
 </list>
 </property>
 </bean>

<!-- 数据源配制 -->
 <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}" />
 <property name="maxActive" value="20" />
 <property name="maxWait" value="1000" />
 <property name="testOnBorrow" value="true"/>
 <property name="testWhileIdle" value="true"/>
 <property name="validationQuery" value="select 1 from dual"/>
 <property name="poolPreparedStatements" value="true" />
 <property name="defaultAutoCommit" value="true" />
 </bean>

<!-- 注入ibatis配置文件 -->
 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
 <property name="configLocations">
 <list>
 <value>classpath*:/sqlMapConfig.xml</value>
 </list>
 </property>
 <property name="dataSource" ref="dataSource" />
 </bean>
<!-- action -->
 <bean id="userAction" class="com.user.action.userAction" scope="prototype">
 <property name="userService" ref="userSI"></property>
 </bean>

<!-- service -->
 <bean id="userSI" class="com.user.service.impl.UserServiceImpl">
 <property name="userdao" ref="userDI" />
 </bean>

<!-- dao -->
 <bean id="userDI" class="com.user.dao.impl.UserDaoImpl">
 <property name="sqlMapClient" ref="sqlMapClient" />
 </bean>

 </beans>

2、数据库参数配置文件jdbc.properties

jdbc.driverClassName=oracle.jdbc.OracleDriver
jdbc.url=jdbc:oracle:thin:@198.10.3.138:1521:fapdb
jdbc.username=fapdb
jdbc.password=fapdb

3、ibatis配置文件sqlMapConfig.xml(持久层)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
 "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
 <settings cacheModelsEnabled="true"
    enhancementEnabled="true"
    lazyLoadingEnabled="false"
    maxTransactions="32"
   maxRequests="512"
   maxSessions="128"
    useStatementNamespaces="false"/>

 <sqlMap resource="com/user/model/sqlmap/User.xml" /> 

</sqlMapConfig>

4、实体类sql配置文件User.xml(持久层)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
  PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
  "http://ibatis.apache.org/dtd/sql-map-2.dtd">
 <!-- 定义配置名 -->
<sqlMap namespace="User">
 <!-- <typeAlias alias="User" type="com.user.model.User"> </typeAlias> -->
 <resultMap id="userResultMap" class="com.user.model.User">
 <result property="userid" column="USERID" />
 <result property="username" column="USERNAME" />
 <result property="password" column="PASSWORD" />
 </resultMap>

<!-- 插入数据 -->
 <insert id="insertUser" parameterClass="com.user.model.User">
 insert into gy_user(USERID,USERNAME,PASSWORD) values(#userid#,#username#,#password#)
 </insert>
<!-- 查询数据 -->
 <select id="queryUser" parameterClass="com.user.model.User" resultClass="com.user.model.User">
 select USERID,USERNAME,PASSWORD from gy_user
 <dynamic prepend="where">
 <isNotEqual prepend="and" property="userid" compareValue="0">
 USERID=#userid#
 </isNotEqual>
 </dynamic>
 order by USERID
 </select>
<!-- 查询by id -->
 <select id="queryUserById" parameterClass="int" resultClass="com.user.model.User">
 select USERID,USERNAME,PASSWORD from gy_user where USERID=#id#
 </select>
<!-- 删除数据 -->
 <delete id="deleteUser" parameterClass="int">
 delete from gy_user where USERID=#id#
 </delete>
<!-- 更新数据 -->
 <update id="updateUser" parameterClass="com.user.model.User">
 update gy_user set USERID=#userid#,USERNAME=#username#,PASSWORD=#password# where USERID=#userid#
 </update>
</sqlMap>

5、struts参数配置文件struts.properties

### 默认编码
struts.i18n.encoding=UTF-8
### 使用spring装配工厂
struts.objectFactory = spring
struts.objectFactory.spring.autoWire = name
struts.objectFactory.spring.useClassCache = true
struts.multipart.parser=jakarta
struts.multipart.saveDir=/tmp
struts.multipart.maxSize=209715200
struts.action.extension=do
struts.serve.static=true
struts.serve.static.browserCache=true
struts.enable.DynamicMethodInvocation = true
struts.enable.SlashesInActionNames = false
struts.tag.altSyntax=true
struts.devMode = false
struts.i18n.reload=true
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
struts.configuration.xml.reload=ture
struts.ui.theme=simple
struts.velocity.configfile = velocity.properties
struts.url.http.port = 80
struts.url.https.port = 443
struts.url.includeParams = get
struts.dispatcher.parametersWorkaround = false
struts.freemarker.templatesCache=false
struts.freemarker.beanwrapperCache=false
struts.freemarker.wrapper.altMap=true
struts.xslt.nocache=false
struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml
struts.mapper.alwaysSelectFullNamespace=false

6、struts配置文件struts.xml(控制层)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 "http://struts.apache.org/dtds/struts-2.0.dtd">
 <struts>
 <span style="white-space:pre"> </span><package name="default" extends="struts-default">
 <span style="white-space:pre"> </span><!-- index_开头的action,调用action类中的*方法 -->
 <span style="white-space:pre"> </span><action name="index_*" class="userAction" method="{1}">
 <span style="white-space:pre"> </span><result name="success">/success.jsp</result>
 <span style="white-space:pre"> </span><result name="userResult">/userResult.jsp</result>
 <span style="white-space:pre"> </span><result name="successdelete">/success.jsp</result>
 <span style="white-space:pre"> </span><result name="querybyidRes">/userUpdate.jsp</result>
 <span style="white-space:pre"> </span><result name="successupdate">/success.jsp</result>
 <span style="white-space:pre"> </span></action>
 <span style="white-space:pre"> </span></package>
 </struts>

7、web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <welcome-file-list>
 <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>

 <!-- 配置Spring -->
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath*:applicationContext.xml</param-value>
 </context-param>
 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

 <!-- 配置Struts -->
 <filter>
 <filter-name>struts</filter-name>
 <filter-class>
 org.apache.struts2.dispatcher.FilterDispatcher
 </filter-class>
 </filter>
 <filter-mapping>
 <filter-name>struts</filter-name>
 <url-pattern>*.do</url-pattern>
 </filter-mapping>
 <filter-mapping>
 <filter-name>struts</filter-name>
 <url-pattern>*.action</url-pattern>
 </filter-mapping>
 <filter-mapping>
 <filter-name>struts</filter-name>
 <url-pattern>*.jsp</url-pattern>
 </filter-mapping>
</web-app>

二、model模型层

实体类User.java

package com.user.model;

public class User {
 private int userid;
 private String username;
 private String password;

 public int getUserid() {
 return userid;
 }
 public String getUsername() {
 return username;
 }
 public String getPassword() {
 return password;
 }
 public void setUserid(int userid) {
 this.userid = userid;
 }
 public void setUsername(String username) {
 this.username = username;
 }
 public void setPassword(String password) {
 this.password = password;
 }

}

三、Action控制层

userAction.java类

package com.user.action;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.user.model.User;
import com.user.service.UserService;

public class userAction extends ActionSupport{
 HttpServletRequest request;
 private User user;
 private UserService userService;
 int id;

 public int getId() {
 return id;
 }

 public void setId(int id) {
 this.id = id;
 }

 public User getUser() {
 return user;
 }

 public void setUser(User user) {
 this.user = user;
 }

 public UserService getUserService() {
 return userService;
 }

 public void setUserService(UserService userService) {
 this.userService = userService;
 }

 public String insertUser() throws Exception{
 userService.insertUser(user);
 return "success";
 }
 //查询用户
 public String queryUser() throws Exception{
 List<User> userlist=userService.queryUser(user);
 System.out.println("userAction--size--"+userlist.size());
 for(int i=0;i<userlist.size();i++) {
  System.out.println("userAction--"+userlist.get(i).getUserid()+"-"+userlist.get(i).getUsername()+"-"+userlist.get(i).getPassword());
 }
 ActionContext.getContext().getSession().put("userresult", userlist);
 System.out.println("*****");
 return "userResult";
 }
 //删除用户
 public String deleteUser() throws Exception{
 System.out.println("userid:"+id);
 userService.deleteUser(id);
 return "successdelete";
 }
 //查询用户by id
 public String queryUserById() throws Exception{
 System.out.println("userid:"+id);
 User user=userService.queryUserById(id);
 System.out.println("--userAction--"+user.getUserid()+"--"+user.getUsername()+"--"+user.getPassword());
 ActionContext.getContext().getSession().put("result", user);
 return "querybyidRes";
 }
 //修改用户
 public String updateUser() throws Exception{
 userService.updateUser(user);
 return "successupdate";
 }

}

四、Service接口+实现(业务逻辑层)

1、Service接口

UserService.java类

package com.user.service;

import java.util.List;
import com.user.model.User;

public interface UserService {
 //添加用户
 public void insertUser(User user) throws Exception;
 //查询用户
 public List<User> queryUser(User user) throws Exception;
 //查询用户by id
 public User queryUserById(int id) throws Exception;
 //删除用户
 public void deleteUser(int id) throws Exception;
 //修改用户
 public void updateUser(User user) throws Exception;
}

2、Service接口实现

UserServiceImpl.java类

package com.user.service.impl;

import java.util.List;
import com.user.model.User;
import com.user.service.UserService;
import com.user.dao.UserDao;

public class UserServiceImpl implements UserService{
 private UserDao userdao=null;
 public UserDao getUserdao() {
 return userdao;
 }

 public void setUserdao(UserDao userdao) {
 this.userdao = userdao;
 }
 //添加用户
 public void insertUser(User user) throws Exception {
 // TODO Auto-generated method stub
 System.out.println("插入数据User开始--->UserService");
 userdao.insertUser(user);
 System.out.println("插入数据User结束--->UserService");
 }
 //查询用户
 public List<User> queryUser(User user) throws Exception{
 System.out.println("查询数据User开始--->UserService");
 List<User> userlist=userdao.queryUser(user);
 System.out.println("UserService--size--"+userlist.size());
 for(int i=0;i<userlist.size();i++) {
  System.out.println("UserService--"+userlist.get(i).getUserid()+"-"+userlist.get(i).getUsername()+"-"+userlist.get(i).getPassword());
 }
 System.out.println("查询数据User结束--->UserService");
 return userlist;
 }
 //删除用户
 public void deleteUser(int id) throws Exception {
 // TODO Auto-generated method stub
 System.out.println("删除数据User开始--->UserService");
 userdao.deleteUser(id);
 System.out.println("删除数据User开始--->UserService");
 }
 //查询用户by id
 public User queryUserById(int id) throws Exception {
 // TODO Auto-generated method stub
 System.out.println("查询数据BY ID开始--->UserService"+"---"+id);
 User user=userdao.queryUserById(id);
 System.out.println("查询数据BY ID结束--->UserService"+"---"+id);
 return user;
 }
 //修改用户
 public void updateUser(User user) throws Exception {
 // TODO Auto-generated method stub
 System.out.println("更新数据User开始--->UserService");
 userdao.updateUser(user);
 System.out.println("更新数据User开始--->UserService");
 }

}

五、DAO接口+实现(持久层)

1、DAO接口

UserDao.java类

package com.user.dao;
import java.util.List;
import com.user.model.User;;

public interface UserDao {
 //添加用户
 public void insertUser(User user);
 //查询用户
 public List<User> queryUser(User user);
 //查询用户by id
 public User queryUserById(int id);
 //删除用户
 public void deleteUser(int id);
 //修改用户
 public void updateUser(User user);
}

2、DAO接口实现

UserServiceImpl.java类

package com.user.dao.impl;

import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.user.dao.UserDao;
import com.user.model.User;

public class UserDaoImpl extends SqlMapClientDaoSupport implements UserDao{
 //添加用户
 public void insertUser(User user ){
 System.out.println("插入数据User开始--->UserDao"+"---"+user.getUserid()+"-"+user.getUsername()+"-"+user.getPassword());
 this.getSqlMapClientTemplate().insert("insertUser",user);
 System.out.println("插入数据User结束--->UserDao");
 }
 //查询用户
 public List<User> queryUser(User user){
 System.out.println("查询数据User开始--->UserDao"+"---"+user.getUserid()+"-"+user.getUsername()+"-"+user.getPassword());
 List<User> userlist=(List<User>)this.getSqlMapClientTemplate().queryForList("queryUser", user);
 System.out.println("查询数据User结束--->UserDao");
 return userlist;
 }
 //删除用户
 public void deleteUser(int id) {
 System.out.println("删除数据User开始--->UserDao"+"---"+id);
 this.getSqlMapClientTemplate().delete("deleteUser", id);
 System.out.println("删除数据User结束--->UserDao"+"---"+id);
 }
 //查询用户by id
 public User queryUserById(int id) {
 System.out.println("查询数据BY ID开始--->UserDao"+"---"+id);
 User user=(User)this.getSqlMapClientTemplate().queryForObject("queryUserById", id);
 System.out.println("查询数据BY ID结束--->UserDao"+"---"+id);
 return user;
 }
 //修改用户
 public void updateUser(User user) {
 System.out.println("更新数据User开始--->UserDao"+"---"+user.getUserid());
 this.getSqlMapClientTemplate().update("updateUser", user);
 System.out.println("更新数据User结束--->UserDao"+"---"+user.getUserid());
 }
}

六、JSP文件(表示层)

1、index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 </head>

 <body>
 <a href="userAdd.jsp" rel="external nofollow" >添加用户</a><br>
 <a href="query.jsp" rel="external nofollow" >查询/管理用户</a>
 </body>
</html>

2、query.jsp查询页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 </head>

 <body>
 <form action="index_queryUser.do" method="post">
 用户ID:<input type="text" name="user.userid" id="userid">
 <input type="submit" value="查询">
 </form>
 </body>
</html>

3、userAdd.jsp添加用户页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>

 </head>

 <body>
 <form action="index_insertUser.do" method="post">
 <table>
  <tr>
  <td>用户ID:</td>
  <td><input type="text" name="user.userid" id="userid"></td>
  </tr>
  <tr>
  <td>用户名:</td>
  <td><input type="text" name="user.username" id="username"></td>
  </tr>
  <tr>
  <td>密码:</td>
  <td><input type="text" name="user.password" id="password"></td>
  </tr>
  <tr>
  <td><input type="submit" value="插入数据"></td>
  </tr>
 </table>
 </form>
 </body>
</html>

4、userUpdate.jsp修改用户页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.user.model.User" ;%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>

 </head>

 <body>
 <%
 User user=(User)session.getAttribute("result");
 %>
 <form action="index_updateUser.do" method="post">
 <table>
  <tr>
  <td>用户ID:</td>
  <td><input type="text" name="user.userid" id="userid" value="<%=user.getUserid() %>" readonly></td>
  </tr>
  <tr>
  <td>用户名:</td>
  <td><input type="text" name="user.username" id="username" value="<%=user.getUsername() %>"></td>
  </tr>
  <tr>
  <td>密码:</td>
  <td><input type="text" name="user.password" id="password" value="<%=user.getPassword() %>"></td>
  </tr>
  <tr>
  <td><input type="submit" value="修改数据"></td>
  </tr>
 </table>
 </form>
 </body>
</html>

5、userResult.jsp用户列表

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.user.model.User" ;%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 </head>

 <body>
 <%
 List<User> userlist=(List<User>)session.getAttribute("userresult");
 System.out.println("userResult.jsp--size--"+userlist.size());
 for(int i=0;i<userlist.size();i++) {
 System.out.println("userResult.jsp--"+userlist.get(i).getUserid()+"-"+userlist.get(i).getUsername()+"-"+userlist.get(i).getPassword());
 }
 %>
 <table border="1">
  <tr>
  <td>用户ID</td>
  <td>用户名</td>
  <td>密码</td>
  <td>修改</td>
  <td>删除</td>
  </tr>
  <%for(int i=0;i<userlist.size();i++) {%>
  <tr>
  <td><%=userlist.get(i).getUserid() %></td>
  <td><%=userlist.get(i).getUsername() %></td>
  <td><%=userlist.get(i).getPassword() %></td>
  <td><a href="index_queryUserById.do?id=<%=userlist.get(i).getUserid() %>" rel="external nofollow" >修改</a></td>
  <td><a href="index_deleteUser.do?id=<%=userlist.get(i).getUserid() %>" rel="external nofollow" >删除</a></td>
  </tr>
  <%} %>
 </table>
 </body>
</html>

6、success.jsp操作成功页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 </head>

 <body>
 操作成功!
 </body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Spring boot + mybatis + Vue.js + ElementUI 实现数据的增删改查实例代码(一)

    环境搭建 spring boot的简介 以往我们开发时用到spring总是避免不了繁琐的配置,例如我们要配置一个数据库连接,可能需要以下几步: 1.编写jdbc.properties配置文件: 2.创建spring的配置文件,加入spring配置文件前缀.配置数据库连接信息以及sqlsessionFactory等等: 3.还要在web.xml文件中加入spring的监听. springboot的出现大大简化了项目的搭建过程(spring配置以及maven配置),让我们专注于应用功能的开发,而不是

  • IntelliJ Idea SpringBoot 数据库增删改查实例详解

    SpringBoot 是 SpringMVC 的升级,对于编码.配置.部署和监控,更加简单 微服务 微服务是一个新兴的软件架构,就是把一个大型的单个应用程序和服务拆分为数十个的支持微服务.一个微服务的策略可以让工作变得更为简便,它可扩展单个组件而不是整个的应用程序堆栈,从而满足服务等级协议. Spring 为 微服务提供了一整套的组件-SpringClound , SpirngBoot 就是该基础. 第一个SpringBoot程序 这里使用的开发软件是IntelliJ Idea,和Eclipse

  • 使用SpringBoot开发Restful服务实现增删改查功能

    在去年的时候,在各种渠道中略微的了解了SpringBoot,在开发web项目的时候是如何的方便.快捷.但是当时并没有认真的去学习下,毕竟感觉自己在Struts和SpringMVC都用得不太熟练.不过在看了很多关于SpringBoot的介绍之后,并没有想象中的那么难,于是开始准备学习SpringBoot. 在闲暇之余的时候,看了下SpringBoot实战以及一些大神关于SpringBoot的博客之后,开始写起了我的第一个SpringBoot的项目.在能够对SpringBoot进行一些简单的开发Re

  • springboot使用JdbcTemplate完成对数据库的增删改查功能

    首先新建一个简单的数据表,通过操作这个数据表来进行演示 DROP TABLE IF EXISTS `items`; CREATE TABLE `items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `name` varchar(10) DEFAULT NULL, `detail` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE

  • SpringMVC4 + MyBatis3 + SQL Server 2014整合教程(含增删改查分页)

    前言 说起整合自然离不开ssm,我本身并不太喜欢ORM,尤其是MyBatis,把SQL语句写在xml里,尤其是大SQL,可读性不高,出错也不容易排查. 开发环境 idea2016.SpringMVC4.Mybatis3 项目结构 SSM整合 1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&qu

  • Spring boot + mybatis + Vue.js + ElementUI 实现数据的增删改查实例代码(二)

    在上篇文章给大家介绍了Spring boot + mybatis + Vue.js + ElementUI 实现数据的增删改查实例代码(一),接下来我们添加分页相关的依赖,时间紧张,直接上代码了,贴上我的pom文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=

  • Spring MVC实现mysql数据库增删改查完整实例

    最近刚学了springmvc框架,感觉确实方便了不少,减少了大量的冗余代码.就自己做了个小项目练练手,这是个初级的springmvc应用的项目,没有用到mybatis,项目功能还算完善,实现了基本的增删改查的功能. 项目环境: -系统:win10 -开发环境:eclipseOxygenReleaseCandidate3(4.7) -jdk版本:java1.8(121) -mysql:5.7 -spring:4.0 -tomcat:8.5 用到的技术: springmvcspringjspjdbc

  • Springboot+hibernate实现简单的增删改查示例

    1.创建好项目之后在配置端口号(也可以不用配置,默认端口8080) #server server.port=8080 server.tomcat.uri-encoding=utf-8 2.配置mysql #MySQL spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8 sprin

  • SpringMVC之简单的增删改查示例(SSM整合)

    虽然已经在做关于SpringMVC的项目.但是还没有写一些比较系统的博客.今天就先来说一说最简单的增删改查吧.这个例子是基于SpringMVC+Spring+Mybatis实现的. 环境配置 主要是几项配置:springmvc的配置,spring的配置,MyBatis的配置,jdbc的配置,和web.xml配置 springmvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&qu

  • SpringBoot JPA实现增删改查、分页、排序、事务操作等功能示例

    今天给大家介绍一下SpringBoot中JPA的一些常用操作,例如:增删改查.分页.排序.事务操作等功能. 下面先来介绍一下JPA中一些常用的查询操作: //And --- 等价于 SQL 中的 and 关键字,比如 findByHeightAndSex(int height,char sex): public List<User> findByHeightAndSex(int height,char sex); // Or --- 等价于 SQL 中的 or 关键字,比如 findByHei

随机推荐