日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Java中SSM框架實現增刪改查功能代碼詳解

瀏覽:25日期:2022-08-28 15:24:28

記錄一下自己第一次整合smm框架的步驟。

參考博客和網站有:我沒有三顆心臟 How2J學習網站

1.數據庫使用的是mySql,首先創建數據庫ssm1,并創建表student

create database ssm1;use ssm1; CREATE TABLE student( id int(11) NOT NULL AUTO_INCREMENT, student_id int(11) NOT NULL UNIQUE, name varchar(255) NOT NULL, age int(11) NOT NULL, sex varchar(255) NOT NULL, birthday date DEFAULT NULL, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2.新建java web項目,命名為ssm1,并且導入相關的jar包。

3.建立pojo類,在這里命名為student,包名為com.ssm1.pojo

package com.ssm1.pojo;public class Student { private int id; private int student_id; private String name; private int age; private String sex; private String birthday; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getStudent_id() { return student_id; } public void setStudent_id(int student_id) { this.student_id = student_id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) { this.birthday = birthday; }}

4.建立映射器接口studentMapper,包名為com.ssm1.mapper

package com.ssm1.mapper;import java.util.List;import com.ssm1.pojo.Student;public interface StudentMapper { public int add(Student student); public void delete(int id); public Student get(int id); public int update(Student student); public List<Student> list();}

5.建立與studentMapper對應的xml文件,同樣屬于包com.ssm1.mapper

<?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.ssm1.mapper.StudentMapper'> <insert parameterType='Student'> INSERT INTO student VALUES(#{student_id},#{name}, #{age}, #{sex}, #{birthday}) </insert> <!-- <insert parameterType='com.ssm1.pojo.Student' useGeneratedKeys='true' keyProperty='id'> insert into student <trim prefix='(' suffix=')' suffixOverrides=',' > <if test='student_id!=null'> student_id, </if> <if test='name!=null and name!=’’'> name, </if> <if test='age!=null'> age, </if> <if test='sex!=null and sex!=’’'> sex, </if> <if test='birthday!=null and birthday !=’’'> birthday, </if> </trim> <trim prefix='values (' suffix=')' suffixOverrides=',' > <if test='student_id!=null'> #{student_id}, </if> <if test='name!=null and name!=’’'> #{name}, </if> <if test='age!=null'> #{age}, </if> <if test='sex!=null and sex!=’’'> #{sex}, </if> <if test='birthday!=null and birthday !=’’'> #{birthday}, </if> </trim> </insert> --> <delete parameterType='Student'> delete from student where id= #{id} </delete> <select parameterType='_int' resultType='Student'> select * from student where id= #{id} </select> <update parameterType='Student'> UPDATE student SET student_id = #{student_id}, name = #{name}, age = #{age}, sex = #{sex}, birthday = #{birthday} WHERE id = #{id} </update> <select resultType='Student'> select * from student </select></mapper>

6.建立studentService接口,包名為com.ssm1.service

package com.ssm1.service;import java.util.List;import com.ssm1.pojo.Student;public interface StudentService { List<Student> list(); void add(Student s); void delete(Student s); void update(Student s); Student get(int id);}

7.建立studentServiceImpl類,實現接口,包名為com.ssm1.service

package com.ssm1.service;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.ssm1.mapper.StudentMapper;import com.ssm1.pojo.Student;@Servicepublic class StudentServiceImpl implements StudentService { @Autowired StudentMapper studentMapper; @Override public List<Student> list() { // TODO Auto-generated method stub return studentMapper.list(); } @Override public void add(Student s) { // TODO Auto-generated method stub studentMapper.add(s); } @Override public void delete(Student s) { // TODO Auto-generated method stub studentMapper.delete(s.getId()); } @Override public void update(Student s) { // TODO Auto-generated method stub studentMapper.update(s); } @Override public Student get(int id) { // TODO Auto-generated method stub return studentMapper.get(id); }}

8.建立studentController控制器,包名為com.ssm1.controller

package com.ssm1.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import com.ssm1.pojo.Student;import com.ssm1.service.StudentService;import com.ssm1.util.Page;@Controller@RequestMapping('')public class StudentController { @Autowired StudentService studentService; @RequestMapping('/index') public ModelAndView index(Page page) { ModelAndView mav = new ModelAndView(); List<Student> cs = studentService.list(); mav.addObject('cs', cs); mav.setViewName('index'); return mav; } @RequestMapping(value = 'addStudent', produces = 'text/html; charset=utf-8') // @RequestMapping('addStudent') public ModelAndView addStudent(Student student) { studentService.add(student); ModelAndView mav = new ModelAndView('redirect:/index'); return mav; } @RequestMapping('deleteStudent') public ModelAndView deleteStudent(Student student) { studentService.delete(student); ModelAndView mav = new ModelAndView('redirect:/index'); return mav; } @RequestMapping('editStudent') public ModelAndView editStudent(Student student) { Student s=studentService.get(student.getId()); ModelAndView mav=new ModelAndView('editStudent'); mav.addObject('s',s); return mav; } @RequestMapping('updateStudent') public ModelAndView updateStudent(Student student) { studentService.update(student); ModelAndView mav=new ModelAndView('redirect:/index'); return mav; }}

9.在WEB-INF目錄下建立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' xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd' version='2.5'> <!-- 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> <!-- spring mvc核心:分發servlet --> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- spring mvc的配置文件 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>CharacterEncodingFilter</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> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>

10.在src目錄下新建applicationContext.xml文件,這是Spring的配置文件

<?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:tx='http://www.springframework.org/schema/tx' xmlns:jdbc='http://www.springframework.org/schema/jdbc' xmlns:context='http://www.springframework.org/schema/context' xmlns:mvc='http://www.springframework.org/schema/mvc' xsi:schemaLocation=' http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd'><!-- 配置@Service包的掃描 --> <context:annotation-config /> <context:component-scan base-package='com.ssm1.service' /> <!-- 配置數據庫的連接 --> <bean class='org.springframework.jdbc.datasource.DriverManagerDataSource'> <property name='driverClassName'> <value>com.mysql.jdbc.Driver</value> </property> <property name='url'> <value>jdbc:mysql://localhost:3306/ssm1?characterEncoding=UTF-8</value> </property> <property name='username'> <value>root</value> </property> <property name='password'> <value>admin</value> </property> </bean> <!-- 配置SQLSessionFactory --> <bean class='org.mybatis.spring.SqlSessionFactoryBean'> <property name='typeAliasesPackage' value='com.ssm1.pojo' /> <property name='dataSource' ref='dataSource'/> <property name='mapperLocations' value='classpath:com/ssm1/mapper/*.xml'/> </bean> <bean class='org.mybatis.spring.mapper.MapperScannerConfigurer'> <property name='basePackage' value='com.ssm1.mapper'/> </bean></beans>

11.在src目錄下新增springMVC.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:tx='http://www.springframework.org/schema/tx' xmlns:jdbc='http://www.springframework.org/schema/jdbc' xmlns:context='http://www.springframework.org/schema/context' xmlns:mvc='http://www.springframework.org/schema/mvc' xsi:schemaLocation='http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd'><context:annotation-config/> <context:component-scan base-package='com.ssm1.controller'> <context:include-filter type='annotation' expression='org.springframework.stereotype.Controller'/> </context:component-scan> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <bean class='org.springframework.web.servlet.view.InternalResourceViewResolver'> <property name='viewClass' value='org.springframework.web.servlet.view.JstlView' /> <property name='prefix' value='/WEB-INF/jsp/' /> <property name='suffix' value='.jsp' /> </bean></beans>

12.在WEB-INF下創建jsp目錄,并創建文件index.jsp和editStudent.jsp

<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8' import='java.util.*'%><%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%><!DOCTYPE html><html><head><meta charset='UTF-8'><title>Insert title here</title></head><body> <table align=’center’ border=’1’ cellspacing=’0’> <tr> <td>id</td> <td>student_id</td> <td>name</td> <td>age</td> <td>sex</td> <td>birthday</td> <td>編輯</td> <td>刪除</td> </tr> <c:forEach items='${cs}' var='c' varStatus='st'> <tr> <td>${c.id}</td> <td>${c.student_id}</td> <td>${c.name}</td> <td>${c.age}</td> <td>${c.sex}</td> <td>${c.birthday}</td> <td><a href='http://m.b3g6.com/bcjs/editStudent?id=${c.id}' rel='external nofollow' >編輯</a></td> <td><a href='http://m.b3g6.com/bcjs/deleteStudent?id=${c.id}' rel='external nofollow' >刪除</a></td> </tr> </c:forEach></table> <div style='text-align:center;margin-top:40px'> <form method='post' action='addStudent' > 學生學號: <input name='student_id' value='' type='text'> <br><br> 學生姓名: <input name='name' value='' type='text'> <br><br> 學生年紀: <input name='age' value='' type='text'> <br><br> 學生性別: <input name='sex' value='' type='text'> <br><br> 學生生日: <input name='birthday' value='' type='text'> <br><br> <input type='submit' value='增加學生'> </form> </div> <div style='text-align:center; margin-top:20px'> <form action='${pageContext.request.contextPath }/index' method='post'> <input value='刷新' type='submit'> </form> </div></body></html>

<%@ page language='java' contentType='text/html; charset=UTF-8' pageEncoding='UTF-8' import='java.util.*'%><%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='s'%> <div style='width:500px;margin:0px auto;text-align:center'> <div style='text-align:center;margin-top:40px'> <form method='post' action='updateStudent'> 分類名稱: <input name='student_id' value='${s.student_id}' type='text'> <br><br> 分類名稱: <input name='name' value='${s.name}' type='text'> <br><br> 分類名稱: <input name='age' value='${s.age}' type='text'> <br><br> 分類名稱: <input name='sex' value='${s.sex}' type='text'> <br><br> 分類名稱: <input name='birthday' value='${s.birthday}' type='text'> <br><br> <input type='hidden' value='${s.id}' name='id'> <input type='submit' value='修改分類'> </form> </div> </div>

13.最后在tomcat上部署項目,輸入路徑localhost:端口號/ssm1/index即可訪問

到此這篇關于Java中SSM框架實現增刪改查功能代碼詳解的文章就介紹到這了,更多相關SSM框架實現增刪改查功內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
成人精品久久| 亚洲色图网站| 久久精品一区二区三区中文字幕| 亚洲精品看片| 日本午夜精品久久久久| 国产精品一区二区精品视频观看| 日韩精品免费一区二区夜夜嗨| 亚洲精品欧洲| 日韩动漫一区| 国产亚洲精aa在线看| 国产探花一区二区| 欧美在线观看天堂一区二区三区| 99热精品久久| 亚洲二区在线| 亚洲一区二区三区免费在线观看 | 日本视频在线一区| 日韩精品一卡二卡三卡四卡无卡| 99国产精品久久久久久久| 精品日韩毛片| 亚洲成av在线| 五月综合激情| 国产乱人伦精品一区| 国产欧美二区| 欧美午夜不卡| 精品久久网站| 蜜桃av一区二区三区电影| 久久只有精品| 老牛影视一区二区三区| 国产成人精品免费视| 欧美综合国产| 国产高潮在线| 最新国产精品视频| 国产精品精品| 日本午夜精品一区二区三区电影| 精品日韩视频| 国产精品v一区二区三区| 性欧美69xoxoxoxo| 欧美国产精品| 亚洲欧美网站在线观看| 亚洲播播91| 国产美女精品视频免费播放软件| 好吊一区二区三区| 日韩av免费大片| 日本国产亚洲| 亚洲精品99| 97精品国产| 欧美中文高清| 尹人成人综合网| 亚洲色图网站| 另类专区亚洲| 天堂va在线高清一区| 国产成人免费视频网站视频社区| 日韩视频在线一区二区三区 | 精品国产乱码久久久久久樱花| 99成人在线视频| 日本va欧美va精品发布| 天堂资源在线亚洲| 国产日韩免费| 日韩av中文在线观看| 国产aa精品| 欧美日本一区| 在线免费观看亚洲| 91精品高清| 日韩精品一区二区三区免费观影| 久久精品国产一区二区| 久久狠狠久久| 日韩高清一区在线| 亚洲欧洲午夜| 亚洲韩日在线| 91精品蜜臀一区二区三区在线| 丰满少妇一区| 精品国产一级| 久久av中文| 国产精品欧美三级在线观看 | 麻豆精品在线| 国产日韩一区二区三免费高清| 午夜电影一区| 亚洲ww精品| 亚洲狼人精品一区二区三区| 午夜一级久久| 美女久久一区| 99精品美女| 欧美成人一二区| 亚洲a级精品| 丝袜美腿亚洲一区二区图片| 久久中文字幕av一区二区不卡| 黄色网一区二区| 国产精品一区二区av日韩在线| 中文字幕成人| 男女激情视频一区| 欧美日韩视频| 免费成人网www| 天堂av在线| 精品美女在线视频| 国产精品手机在线播放| 欧美一区网站| 亚洲丝袜美腿一区| 午夜在线播放视频欧美| 美女亚洲一区| 欧美成人久久| 亚洲激情中文在线| 午夜久久99| 伊人影院久久| 中文国产一区| aa国产精品| 亚洲色诱最新| 亚洲欧美日韩在线观看a三区| 欧美日韩视频一区二区三区| 欧美1级日本1级| 美女少妇全过程你懂的久久| 久久五月天小说| 亚洲最新无码中文字幕久久| 国产精品成人一区二区不卡| 91偷拍一区二区三区精品| 国产一区二区三区精品在线观看| 美女性感视频久久| 精品五月天堂| 国产资源在线观看入口av| 国产videos久久| 国产成人精品亚洲线观看| 日本一区二区高清不卡| 国产精品久久久久久久免费观看 | 日韩在线精品| 另类专区亚洲| 999国产精品永久免费视频app| 久久久久久黄| 欧美另类综合| 亚洲有吗中文字幕| 日韩av网站在线观看| 国产精品密蕾丝视频下载| 国产精品久久久久久久久免费高清 | 欧美日韩一二| 香蕉久久99| 欧美日韩视频| 亚洲精品无播放器在线播放| 欧美一区精品| 另类综合日韩欧美亚洲| 国产精选在线| 91精品观看| 亚洲一区网站| 五月国产精品| 国产精品一区二区美女视频免费看 | 免费在线看一区| 好看的亚洲午夜视频在线| 亚洲欧美日韩一区在线观看| 亚洲精品在线a| 日韩精品亚洲aⅴ在线影院| 91精品福利观看| 精品国产黄a∨片高清在线| 麻豆网站免费在线观看| 国产国产精品| 日韩有吗在线观看| 久久久国产精品网站| 亚洲91视频| 最新国产精品视频| 精品免费av一区二区三区| 久久夜夜操妹子| 日韩在线卡一卡二| 国产精品巨作av| 日韩精品麻豆| 免费在线视频一区| 日韩成人一级| 久久男人av资源站| 视频一区欧美日韩| 国产精品久久久久久av公交车| 日韩免费av| 亚洲日本国产| 国产成人精品福利| 中文一区在线| 美腿丝袜亚洲一区| 婷婷亚洲五月| 国产调教一区二区三区| 日韩不卡在线| 婷婷成人av| 亚洲成人av观看| 亚洲人成精品久久久| 老色鬼精品视频在线观看播放| 精品一区亚洲| 美女精品视频在线| 欧美1级日本1级| 国产精品二区影院| 久久精品国产亚洲夜色av网站 | 亚洲精品伦理| 成人亚洲一区二区| 中文字幕日本一区二区| 日韩av二区| 亚洲精品黄色| 久久精品国内一区二区三区水蜜桃| 日本视频中文字幕一区二区三区| а√天堂8资源中文在线| 四虎精品永久免费| 视频二区不卡| 国产精品激情| 蜜臀久久99精品久久久久久9 | 欧美激情麻豆| 巨乳诱惑日韩免费av| 成人国产精选| 日韩av中文字幕一区| 亚洲精品电影| bbw在线视频|