首页 > 代码库 > ssh的有关注解的配置annotation
ssh的有关注解的配置annotation
dao层:@Repository(value ="")或者@Component(value="") service层:@Service(value ="")或者@Component(value="") 有关事务的配置: @Transactional(propagation=Propagation.REQUIRED)(更新) @Transactional(propagation=Propagation.SUPPORTS)(查询) action层:@Controller(value=""),@Scope("prototype") (配置为多例) 注入:@Autowired,@Resource 实体类中的配置: 类之前: @Entity(name="User") @Table(name="xs_user") @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) @IdClass(value=AgencyFunctionInfoRoleAssociate.class) id 前的配置: @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", nullable = false) private Integer id; 有关时间的配置: @Temporal(TemporalType.TIMESTAMP) @Column(name = "create_time", nullable = false) private Date createTime; 用到枚举是的配置: @Enumerated(EnumType.STRING) @Column(name = "active_type", nullable = false, length = 32) private ActiveType activeType; 一般的配置: @Column(name = "comments", nullable = false, length = 128) private String comments; @Column(name = "comments", nullable = false, length = 256) private String comments; 内容较多时: @Column(name = "affiche_content", nullable = false, columnDefinition="TEXT") private String afficheContent; Boolean型: @Column(name = "is_enable", nullable = false) private Boolean enable; 有关于唯一: @Column(name = "logogram_name", nullable = false, unique = true, length = 16) private String logogramName; 有默认值时: @Column(name = "already_guaranted_count", nullable = false, columnDefinition = "int DEFAULT 0") private Integer alreadyGuarantedPhasesCount; double类型的处理: @Column(name = "already_guaranted_amount", scale = 2, precision = 16, columnDefinition = "decimal(16,2) DEFAULT 0", nullable = false) private Double alreadyGuarantedAmount; @Column(name="birthday") @ManyToOne @JoinColumn(name="c_id") 一对一的配置: @OneToOne(optional = false, targetEntity = com.zhang.model.activities.Award.class, cascade = { CascadeType.DETACH }, fetch = FetchType.LAZY) @JoinColumn(name = "award_id", unique = false, nullable = false) private Award award; 多对多的配置: @ManyToMany(targetEntity = com.zhang.model.agency.AgencyRole.class, cascade = { CascadeType.ALL }, fetch = FetchType.EAGER) @JoinTable(name = "rbac_agency_role_associate", joinColumns = @JoinColumn(name = "agency_id"), inverseJoinColumns = @JoinColumn(name = "agency_role_id")) private Set<AgencyRole> roles; @ManyToMany(targetEntity = com.zhang.model.agency.AgencyFunctionInfo.class, cascade = { CascadeType.ALL }, fetch = FetchType.EAGER) private Set<AgencyFunctionInfo> agencyFunctionInfos; @ManyToMany(targetEntity = com.zhang.model.agency.AgencyRole.class, cascade = { CascadeType.ALL }, fetch = FetchType.EAGER) @JoinTable(name = "agency_role_staff_associate", joinColumns = @JoinColumn(name = "agency_staff_id"), inverseJoinColumns = @JoinColumn(name = "agency_role_id")) private Set<AgencyRole> agencyRoles; 多对一的配置: @ManyToOne(targetEntity = com.zhang.model.agency.Agency.class, optional = true,cascade={CascadeType.REFRESH}) @JoinColumn(name = "agency_id", nullable = false) private Agency agency; @ManyToOne(targetEntity = com.zhang.model.agency.Agency.class, optional = true,cascade={CascadeType.REFRESH}) @JoinColumn(name = "agency_id", nullable = false) private Agency agency; @ManyToOne(targetEntity = com.zhang.model.agency.AgencyDepart.class, optional = true,cascade={CascadeType.REFRESH}) @JoinColumn(name = "agency_depart", nullable = false) private AgencyDepart agencyDepart; @ManyToOne(targetEntity = com.zhang.model.agency.Agency.class, optional = true, cascade = { CascadeType.REFRESH }) @JoinColumn(name = "agency_id", nullable = false) private Agency agency; 一对多的配置: @OneToMany(targetEntity = AgencyFunctionInfo.class, cascade = { CascadeType.REFRESH }, fetch = FetchType.EAGER,mappedBy="parentId") private List<AgencyFunctionInfo> children; @OneToMany(targetEntity = ProductParamter.class, cascade = {CascadeType.PERSIST, CascadeType.REFRESH }, fetch = FetchType.EAGER) private Set<ProductParamter> paramters;
sping 的配置文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:aop="http://www.springframework.org/schema/aop" 4 xmlns:tx="http://www.springframework.org/schema/tx" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 7 xsi:schemaLocation= 8 "http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans.xsd 10 http://www.springframework.org/schema/aop 11 http://www.springframework.org/schema/aop/spring-aop.xsd 12 http://www.springframework.org/schema/tx 13 http://www.springframework.org/schema/tx/spring-tx.xsd 14 http://www.springframework.org/schema/context 15 http://www.springframework.org/schema/context/spring-context.xsd "> 16 17 <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 18 <property name="location" value="classpath:com/zhang/hibernate/hibernate.properties"></property> 19 </bean> 20 21 <context:annotation-config/> 22 23 <!-- 查询所有加了@Component注解的类 24 包含了 annotation-config 标签的功能 25 --> 26 <context:component-scan base-package="com.zhang.dao.impl,com.zhang.service.impl,com.zhang.action"/> 27 28 <!-- 启用对事务注解@Transactional 的支持 29 通过注解驱动 30 --> 31 <tx:annotation-driven/> 32 33 <!-- 事务管理器 --> 34 <bean id="transactionManager" 35 class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 36 <property name="sessionFactory" ref="sessionFactory"></property> 37 <property name="dataSource" ref="dataSource"/> 38 </bean> 39 40 <!-- 数据源 --> 41 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 42 <property name="jdbcUrl" value="${jdbc.url}"></property> 43 <property name="driverClass" value="${jdbc.driver}"></property> 44 <property name="user" value="${jdbc.username}"></property> 45 <property name="password" value="${jdbc.password}"></property> 46 <!-- 其他参数--> 47 <property name="acquireIncrement" value="2"/> 48 <property name="maxIdleTime" value="10"/> 49 <property name="maxPoolSize" value="5"/> 50 <property name="initialPoolSize" value="1"/> 51 <property name="minPoolSize" value="2"/> 52 </bean> 53 54 <!-- sessionFactory --> 55 <bean id="sessionFactory" 56 class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 57 <property name="dataSource" ref="dataSource"/> 58 <property name="hibernateProperties"> 59 <props> 60 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 61 <prop key="hibernate.show_sql">true</prop> 62 <prop key="hibernate.format_sql">true</prop> 63 </props> 64 </property> 65 <!-- 到entity包下去搜索加了@Entity的实体类 --> 66 <property name="packagesToScan"> 67 <list> 68 <value>com.zhang.entity</value> 69 </list> 70 </property> 71 </bean> 72 </beans>
hibernat参数的配置
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/zhangqy
jdbc.username=root
jdbc.password=root
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。