惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
V2EX - 技术
V2EX - 技术
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
Project Zero
Project Zero
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
AWS News Blog
AWS News Blog
Scott Helme
Scott Helme
C
Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
P
Privacy International News Feed
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
The Last Watchdog
The Last Watchdog
NISL@THU
NISL@THU
Attack and Defense Labs
Attack and Defense Labs
G
GRAHAM CLULEY
Security Latest
Security Latest
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Hugging Face - Blog
Hugging Face - Blog
月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Security @ Cisco Blogs
腾讯CDC
S
Secure Thoughts
WordPress大学
WordPress大学
P
Proofpoint News Feed
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
小众软件
小众软件
M
MIT News - Artificial intelligence
博客园 - 叶小钗
IT之家
IT之家
G
Google Developers Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
N
News and Events Feed by Topic

博客园 - Ring

运行Java cmd程序 找不到或无法加载主类怎么解决 Generics and Collection (2) Generics and Collection (1) 什么时候该用NoSQL? 如何学习Javascript 好文章尽收眼底 事务和锁 索引 VS调试Javascript. Asp.net常用状态管理方案分析 .NET中的缓存知识总结 "The server has rejected the client credentials"解决方案 - Ring 有关IIS7概述以及配置和开发的几篇文章摘录 CodeForFun--编写自动登录Email的程序 是什么使得我的进程崩溃了? OutOfMemory这家伙是谁?为什么我还留有许多内存,它却使进程崩溃了? ASP.NET 崩溃-SiteMap中疯狂的循环 何时.NET中AppDomain会回收? .NET如何使用内存---餐馆案例分析
mybatis, spring, springmvc
Ring · 2015-04-16 · via 博客园 - Ring

mybatis配置:


mybatis-config.xml

<configuration>
    <!-- 作者MyBatis博客:
         http://legend2011.blog.51cto.com/3018495/d-5 -->
    
    <environments default="development">
        <!-- id必须唯一 -->
        <environment id="development">
            <!-- 事务管理器,这里直接使用jdbc的事务管理能力 -->
            <transactionManager type="jdbc" />
            <!-- 数据源配置 -->
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost/db_book" />
                <property name="username" value="root" />
                <property name="password" value="123456" />
            </dataSource>
        </environment>
    </environments>

    <!-- 采用相对类路径 -->
    <mappers>
        <mapper resource="mapper/StudentMapper.xml" />
    </mappers>
</configuration>

StudentMapper.xml

<?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.abc.mapper.StudentMapper">
    <!-- 作者MyBatis博客:
         http://legend2011.blog.51cto.com/3018495/d-5 -->
    
    <!--useGeneratedKeys="true"表明使用数据库自动生成的主键,
      keyColumn="id"指定Student表中主键列,keyProperty="id"
            表明当插入记录后,会把数据库生成的主键值设置到Student对象
            的id属性中,也就是说,它指定与Student表中的主键列对应的
      Student实体类中的属性是id这个属性-->
    <insert id="add" useGeneratedKeys="true" keyColumn="id"
        keyProperty="id" 
        parameterType="com.abc.domain.Student">
        insert into student(name, gender, major, grade)
        values(#{name}, #{gender}, #{major}, #{grade})
    </insert> 
 
</mapper>

SPRING配置:

bean.xml (IOC)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    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">
    
    <bean id="dog" class="com.java1234.entity.Dog">
        <property name="name" value="jack"></property>
    </bean>
    
    <bean id="abstractPeople" class="com.java1234.entity.People" abstract="true">
        <property name="className" value="高三5班"></property>
        <property name="age" value="19"></property>
    </bean>
    
    <bean id="zhangsan" parent="abstractPeople" depends-on="autority">
        <property name="id" value="1"></property>
        <property name="name" value="张三"></property>
    </bean>
    
    <bean id="lisi" parent="abstractPeople">
        <property name="id" value="2"></property>
        <property name="name" value="李四"></property>
        <property name="age" value="20"></property>
        <property name="dog" ref="dog"></property>
    </bean>
    
    
    <bean id="autority" class="com.java1234.service.Authority"></bean>
</beans>


(AOP)

<?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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
    
    <bean id="studentServiceAspect" class="com.java1234.advice.StudentServiceAspect"></bean>
    
    <bean id="studentService" class="com.java1234.service.impl.StudentServiceImpl"></bean>

    <aop:config>
        <aop:aspect id="studentServiceAspect" ref="studentServiceAspect">
            <aop:pointcut expression="execution(* com.java1234.service.*.*(..))" id="businessService"/>
            <aop:before method="doBefore" pointcut-ref="businessService"/>
            <aop:after method="doAfter" pointcut-ref="businessService"/>
            <aop:around method="doAround" pointcut-ref="businessService"/>
            <aop:after-returning method="doAfterReturning" pointcut-ref="businessService"/>
            <aop:after-throwing method="doAfterThrowing" pointcut-ref="businessService" throwing="ex"/>
        </aop:aspect> 
    </aop:config>
</beans>

SPRINGMVC

spring-mvc.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: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/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 使用注解的包,包括子集 -->
    <context:component-scan base-package="com.java1234"/>

    <!-- 视图解析器 -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp"></property>
    </bean>
    
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        
        <property name="defaultEncoding" value="UTF-8"/>  
        <property name="maxUploadSize" value="10000000"/>

    <


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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>SpringMvc01</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
</web-app>