Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.emp.controller;
- @Controller
- @RequestMapping("/emp")
- public class EmpController {
- @Autowired
- EmpMapper empMapper;
- @RequestMapping(value = "testInsert")
- public void insertEmp() {
- EmpVO empVO = new EmpVO();
- empVO.setEname("RAYSUN2");
- empVO.setComm(10000.0);
- empVO.setHireDate(java.sql.Date.valueOf("2019-01-01"));
- empVO.setDeptNo(20);
- empVO.setSal(90000.0);
- empMapper.insert(empVO);
- //ApplicationContext context = new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
- //EmpMapper empMapper = context.getBean(EmpMapper.class);
- //empMapper.insert(empVO);
- }
- }
- package com.emp.mapper;
- public interface EmpMapper {
- void insert(EmpVO empVO);
- void update(EmpVO empVO);
- void delete(Integer empno);
- EmpVO findByPrimaryKey(Integer empno);
- List<EmpVO> getAll();
- }
- <?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.emp.mapper.EmpMapper">
- <sql id="emp2_seq">emp2_seq.nextval</sql>
- <resultMap type="com.emp.model.EmpVO" id="EmpVO">
- <id property="empno" column="empno" jdbcType="DECIMAL" />
- <result property="ename" column="ename" jdbcType="VARCHAR" />
- <result property="job" column="job" jdbcType="VARCHAR" />
- <result property="hireDate" column="hiredate" jdbcType="DATE" />
- <result property="sal" column="sal" jdbcType="DOUBLE" />
- <result property="comm" column="comm" jdbcType="DOUBLE" />
- <result property="deptNo" column="deptno" jdbcType="DECIMAL" />
- </resultMap>
- <insert id="insert" parameterType="com.emp.model.EmpVO">
- insert into emp2 (empno, ename, job, hiredate, sal, comm, deptno)
- values
- (<include refid="emp2_seq" />, #{ename}, #{job}, #{hireDate}, #{sal}, #{comm}, #{deptNo})
- </insert>
- </mapper>
- <?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: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">
- <import resource="classpath*:/spring/model-config2-JndiObjectFactoryBean.xml"/>
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="configLocation" value="classpath:/mybatis/mybatis-config.xml" />
- <property name="mapperLocations" value="classpath*:/mybatis/mapper/**/*.xml" />
- </bean>
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
- <property name="basePackage" value="com.emp.mapper" />
- </bean>
- </beans>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- 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/mvc
- http://www.springframework.org/schema/mvc/spring-mvc.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd">
- <context:component-scan base-package="com.emp">
- </context:component-scan>
- <mvc:annotation-driven />
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/views/" />
- <property name="suffix" value=".jsp" />
- </bean>
- </beans>
- <!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-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- classpath*:/spring/*.xml
- </param-value>
- </context-param>
- <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*:/springmvc/spring-ssm_webapp-mvc.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>dispatcher</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- </web-app>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
Add Comment
Please, Sign In to add comment