Guest User

Untitled

a guest
Feb 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. package com.emp.controller;
  2. @Controller
  3. @RequestMapping("/emp")
  4. public class EmpController {
  5. @Autowired
  6. EmpMapper empMapper;
  7. @RequestMapping(value = "testInsert")
  8. public void insertEmp() {
  9. EmpVO empVO = new EmpVO();
  10. empVO.setEname("RAYSUN2");
  11. empVO.setComm(10000.0);
  12. empVO.setHireDate(java.sql.Date.valueOf("2019-01-01"));
  13. empVO.setDeptNo(20);
  14. empVO.setSal(90000.0);
  15. empMapper.insert(empVO);
  16. //ApplicationContext context = new ClassPathXmlApplicationContext("spring/spring-mybatis.xml");
  17. //EmpMapper empMapper = context.getBean(EmpMapper.class);
  18. //empMapper.insert(empVO);
  19. }
  20. }
  21.  
  22. package com.emp.mapper;
  23. public interface EmpMapper {
  24. void insert(EmpVO empVO);
  25. void update(EmpVO empVO);
  26. void delete(Integer empno);
  27. EmpVO findByPrimaryKey(Integer empno);
  28. List<EmpVO> getAll();
  29. }
  30.  
  31. <?xml version="1.0" encoding="UTF-8"?>
  32. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  33. <mapper namespace="com.emp.mapper.EmpMapper">
  34. <sql id="emp2_seq">emp2_seq.nextval</sql>
  35. <resultMap type="com.emp.model.EmpVO" id="EmpVO">
  36. <id property="empno" column="empno" jdbcType="DECIMAL" />
  37. <result property="ename" column="ename" jdbcType="VARCHAR" />
  38. <result property="job" column="job" jdbcType="VARCHAR" />
  39. <result property="hireDate" column="hiredate" jdbcType="DATE" />
  40. <result property="sal" column="sal" jdbcType="DOUBLE" />
  41. <result property="comm" column="comm" jdbcType="DOUBLE" />
  42. <result property="deptNo" column="deptno" jdbcType="DECIMAL" />
  43. </resultMap>
  44. <insert id="insert" parameterType="com.emp.model.EmpVO">
  45. insert into emp2 (empno, ename, job, hiredate, sal, comm, deptno)
  46. values
  47. (<include refid="emp2_seq" />, #{ename}, #{job}, #{hireDate}, #{sal}, #{comm}, #{deptNo})
  48. </insert>
  49. </mapper>
  50.  
  51. <?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54. xmlns:aop="http://www.springframework.org/schema/aop"
  55. xmlns:tx="http://www.springframework.org/schema/tx"
  56. xmlns:context="http://www.springframework.org/schema/context"
  57. xsi:schemaLocation="
  58. http://www.springframework.org/schema/beans
  59. http://www.springframework.org/schema/beans/spring-beans.xsd
  60. http://www.springframework.org/schema/tx
  61. http://www.springframework.org/schema/tx/spring-tx.xsd
  62. http://www.springframework.org/schema/aop
  63. http://www.springframework.org/schema/aop/spring-aop.xsd
  64. http://www.springframework.org/schema/context
  65. http://www.springframework.org/schema/context/spring-context.xsd">
  66. <import resource="classpath*:/spring/model-config2-JndiObjectFactoryBean.xml"/>
  67.  
  68. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  69. <property name="dataSource" ref="dataSource" />
  70. <property name="configLocation" value="classpath:/mybatis/mybatis-config.xml" />
  71. <property name="mapperLocations" value="classpath*:/mybatis/mapper/**/*.xml" />
  72. </bean>
  73.  
  74. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  75. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  76. <property name="basePackage" value="com.emp.mapper" />
  77. </bean>
  78. </beans>
  79.  
  80. <beans xmlns="http://www.springframework.org/schema/beans"
  81. xmlns:context="http://www.springframework.org/schema/context"
  82. xmlns:mvc="http://www.springframework.org/schema/mvc"
  83. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84. xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. http://www.springframework.org/schema/beans/spring-beans.xsd
  86. http://www.springframework.org/schema/mvc
  87. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  88. http://www.springframework.org/schema/context
  89. http://www.springframework.org/schema/context/spring-context.xsd">
  90. <context:component-scan base-package="com.emp">
  91. </context:component-scan>
  92. <mvc:annotation-driven />
  93. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  94. <property name="prefix" value="/WEB-INF/views/" />
  95. <property name="suffix" value=".jsp" />
  96. </bean>
  97. </beans>
  98.  
  99. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
  100. <web-app>
  101. <display-name>Archetype Created Web Application</display-name>
  102. <context-param>
  103. <param-name>contextConfigLocation</param-name>
  104. <param-value>
  105. classpath*:/spring/*.xml
  106. </param-value>
  107. </context-param>
  108. <servlet>
  109. <servlet-name>dispatcher</servlet-name>
  110. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  111. <init-param>
  112. <param-name>contextConfigLocation</param-name>
  113. <param-value>classpath*:/springmvc/spring-ssm_webapp-mvc.xml</param-value>
  114. </init-param>
  115. <load-on-startup>1</load-on-startup>
  116. </servlet>
  117. <servlet-mapping>
  118. <servlet-name>dispatcher</servlet-name>
  119. <url-pattern>/</url-pattern>
  120. </servlet-mapping>
  121. </web-app>
  122.  
  123. <listener>
  124. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  125. </listener>
Add Comment
Please, Sign In to add comment